Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 310)
@@ -56,5 +56,9 @@
 // ====================================================================================================================
 
-#define NV_VERSION        "2.0avc"                 ///< Current software version
+#if SVC_EXTENSION
+#define NV_VERSION        "2.1"                 ///< Current software version
+#else
+#define NV_VERSION        "11.0"                ///< Current software version
+#endif
 
 // ====================================================================================================================
@@ -110,7 +114,4 @@
 #define MAX_NUM_REF_PICS            16          ///< max. number of pictures used for reference
 #define MAX_NUM_REF                 16          ///< max. number of entries in picture reference list
-#if !L0034_COMBINED_LIST_CLEANUP
-#define MAX_NUM_REF_LC              MAX_NUM_REF_PICS  // TODO: remove this macro definition (leftover from combined list concept)
-#endif
 
 #define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
Index: trunk/source/Lib/TLibCommon/NAL.h
===================================================================
--- trunk/source/Lib/TLibCommon/NAL.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/NAL.h	(revision 310)
@@ -91,5 +91,4 @@
         || m_nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R;
   }
-#if L0045_NON_NESTED_SEI_RESTRICTIONS
   Bool isSei()
   {
@@ -102,5 +101,4 @@
     return ( (UInt)m_nalUnitType < 32 );
   }
-#endif
 };
 
Index: trunk/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/SEI.cpp	(revision 310)
@@ -39,8 +39,6 @@
 #include "SEI.h"
 
-#if J0149_TONE_MAPPING_SEI 
 //Table D-7 Meaning of camera iso sensitivity indicator and exposure index rating indicator
 Int  Table_exp_indicator[32] = {0, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, -1};
-#endif
 
 SEIMessages getSeisByType(SEIMessages &seiList, SEI::PayloadType seiType)
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 310)
@@ -72,4 +72,7 @@
     SCALABLE_NESTING                     = 133,
     REGION_REFRESH_INFO                  = 134,
+#if M0043_LAYERS_PRESENT_SEI
+    LAYERS_PRESENT                       = 137,
+#endif
   };
   
@@ -124,20 +127,14 @@
 
   SEIActiveParameterSets() 
-#if !L0047_APS_FLAGS
-    :numSpsIdsMinus1(0)
-#else
     : activeVPSId            (0)
     , m_fullRandomAccessFlag (false)
     , m_noParamSetUpdateFlag (false)
     , numSpsIdsMinus1        (0)
-#endif
   {}
   virtual ~SEIActiveParameterSets() {}
 
   Int activeVPSId; 
-#if L0047_APS_FLAGS
   Bool m_fullRandomAccessFlag;
   Bool m_noParamSetUpdateFlag;
-#endif
   Int numSpsIdsMinus1;
   std::vector<Int> activeSeqParamSetId; 
@@ -150,5 +147,4 @@
 
   SEIBufferingPeriod()
-#if L0044_CPB_DPB_DELAY_OFFSET
   : m_bpSeqParameterSetId (0)
   , m_rapCpbParamsPresentFlag (false)
@@ -161,23 +157,16 @@
     ::memset(m_initialAltCpbRemovalDelayOffset, 0, sizeof(m_initialAltCpbRemovalDelayOffset));
   }
-#else
-  {}
-#endif
   virtual ~SEIBufferingPeriod() {}
 
   UInt m_bpSeqParameterSetId;
   Bool m_rapCpbParamsPresentFlag;
-#if L0044_CPB_DPB_DELAY_OFFSET
   Bool m_cpbDelayOffset;
   Bool m_dpbDelayOffset;
-#endif
   UInt m_initialCpbRemovalDelay         [MAX_CPB_CNT][2];
   UInt m_initialCpbRemovalDelayOffset   [MAX_CPB_CNT][2];
   UInt m_initialAltCpbRemovalDelay      [MAX_CPB_CNT][2];
   UInt m_initialAltCpbRemovalDelayOffset[MAX_CPB_CNT][2];
-#if L0328_SPLICING
   Bool m_concatenationFlag;
   UInt m_auCpbRemovalDelayDelta;
-#endif
 };
 class SEIPictureTiming : public SEI
@@ -188,13 +177,7 @@
   SEIPictureTiming()
   : m_picStruct               (0)
-#if L0046_RENAME_PROG_SRC_IDC
   , m_sourceScanType          (0)
-#else
-  , m_progressiveSourceIdc    (0)
-#endif
   , m_duplicateFlag           (false)
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   , m_picDpbOutputDuDelay     (0)
-#endif
   , m_numNalusInDuMinus1      (NULL)
   , m_duCpbRemovalDelayMinus1 (NULL)
@@ -213,16 +196,10 @@
 
   UInt  m_picStruct;
-#if L0046_RENAME_PROG_SRC_IDC
   UInt  m_sourceScanType;
-#else
-  UInt  m_progressiveSourceIdc;
-#endif
   Bool  m_duplicateFlag;
 
   UInt  m_auCpbRemovalDelay;
   UInt  m_picDpbOutputDelay;
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   UInt  m_picDpbOutputDuDelay;
-#endif
   UInt  m_numDecodingUnitsMinus1;
   Bool  m_duCommonCpbRemovalDelayFlag;
@@ -240,16 +217,12 @@
     : m_decodingUnitIdx(0)
     , m_duSptCpbRemovalDelay(0)
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
     , m_dpbOutputDuDelayPresentFlag(false)
     , m_picSptDpbOutputDuDelay(0)
-#endif
   {}
   virtual ~SEIDecodingUnitInfo() {}
   Int m_decodingUnitIdx;
   Int m_duSptCpbRemovalDelay;
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   Bool m_dpbOutputDuDelayPresentFlag;
   Int m_picSptDpbOutputDuDelay;
-#endif
 };
 
@@ -290,9 +263,5 @@
   Int  m_frame1GridPositionY;
   Int  m_arrangementReservedByte;
-#if L0045_PERSISTENCE_FLAGS
   Bool m_arrangementPersistenceFlag;
-#else
-  Int  m_arrangementRepetetionPeriod;
-#endif
   Bool m_upsampledAspectRatio;
 };
@@ -305,9 +274,5 @@
   SEIDisplayOrientation()
     : cancelFlag(true)
-#if L0045_PERSISTENCE_FLAGS
     , persistenceFlag(0)
-#else
-    , repetitionPeriod(1)
-#endif
     , extensionFlag(false)
     {}
@@ -319,9 +284,5 @@
 
   UInt anticlockwiseRotation;
-#if L0045_PERSISTENCE_FLAGS
   Bool persistenceFlag;
-#else
-  UInt repetitionPeriod;
-#endif
   Bool extensionFlag;
 };
@@ -355,5 +316,19 @@
 };
 
-#if L0208_SOP_DESCRIPTION_SEI
+#if M0043_LAYERS_PRESENT_SEI
+class SEILayersPresent : public SEI
+{
+public:
+  PayloadType payloadType() const { return LAYERS_PRESENT; }
+
+  SEILayersPresent() {}
+  virtual ~SEILayersPresent() {}
+
+  UInt m_activeVpsId;
+  UInt m_vpsMaxLayers;
+  Bool m_layerPresentFlag[MAX_LAYERS];
+};
+#endif
+
 class SEISOPDescription : public SEI
 {
@@ -372,7 +347,5 @@
   Int m_sopDescPocDelta[MAX_NUM_PICS_IN_SOP];
 };
-#endif
-
-#if J0149_TONE_MAPPING_SEI 
+
 class SEIToneMappingInfo : public SEI
 {
@@ -407,5 +380,4 @@
   Int    m_extendedWhiteLevelLumaCodeValue;
 };
-#endif
 
 typedef std::list<SEI*> SEIMessages;
@@ -420,5 +392,4 @@
 Void deleteSEIs (SEIMessages &seiList);
 
-#if K0180_SCALABLE_NESTING_SEI
 class SEIScalableNesting : public SEI
 {
@@ -450,5 +421,4 @@
   SEIMessages m_nestedSEIs;
 };
-#endif
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComBitStream.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 310)
@@ -193,4 +193,10 @@
   }
 
+  Void        peekPreviousByte( UInt &byte )
+  {
+    assert(m_fifo_idx > 0);
+    byte = (*m_fifo)[m_fifo_idx - 1];
+  }
+  
   Void        readOutTrailingBits ();
   UChar getHeldBits  ()          { return m_held_bits;          }
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 310)
@@ -589,11 +589,9 @@
   }
 
-  UInt uiTmp = uhWidth*uhHeight;
-
   if(getPic()->getPicSym()->getInverseCUOrderMap(getAddr())*m_pcPic->getNumPartInCU()+m_uiAbsIdxInLCU >= getSlice()->getSliceSegmentCurStartCUAddr())
   {
     m_acCUMvField[0].clearMvField();
     m_acCUMvField[1].clearMvField();
-    uiTmp = uhWidth*uhHeight;
+    UInt uiTmp = uhWidth*uhHeight;
     
     memset( m_pcTrCoeffY,    0, uiTmp * sizeof( *m_pcTrCoeffY    ) );
@@ -794,7 +792,4 @@
   m_uiCUPelY           = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
   
-  UInt uiWidth         = g_uiMaxCUWidth  >> uiDepth;
-  UInt uiHeight        = g_uiMaxCUHeight >> uiDepth;
-  
   m_skipFlag=pcCU->getSkipFlag()          + uiPart;
 
@@ -838,5 +833,4 @@
   m_apcCUColocated[1] = pcCU->getCUColocated(REF_PIC_LIST_1);
   
-  UInt uiTmp = uiWidth*uiHeight;
   UInt uiMaxCuWidth=pcCU->getSlice()->getSPS()->getMaxCUWidth();
   UInt uiMaxCuHeight=pcCU->getSlice()->getSPS()->getMaxCUHeight();
@@ -850,5 +844,4 @@
   m_pcIPCMSampleY = pcCU->getPCMSampleY() + uiCoffOffset;
 
-  uiTmp >>= 2;
   uiCoffOffset >>=2;
   m_pcTrCoeffCb=pcCU->getCoeffCb() + uiCoffOffset;
@@ -1577,6 +1570,5 @@
     return getSlice()->getSliceQp();
   }
-  else
-  if ( iLastValidPartIdx >= 0 )
+  else if ( iLastValidPartIdx >= 0 )
   {
     return getQP( iLastValidPartIdx );
@@ -1647,5 +1639,5 @@
   Int         iLeftIntraDir, iAboveIntraDir;
   Int         uiPredNum = 0;
-  
+
   // Get intra direction of left PU
   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
@@ -1738,4 +1730,68 @@
   return uiPredNum;
 }
+
+
+#if FAST_INTRA_SHVC
+/** generate limited set of remaining modes
+*\param   uiAbsPartIdx
+*\param   uiIntraDirPred  pointer to the array for MPM storage
+*\returns Number of intra coding modes (nb of remaining modes + 3 MPMs)
+*/
+Int TComDataCU::reduceSetOfIntraModes( UInt uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes )
+{
+  // check BL mode
+  UInt          uiCUAddrBase, uiAbsPartAddrBase;
+  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
+
+  if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
+  {
+    return( NUM_INTRA_MODE-1 );
+  }
+
+  // compute set of enabled modes g_reducedSetIntraModes[...]
+  Int authorizedMode[NUM_INTRA_MODE-1]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
+  Int nbModes;
+  for (nbModes=0; nbModes<3; nbModes++)  // add 3 MPMs 1st
+  {
+    g_reducedSetIntraModes[nbModes] = uiIntraDirPred[nbModes];
+    authorizedMode[ uiIntraDirPred[nbModes] ] = 0;
+  }
+
+  Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+  if ( authorizedMode[iColBaseDir] )  //possibly add BL mode
+  {
+    g_reducedSetIntraModes[nbModes++] = iColBaseDir;
+    authorizedMode[ iColBaseDir ] = 0;
+  }
+
+  Int iRefMode = ( iColBaseDir > 1 ) ? iColBaseDir : uiIntraDirPred[0];
+  if ( iRefMode > 1 )    //add neighboring modes of refMode
+  {
+    UInt Left  = iRefMode;
+    UInt Right = iRefMode;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      Left = ((Left + 29) % 32) + 2;
+      Right = ((Right - 1 ) % 32) + 2;
+      if ( authorizedMode[Left] )   g_reducedSetIntraModes[nbModes++] = Left;
+      if ( authorizedMode[Right] )  g_reducedSetIntraModes[nbModes++] = Right;
+    }
+  }
+  else      //add pre-defined modes
+  {
+    Int  idx = 0;
+    while ( nbModes < NB_REMAIN_MODES+3 )
+    {
+      UInt mode = g_predefSetIntraModes[idx++];
+      if ( authorizedMode[mode] )   g_reducedSetIntraModes[nbModes++] = mode;
+    }
+  }
+
+  fullSetOfModes = 0;
+  return ( nbModes );
+}
+#endif
+
 
 UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
@@ -2541,5 +2597,5 @@
     if(m_layerId)  
     {
-      pcColCU = getBaseColCU( xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
+      pcColCU = getBaseColCU( m_layerId - 1, xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
 
 #if INTRA_BL
@@ -2563,5 +2619,5 @@
         {
           pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_0, cMvFieldBaseColCU[0]);
-          scaleBaseMV( pcMvFieldNeighbours[iCount<<1], cMvFieldBaseColCU[0] );
+          scaleBaseMV( m_layerId - 1, pcMvFieldNeighbours[iCount<<1], cMvFieldBaseColCU[0] );
         }
 
@@ -2569,5 +2625,5 @@
         {
           pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_1, cMvFieldBaseColCU[1] );
-          scaleBaseMV( pcMvFieldNeighbours[(iCount<<1)+1], cMvFieldBaseColCU[1] );
+          scaleBaseMV( m_layerId - 1, pcMvFieldNeighbours[(iCount<<1)+1], cMvFieldBaseColCU[1] );
         }
 
@@ -2796,5 +2852,4 @@
     //>> MTK colocated-RightBottom
     UInt uiPartIdxRB;
-    Int uiLCUIdx = getAddr();
 
     deriveRightBottomIdx( uiPUIdx, uiPartIdxRB );  
@@ -2805,12 +2860,11 @@
     TComMv cColMv;
     Int iRefIdx;
+    Int uiLCUIdx = -1;
 
     if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
-      uiLCUIdx = -1;
     }
     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
     {
-      uiLCUIdx = -1;
     }
     else
@@ -2825,5 +2879,4 @@
       {
         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
-        uiLCUIdx = -1 ; 
       }
       else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
@@ -2835,5 +2888,4 @@
       {
         uiAbsPartAddr = 0;
-        uiLCUIdx = -1 ; 
       }
     }
@@ -3099,5 +3151,5 @@
     if (!bAdded) 
     {
-      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
+      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLB, MD_LEFT );
     }
   }
@@ -3112,5 +3164,5 @@
   if(!bAdded)
   {
-    bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
+    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
   }
   bAdded = bAddedSmvp;
@@ -3127,5 +3179,5 @@
     if(!bAdded)
     {
-      bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
+      xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
     }
   }
@@ -3147,5 +3199,4 @@
     UInt uiAbsPartIdx;  
     UInt uiAbsPartAddr;
-    Int uiLCUIdx = getAddr();
 
     deriveRightBottomIdx( uiPartIdx, uiPartIdxRB );
@@ -3154,11 +3205,10 @@
     //----  co-located RightBottom Temporal Predictor (H) ---//
     uiAbsPartIdx = g_auiZscanToRaster[uiPartIdxRB];
+    Int uiLCUIdx = -1;
     if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdx] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     {
-      uiLCUIdx = -1;
     }
     else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdx] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
     {
-      uiLCUIdx = -1;
     }
     else
@@ -3173,5 +3223,4 @@
       {
         uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdx + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
-        uiLCUIdx      = -1 ; 
       }
       else if ( uiAbsPartIdx / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
@@ -3183,5 +3232,4 @@
       {
         uiAbsPartAddr = 0;
-        uiLCUIdx      = -1 ; 
       }
     }
@@ -3245,6 +3293,5 @@
 UInt TComDataCU::getIntraSizeIdx(UInt uiAbsPartIdx)
 {
-  UInt uiShift = ( (m_puhTrIdx[uiAbsPartIdx]==0) && (m_pePartSize[uiAbsPartIdx]==SIZE_NxN) ) ? m_puhTrIdx[uiAbsPartIdx]+1 : m_puhTrIdx[uiAbsPartIdx];
-  uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
+  UInt uiShift = ( m_pePartSize[uiAbsPartIdx]==SIZE_NxN ? 1 : 0 );
   
   UChar uiWidth = m_puhWidth[uiAbsPartIdx]>>uiShift;
@@ -3332,9 +3379,5 @@
   }
   
-#if L0363_MVP_POC
   if ( pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) >= 0 && m_pcSlice->getRefPic( eRefPicList, iRefIdx)->getPOC() == pcTmpCU->getSlice()->getRefPOC( eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ))
-#else
-  if ( m_pcSlice->isEqualRef(eRefPicList, pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx), iRefIdx) )
-#endif
   {
     TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
@@ -3519,5 +3562,17 @@
 
   // use coldir.
+#if M0457_COL_PICTURE_SIGNALING
+  TComPic *pColPic;
+  if (m_layerId > 0 && getSlice()->getAltColIndicationFlag())
+  {
+    pColPic = getSlice()->getMotionPredIlp();
+  }
+  else
+  {
+    pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+  }
+#else
   TComPic *pColPic = getSlice()->getRefPic( RefPicList(getSlice()->isInterB() ? 1-getSlice()->getColFromL0Flag() : 0), getSlice()->getColRefIdx());
+#endif
   TComDataCU *pColCU = pColPic->getCU( uiCUAddr );
   if(pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE)
@@ -3526,5 +3581,4 @@
   }
   iCurrPOC = m_pcSlice->getPOC();    
-  iCurrRefPOC = m_pcSlice->getRefPic(eRefPicList, riRefIdx)->getPOC();
   iColPOC = pColCU->getSlice()->getPOC();  
 
@@ -4121,5 +4175,5 @@
 
 #if SVC_COL_BLK
-TComDataCU*  TComDataCU::getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
 {
 #if 1 // it should provide identical resutls
@@ -4127,5 +4181,5 @@
   UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
 
-  return getBaseColCU( uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
+  return getBaseColCU( refLayerIdc, uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
 #else
   TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
@@ -4176,7 +4230,7 @@
 }
 
-TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
-{
-  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
 
 #if !SIMPLIFIED_MV_POS_SCALING
@@ -4206,11 +4260,11 @@
 #if SIMPLIFIED_MV_POS_SCALING
 #if SCALED_REF_LAYER_OFFSETS
-  Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowLeftOffset();
-  Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowTopOffset();
-  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
-  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+  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[m_layerId][0] + (1<<15)) >> 16;
-  Int iBY = (uiPelY*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+  Int iBX = (uiPelX*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
+  Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
 #endif
 #else
@@ -4234,6 +4288,6 @@
   const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
 
-  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+  Int widthBL   = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int heightBL  = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
 #endif
   if( iBX >= widthBL || iBY >= heightBL ) //outside of the reference layer cropped picture
@@ -4255,10 +4309,10 @@
 }
 
-Void TComDataCU::scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
+Void TComDataCU::scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
 {
   TComMvField cMvFieldBase;
   TComMv cMv;
 #if SIMPLIFIED_MV_POS_SCALING
-  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[m_layerId][0], g_mvScalingFactor[m_layerId][1] );
+  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[refLayerIdc][0], g_mvScalingFactor[refLayerIdc][1] );
 #else
   const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 310)
@@ -533,4 +533,8 @@
 #endif  
 
+#if FAST_INTRA_SHVC
+  Int           reduceSetOfIntraModes              (  UInt   uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes );
+#endif
+
 #if REF_IDX_ME_ZEROMV
   Bool xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
@@ -550,7 +554,7 @@
 
 #if SVC_COL_BLK 
-  TComDataCU*   getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
-  TComDataCU*   getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
-  Void          scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  Void          scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
 #endif
 };
Index: trunk/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 310)
@@ -461,5 +461,4 @@
         if ( ((piRefP0==piRefQ0)&&(piRefP1==piRefQ1)) || ((piRefP0==piRefQ1)&&(piRefP1==piRefQ0)) )
         {
-          uiBs = 0;
           if ( piRefP0 != piRefP1 )   // Different L0 & L1
           {
@@ -694,6 +693,4 @@
   for ( UInt iIdx = 0; iIdx < uiNumParts; iIdx++ )
   {
-    ucBs = 0;
-    
     uiBsAbsIdx = xCalcBsIdx( pcCU, uiAbsZorderIdx, iDir, iEdge, iIdx);
     ucBs = m_aapucBS[iDir][uiBsAbsIdx];
Index: trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMv.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComMv.h	(revision 310)
@@ -152,6 +152,6 @@
   const TComMv scaleMv( Int iScaleX, Int iScaleY ) const
   {
-    Int mvx = Clip3( -32768, 32767, (iScaleX * getHor() + 127 + (iScaleX * getHor() < 0)) >> 8 );
-    Int mvy = Clip3( -32768, 32767, (iScaleY * getVer() + 127 + (iScaleY * getVer() < 0)) >> 8 );
+    Int mvx = iScaleX == 4096 ? getHor() : Clip3( -32768, 32767, (iScaleX * getHor() + 127 + (iScaleX * getHor() < 0)) >> 8 );
+    Int mvy = iScaleY == 4096 ? getVer() : Clip3( -32768, 32767, (iScaleY * getVer() + 127 + (iScaleY * getVer() < 0)) >> 8 );
     return TComMv( mvx, mvy );
   }
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 310)
@@ -67,9 +67,9 @@
 , m_pNDBFilterYuvTmp                      (NULL)
 , m_bCheckLTMSB                           (false)
+{
 #if SVC_EXTENSION
-, m_bSpatialEnhLayer( false )
-, m_pcFullPelBaseRec( NULL )
-#endif
-{
+  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
+  memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) );
+#endif
   m_apcPicYuv[0]      = NULL;
   m_apcPicYuv[1]      = NULL;
@@ -91,7 +91,10 @@
   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
 
-  if (m_bSpatialEnhLayer)
-  {
-    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  for( Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    if( m_bSpatialEnhLayer[i] )
+    {
+      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+    }
   }
 
@@ -173,9 +176,12 @@
   deleteSEIs(m_SEIs);
 #if SVC_EXTENSION && SVC_UPSAMPLING
-  if (m_bSpatialEnhLayer)
-  {
-    m_pcFullPelBaseRec->destroy();
-    delete m_pcFullPelBaseRec;
-    m_pcFullPelBaseRec  = NULL;
+  for( Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    if( m_bSpatialEnhLayer[i] )
+    {
+      m_pcFullPelBaseRec[i]->destroy();
+      delete m_pcFullPelBaseRec[i];
+      m_pcFullPelBaseRec[i]  = NULL;
+    }
   }
 #endif 
@@ -562,5 +568,5 @@
 
 #if REF_IDX_MFM
-Void TComPic::copyUpsampledMvField(TComPic* pcPicBase)
+Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
 {
 #if AVC_SYNTAX && !ILP_DECODED_PICTURE
@@ -592,5 +598,5 @@
 
       TComDataCU *pcColCU = 0;
-      pcColCU = pcCUDes->getBaseColCU(pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
+      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
 
 #if AVC_SYNTAX && !ILP_DECODED_PICTURE
@@ -607,5 +613,5 @@
           TComMvField sMvFieldBase, sMvField;
           pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
-          pcCUDes->scaleBaseMV( sMvField, sMvFieldBase );
+          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase );
 
           pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 310)
@@ -92,6 +92,6 @@
   SEIMessages  m_SEIs; ///< Any SEI messages that have been received.  If !NULL we own the object.
 #if SVC_EXTENSION
-  Bool                  m_bSpatialEnhLayer;       // whether current layer is a spatial enhancement layer,
-  TComPicYuv*           m_pcFullPelBaseRec;    // upsampled base layer recontruction for difference domain inter prediction
+  Bool                  m_bSpatialEnhLayer[MAX_LAYERS];       // whether current layer is a spatial enhancement layer,
+  TComPicYuv*           m_pcFullPelBaseRec[MAX_LAYERS];    // upsampled base layer recontruction for difference domain inter prediction
 #endif
 
@@ -114,8 +114,8 @@
   Void          setLayerId (UInt layerId) { m_layerId = layerId; }
   UInt          getLayerId ()               { return m_layerId; }
-  Bool          isSpatialEnhLayer()             { return m_bSpatialEnhLayer; }
-  Void          setSpatialEnhLayerFlag (Bool b) { m_bSpatialEnhLayer = b; }
-  Void          setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
-  TComPicYuv*   getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+  Bool          isSpatialEnhLayer(UInt refLayerIdc)             { return m_bSpatialEnhLayer[refLayerIdc]; }
+  Void          setSpatialEnhLayerFlag (UInt refLayerIdc, Bool b) { m_bSpatialEnhLayer[refLayerIdc] = b; }
+  Void          setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
+  TComPicYuv*   getFullPelBaseRec   (UInt refLayerIdc)  { return  m_pcFullPelBaseRec[refLayerIdc];  }
 #endif
 #if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
@@ -124,5 +124,5 @@
 
 #if REF_IDX_MFM
-  Void          copyUpsampledMvField  (  TComPic* pcPicBase );
+  Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
   Void          initUpsampledMvField  ();
 #endif
Index: trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 310)
@@ -92,4 +92,8 @@
 #endif
 
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  Bool    m_isReconstructed;
+#endif
+
   Bool  m_bIsBorderExtended;
   
@@ -126,7 +130,4 @@
 #endif
 
-#if JCTVC_L0178
-  Void   setWidth   ( Int iPicWidth )     { m_iPicWidth = iPicWidth; }
-#endif
   Int   getStride   ()     { return (m_iPicWidth     ) + (m_iLumaMarginX  <<1); }
   Int   getCStride  ()     { return (m_iPicWidth >> 1) + (m_iChromaMarginX<<1); }
@@ -177,5 +178,10 @@
   //  Dump picture
   Void  dump (Char* pFileName, Bool bAdd = false);
-  
+
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  Void  setReconstructed(Bool x) { m_isReconstructed = x;    }
+  Bool  isReconstructed()        { return m_isReconstructed; }
+#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 230)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 310)
@@ -122,4 +122,5 @@
 Pel TComPrediction::predIntraGetPredValDC( Int* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
 {
+  assert(iWidth > 0 && iHeight > 0);
   Int iInd, iSum = 0;
   Pel pDcVal;
@@ -774,12 +775,12 @@
 #if SVC_UPSAMPLING
 #if SCALED_REF_LAYER_OFFSETS
-Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
-{
-  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic, window);
+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( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
-{
-  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic);
 }
 #endif
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 310)
@@ -123,7 +123,7 @@
 #if SVC_UPSAMPLING
 #if SCALED_REF_LAYER_OFFSETS
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
 #else
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 #endif
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 310)
@@ -485,5 +485,5 @@
 }
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height )
 {
Index: trunk/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 310)
@@ -168,4 +168,7 @@
 #if RATE_CONTROL_LAMBDA_DOMAIN
   Double  getLambda() { return m_dLambda; }
+#if M0036_RC_IMPROVEMENT
+  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
+#endif
 #endif
   
@@ -264,5 +267,5 @@
 #endif
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
   UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
 #endif
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 310)
@@ -99,4 +99,9 @@
 UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5};
 
+#if FAST_INTRA_SHVC
+UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
+UInt g_predefSetIntraModes[NUM_INTRA_MODE-1] = {26,10,18,34,2,22,14,30,6,24,12,28,8,20,16,32,4,17,19,15,21,13,23,11,25,9,27,7,29,5,31,3,33,0,2};
+#endif
+
 Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx )
 {
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 310)
@@ -132,4 +132,9 @@
 
 extern const UChar  g_aucIntraModeNumFast[7];
+
+#if FAST_INTRA_SHVC
+extern       UInt  g_reducedSetIntraModes[NUM_INTRA_MODE-1];
+extern       UInt  g_predefSetIntraModes[NUM_INTRA_MODE-1];
+#endif
 
 // ====================================================================================================================
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 310)
@@ -65,8 +65,4 @@
 , m_deblockingFilterBetaOffsetDiv2 ( 0 )
 , m_deblockingFilterTcOffsetDiv2   ( 0 )
-#if !L0034_COMBINED_LIST_CLEANUP
-, m_bRefPicListModificationFlagLC ( false )
-, m_bRefPicListCombinationFlag    ( false )
-#endif
 , m_bCheckLDC                     ( false )
 , m_iSliceQpDelta                 ( 0 )
@@ -75,4 +71,7 @@
 , m_iDepth                        ( 0 )
 , m_bRefenced                     ( false )
+#if SH_DISCARDABLE_FLAG
+, m_bDiscardableFlag              ( false )
+#endif
 , m_pcSPS                         ( NULL )
 , m_pcPPS                         ( NULL )
@@ -86,11 +85,7 @@
 , m_dLambda                       ( 0.0 )
 #endif
-#if !L0034_COMBINED_LIST_CLEANUP
-, m_bNoBackPredFlag             ( false )
-#endif
 , m_uiTLayer                      ( 0 )
 #if SVC_EXTENSION
 , m_layerId                     ( 0 )
-, m_pcBaseColPic                  ( NULL )
 #endif
 , m_bTLayerSwitchingFlag          ( false )
@@ -117,10 +112,8 @@
 , m_enableTMVPFlag                ( true )
 {
-#if L0034_COMBINED_LIST_CLEANUP
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = 0;
-#else
-  m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
-#endif
-  
+
+#if SVC_EXTENSION
+  memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
 #if REF_IDX_FRAMEWORK
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -131,24 +124,21 @@
   m_numILRRefIdx = 0;
 #endif 
+#if M0457_COL_PICTURE_SIGNALING
+  m_altColIndicationFlag = false;
+  m_colRefLayerIdx       = 0;
+#endif
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  m_numSamplePredRefLayers       = 0;
+  m_interLayerSamplePredOnlyFlag = false;
+#endif
+#endif
 #endif
 
   initEqualRef();
   
-#if L0034_COMBINED_LIST_CLEANUP
   for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
   {
     m_list1IdxToList0Idx[idx] = -1;
   }
-#else
-  for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
-  {
-    m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
-    m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
-    m_eListIdFromIdxOfLC[iNumCount]=0;
-    m_iRefIdxFromIdxOfLC[iNumCount]=0;
-    m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
-    m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
-  }    
-#endif
   for(Int iNumCount = 0; iNumCount < MAX_NUM_REF; iNumCount++)
   {
@@ -188,5 +178,8 @@
   m_numILRRefIdx              = 0;
 #endif  
-
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  m_numSamplePredRefLayers       = 0;
+  m_interLayerSamplePredOnlyFlag = false;
+#endif
 #endif
   m_colFromL0Flag = 1;
@@ -194,16 +187,7 @@
   m_colRefIdx = 0;
   initEqualRef();
-#if !L0034_COMBINED_LIST_CLEANUP
-  m_bNoBackPredFlag = false;
-  m_bRefPicListCombinationFlag = false;
-  m_bRefPicListModificationFlagLC = false;
-#endif
   m_bCheckLDC = false;
   m_iSliceQpDeltaCb = 0;
   m_iSliceQpDeltaCr = 0;
-
-#if !L0034_COMBINED_LIST_CLEANUP
-  m_aiNumRefIdx[REF_PIC_LIST_C]      = 0;
-#endif
 
   m_maxNumMergeCand = MRG_MAX_NUM_CANDS;
@@ -348,5 +332,4 @@
 }
 
-#if L0034_COMBINED_LIST_CLEANUP
 Void TComSlice::setList1IdxToList0Idx()
 {
@@ -365,71 +348,11 @@
   }
 }
-#else
-Void TComSlice::generateCombinedList()
-{
-  if(m_aiNumRefIdx[REF_PIC_LIST_C] > 0)
-  {
-    m_aiNumRefIdx[REF_PIC_LIST_C]=0;
-    for(Int iNumCount = 0; iNumCount < MAX_NUM_REF_LC; iNumCount++)
-    {
-      m_iRefIdxOfLC[REF_PIC_LIST_0][iNumCount]=-1;
-      m_iRefIdxOfLC[REF_PIC_LIST_1][iNumCount]=-1;
-      m_eListIdFromIdxOfLC[iNumCount]=0;
-      m_iRefIdxFromIdxOfLC[iNumCount]=0;
-      m_iRefIdxOfL0FromRefIdxOfL1[iNumCount] = -1;
-      m_iRefIdxOfL1FromRefIdxOfL0[iNumCount] = -1;
-    }
-
-    for (Int iNumRefIdx = 0; iNumRefIdx < MAX_NUM_REF; iNumRefIdx++)
-    {
-      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_0])
-      {
-        Bool bTempRefIdxInL2 = true;
-        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
-        {
-          if ( m_apcRefPicList[REF_PIC_LIST_0][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
-          {
-            m_iRefIdxOfL1FromRefIdxOfL0[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
-            m_iRefIdxOfL0FromRefIdxOfL1[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
-            bTempRefIdxInL2 = false;
-            break;
-          }
-        }
-
-        if(bTempRefIdxInL2 == true)
-        { 
-          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_0;
-          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
-          m_iRefIdxOfLC[REF_PIC_LIST_0][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
-        }
-      }
-
-      if(iNumRefIdx < m_aiNumRefIdx[REF_PIC_LIST_1])
-      {
-        Bool bTempRefIdxInL2 = true;
-        for ( Int iRefIdxLC = 0; iRefIdxLC < m_aiNumRefIdx[REF_PIC_LIST_C]; iRefIdxLC++ )
-        {
-          if ( m_apcRefPicList[REF_PIC_LIST_1][iNumRefIdx]->getPOC() == m_apcRefPicList[m_eListIdFromIdxOfLC[iRefIdxLC]][m_iRefIdxFromIdxOfLC[iRefIdxLC]]->getPOC() )
-          {
-            m_iRefIdxOfL0FromRefIdxOfL1[iNumRefIdx] = m_iRefIdxFromIdxOfLC[iRefIdxLC];
-            m_iRefIdxOfL1FromRefIdxOfL0[m_iRefIdxFromIdxOfLC[iRefIdxLC]] = iNumRefIdx;
-            bTempRefIdxInL2 = false;
-            break;
-          }
-        }
-        if(bTempRefIdxInL2 == true)
-        {
-          m_eListIdFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = REF_PIC_LIST_1;
-          m_iRefIdxFromIdxOfLC[m_aiNumRefIdx[REF_PIC_LIST_C]] = iNumRefIdx;
-          m_iRefIdxOfLC[REF_PIC_LIST_1][iNumRefIdx] = m_aiNumRefIdx[REF_PIC_LIST_C]++;
-        }
-      }
-    }
-  }
-}
-#endif
 
 #if FIX1071
+#if SVC_EXTENSION
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr, TComPic** ilpPic)
+#else
+Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
+#endif
 #else
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
@@ -440,8 +363,9 @@
 #endif
   {
-    if( m_eSliceType == I_SLICE )
+    if (m_eSliceType == I_SLICE)
     {
       ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
       ::memset( m_aiNumRefIdx,   0, sizeof ( m_aiNumRefIdx ));
+      
       return;
     }
@@ -479,4 +403,7 @@
       pcRefPic->getPicYuvRec()->extendPicBorder();
       RefPicSetStCurr0[NumPocStCurr0] = pcRefPic;
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+      if( !m_interLayerSamplePredOnlyFlag || pcRefPic->getLayerId() < getLayerId()) 
+#endif
       NumPocStCurr0++;
       pcRefPic->setCheckLTMSBPresent(false);  
@@ -492,4 +419,7 @@
       pcRefPic->getPicYuvRec()->extendPicBorder();
       RefPicSetStCurr1[NumPocStCurr1] = pcRefPic;
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+      if( !m_interLayerSamplePredOnlyFlag || pcRefPic->getLayerId() < getLayerId()) 
+#endif
       NumPocStCurr1++;
       pcRefPic->setCheckLTMSBPresent(false);  
@@ -505,4 +435,7 @@
       pcRefPic->getPicYuvRec()->extendPicBorder();
       RefPicSetLtCurr[NumPocLtCurr] = pcRefPic;
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+      if( !m_interLayerSamplePredOnlyFlag || pcRefPic->getLayerId() < getLayerId()) 
+#endif
       NumPocLtCurr++;
     }
@@ -518,22 +451,41 @@
 
 #if REF_IDX_FRAMEWORK
-  //inter-layer reference picture
+  for( i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+    //inter-layer reference picture
 #if REF_IDX_MFM
+
+#if ILR_RESTR
+    Int maxSubLayerForILPPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
 #if ZERO_NUM_DIRECT_LAYERS
-  if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
-#else
-  if (getLayerId())
-#endif
-  {
-    if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
-    { 
-      ilpPic[0]->copyUpsampledMvField(getBaseColPic());
-    }
-    else
-    {
-      ilpPic[0]->initUpsampledMvField();
-    }
-  #endif
-    ilpPic[0]->setIsLongTerm(1);
+    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
+#else
+    if( m_layerId > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  )
+#endif
+
+#else
+#if ZERO_NUM_DIRECT_LAYERS
+    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
+#else
+    if( m_layerId > 0 )
+#endif
+#endif
+    {
+#if M0457_COL_PICTURE_SIGNALING
+      if(!(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) && getMFMEnabledFlag())
+#else
+      if(!(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) && m_pcSPS->getMFMEnabledFlag())
+#endif
+      { 
+        ilpPic[refLayerIdc]->copyUpsampledMvField( refLayerIdc, m_pcBaseColPic[refLayerIdc] );
+      }
+      else
+      {
+        ilpPic[refLayerIdc]->initUpsampledMvField();
+      }
+#endif
+      ilpPic[refLayerIdc]->setIsLongTerm(1);
+    }
   }
 #endif
@@ -542,4 +494,57 @@
   TComPic*  rpsCurrList1[MAX_NUM_REF+1];
 #if REF_IDX_FRAMEWORK
+#if ILR_RESTR
+  Int numInterLayerRPSPics = 0;
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
+#else
+  if( m_layerId > 0 )
+#endif
+  {
+    for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
+    {
+      Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
+      if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
+      {
+        numInterLayerRPSPics++;
+      }
+    }
+#if JCTVC_M0458_INTERLAYER_RPS_SIG
+    if (numInterLayerRPSPics < m_activeNumILRRefIdx)
+    {
+      m_activeNumILRRefIdx = numInterLayerRPSPics;
+    }
+#if MAX_ONE_RESAMPLING_DIRECT_LAYERS && SIMPLIFIED_MV_POS_SCALING
+    if( m_pcVPS->getScalabilityMask(1) )
+    {
+      Int numResampler = 0;
+      const Window &scalEL = getSPS()->getScaledRefLayerWindow(m_interLayerPredLayerIdc[i]);
+      Int scalingOffset = ((scalEL.getWindowLeftOffset()   == 0 ) && 
+                           (scalEL.getWindowRightOffset()  == 0 ) && 
+                           (scalEL.getWindowTopOffset()    == 0 ) && 
+                           (scalEL.getWindowBottomOffset() == 0 ) 
+                          );
+
+      for( i=0; i < m_activeNumILRRefIdx; i++ )
+      {
+        UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) && (scalingOffset)) // ratio 1x
+        {
+          numResampler++;
+        }
+      }
+
+      //Bitstream constraint for SHVC: The picture resampling process as specified in subclause G.8.1.4.1 shall not be invoked more than once for decoding of each particular picture.
+      assert(numResampler <= 1);
+    }
+#endif 
+#else
+    if (numInterLayerRPSPics < m_numILRRefIdx)
+    {
+      m_numILRRefIdx = numInterLayerRPSPics;
+    }
+#endif
+  }
+#endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr + m_activeNumILRRefIdx;
@@ -554,7 +559,13 @@
   {
     // The variable NumPocTotalCurr is derived as specified in subclause 7.4.7.2. It is a requirement of bitstream conformance that the following applies to the value of NumPocTotalCurr:
+#if ILP_RAP    // inter-layer prediction is allowed for BLA, CRA pictures of nuh_layer_id>0
+    // – If the current picture is a BLA or CRA picture with nuh_layer_id equal to 0, the value of NumPocTotalCurr shall be equal to 0.
+    // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
+    if (getRapPicFlag() && getLayerId()==0)
+#else
     // – If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     // – Otherwise, when the current picture contains a P or B slice, the value of NumPocTotalCurr shall not be equal to 0.
     if (getRapPicFlag())
+#endif
     {
       assert(numPocTotalCurr == 0);
@@ -569,5 +580,5 @@
     }
     
-    assert(numPocTotalCurr != 0);
+    assert(numPocTotalCurr > 0);
     
     m_aiNumRefIdx[0] = getNumRefIdx(REF_PIC_LIST_0);
@@ -575,5 +586,13 @@
   }
 #endif
-  
+
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+    if( m_interLayerSamplePredOnlyFlag && getLayerId() ) 
+    {
+      m_aiNumRefIdx[0] = m_aiNumRefIdx[0] > m_activeNumILRRefIdx ? m_activeNumILRRefIdx : m_aiNumRefIdx[0];
+      m_aiNumRefIdx[1] = m_aiNumRefIdx[1] > m_activeNumILRRefIdx ? m_activeNumILRRefIdx : m_aiNumRefIdx[1];
+    }
+#endif
+ 
     Int cIdx = 0;
     for ( i=0; i<NumPocStCurr0; i++, cIdx++)
@@ -588,7 +607,8 @@
     {
       rpsCurrList0[cIdx] = RefPicSetLtCurr[i];
-    }
+    }    
+
 #if REF_IDX_FRAMEWORK
-    if(getLayerId())
+    if( m_layerId > 0 )
     {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -598,8 +618,15 @@
 #endif 
       {
-        rpsCurrList0[cIdx] = ilpPic[i];
-      }
-    }
-#endif
+        Int refLayerIdc = m_interLayerPredLayerIdc[i];
+#if ILR_RESTR
+         Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+#endif
+        rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
+      }
+    }
+#endif
+  assert(cIdx == numPocTotalCurr);
+
   if (m_eSliceType==B_SLICE)
   {
@@ -616,7 +643,8 @@
     {
       rpsCurrList1[cIdx] = RefPicSetLtCurr[i];
-    }
+    }    
+
 #if REF_IDX_FRAMEWORK
-    if(getLayerId())
+    if( m_layerId > 0 )
     {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -626,19 +654,27 @@
 #endif 
       {
-        rpsCurrList1[cIdx] = ilpPic[i];
-      }
-    }
-#endif
+        Int refLayerIdc = m_interLayerPredLayerIdc[i];
+#if ILR_RESTR
+        Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+#endif
+        rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
+      }
+    }
+#endif
+
+    assert(cIdx == numPocTotalCurr);
   }
 
   ::memset(m_bIsUsedAsLongTerm, 0, sizeof(m_bIsUsedAsLongTerm));
 
-  for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[0]-1); rIdx ++)
-  {
-    m_apcRefPicList[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? rpsCurrList0[ m_RefPicListModification.getRefPicSetIdxL0(rIdx) ] : rpsCurrList0[rIdx % numPocTotalCurr];
-    m_bIsUsedAsLongTerm[0][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL0() ? (m_RefPicListModification.getRefPicSetIdxL0(rIdx) >= (NumPocStCurr0 + NumPocStCurr1))
-                                  : ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1));
-  }
-  if ( m_eSliceType == P_SLICE )
+  for (Int rIdx = 0; rIdx < m_aiNumRefIdx[0]; rIdx ++)
+  {
+    cIdx = m_RefPicListModification.getRefPicListModificationFlagL0() ? m_RefPicListModification.getRefPicSetIdxL0(rIdx) : rIdx % numPocTotalCurr;
+    assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+    m_apcRefPicList[0][rIdx] = rpsCurrList0[ cIdx ];
+    m_bIsUsedAsLongTerm[0][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
+  }
+  if ( m_eSliceType != B_SLICE )
   {
     m_aiNumRefIdx[1] = 0;
@@ -647,9 +683,10 @@
   else
   {
-    for (Int rIdx = 0; rIdx <= (m_aiNumRefIdx[1]-1); rIdx ++)
-    {
-      m_apcRefPicList[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ? rpsCurrList1[ m_RefPicListModification.getRefPicSetIdxL1(rIdx) ] : rpsCurrList1[rIdx % numPocTotalCurr];
-      m_bIsUsedAsLongTerm[1][rIdx] = m_RefPicListModification.getRefPicListModificationFlagL1() ?
-                                  (m_RefPicListModification.getRefPicSetIdxL1(rIdx) >= (NumPocStCurr0 + NumPocStCurr1)): ((rIdx % numPocTotalCurr) >= (NumPocStCurr0 + NumPocStCurr1));
+    for (Int rIdx = 0; rIdx < m_aiNumRefIdx[1]; rIdx ++)
+    {
+      cIdx = m_RefPicListModification.getRefPicListModificationFlagL1() ? m_RefPicListModification.getRefPicSetIdxL1(rIdx) : rIdx % numPocTotalCurr;
+      assert(cIdx >= 0 && cIdx < numPocTotalCurr);
+      m_apcRefPicList[1][rIdx] = rpsCurrList1[ cIdx ];
+      m_bIsUsedAsLongTerm[1][rIdx] = ( cIdx >= NumPocStCurr0 + NumPocStCurr1 );
     }
   }
@@ -659,15 +696,15 @@
 Void TComSlice::setRefPicListModificationSvc()
 {
-  if( !this->getPPS()->getListsModificationPresentFlag()) 
+  if( !m_pcPPS->getListsModificationPresentFlag()) 
   {
     return;
   }
 
-  if(this->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && this->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)
+  if(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA)
   {
     return;
   }
 
-  TComRefPicListModification* refPicListModification = this->getRefPicListModification();
+  TComRefPicListModification* refPicListModification = &m_RefPicListModification;
   Int numberOfRpsCurrTempList = this->getNumRpsCurrTempList();  // total number of ref pics in listTemp0 including inter-layer ref pics
 
@@ -743,7 +780,7 @@
 
 #if REF_IDX_FRAMEWORK
-  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
-    (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
-    (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
+  if( m_eSliceType == I_SLICE || ( m_pcSPS->getLayerId() && 
+    (m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
+    (m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) ) )
 #else
   if (m_eSliceType == I_SLICE) 
@@ -768,5 +805,5 @@
   }
 #if REF_IDX_FRAMEWORK
-  if(getLayerId())
+  if( m_layerId > 0 )
   {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -950,36 +987,13 @@
   m_deblockingFilterTcOffsetDiv2 = pSrc->m_deblockingFilterTcOffsetDiv2;
   
-#if L0034_COMBINED_LIST_CLEANUP
   for (i = 0; i < 2; i++)
-#else
-  for (i = 0; i < 3; i++)
-#endif
   {
     m_aiNumRefIdx[i]     = pSrc->m_aiNumRefIdx[i];
   }
 
-#if L0034_COMBINED_LIST_CLEANUP
   for (i = 0; i < MAX_NUM_REF; i++)
   {
     m_list1IdxToList0Idx[i] = pSrc->m_list1IdxToList0Idx[i];
   } 
-#else
-  for (i = 0; i < 2; i++)
-  {
-    for (j = 0; j < MAX_NUM_REF_LC; j++)
-    {
-       m_iRefIdxOfLC[i][j]  = pSrc->m_iRefIdxOfLC[i][j];
-    }
-  }
-  for (i = 0; i < MAX_NUM_REF_LC; i++)
-  {
-    m_eListIdFromIdxOfLC[i] = pSrc->m_eListIdFromIdxOfLC[i];
-    m_iRefIdxFromIdxOfLC[i] = pSrc->m_iRefIdxFromIdxOfLC[i];
-    m_iRefIdxOfL1FromRefIdxOfL0[i] = pSrc->m_iRefIdxOfL1FromRefIdxOfL0[i];
-    m_iRefIdxOfL0FromRefIdxOfL1[i] = pSrc->m_iRefIdxOfL0FromRefIdxOfL1[i];
-  }
-  m_bRefPicListModificationFlagLC = pSrc->m_bRefPicListModificationFlagLC;
-  m_bRefPicListCombinationFlag    = pSrc->m_bRefPicListCombinationFlag;
-#endif
   m_bCheckLDC             = pSrc->m_bCheckLDC;
   m_iSliceQpDelta        = pSrc->m_iSliceQpDelta;
@@ -1012,5 +1026,4 @@
   m_activeNumILRRefIdx         = pSrc->m_activeNumILRRefIdx;
   m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
-  m_numInterLayerRefPics       = pSrc->m_numInterLayerRefPics;
   memcpy( m_interLayerPredLayerIdc, pSrc->m_interLayerPredLayerIdc, sizeof( m_interLayerPredLayerIdc ) );
 #elif REF_IDX_FRAMEWORK
@@ -1044,7 +1057,4 @@
   }
 
-#if !L0034_COMBINED_LIST_CLEANUP
-  m_bNoBackPredFlag      = pSrc->m_bNoBackPredFlag;
-#endif
   m_uiTLayer                      = pSrc->m_uiTLayer;
   m_bTLayerSwitchingFlag          = pSrc->m_bTLayerSwitchingFlag;
@@ -1351,5 +1361,9 @@
 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
 */
+#if FIX1071
+Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
+#else
 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
+#endif
 {
   TComPic* rpcPic;
@@ -1376,5 +1390,9 @@
         // and should be added to the explicit Reference Picture Set
         pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
+#if FIX1071
+        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+#else
         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
+#endif
         if(pcRPS->getDeltaPOC(k) < 0)
         {
@@ -1554,9 +1572,5 @@
   {
     m_numReorderPics[i] = 0;
-#if L0323_DPB
     m_uiMaxDecPicBuffering[i] = 1; 
-#else
-    m_uiMaxDecPicBuffering[i] = 0; 
-#endif
     m_uiMaxLatencyIncrease[i] = 0;
   }
@@ -1587,4 +1601,8 @@
   ::memset(m_numDirectRefLayers,   0, sizeof(m_numDirectRefLayers  ));
   ::memset(m_refLayerId,           0, sizeof(m_refLayerId          ));
+#if M0457_PREDICTION_INDICATIONS
+  m_directDepTypeLen = 2;
+  ::memset(m_directDependencyType, 0, sizeof(m_directDependencyType));
+#endif
 #endif
 #if DERIVE_LAYER_ID_LIST_VARIABLES
@@ -1597,4 +1615,10 @@
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   m_maxOneActiveRefLayerFlag = true;
+#endif
+#if JCTVC_M0203_INTERLAYER_PRED_IDC
+  for( Int i = 0; i < MAX_VPS_LAYER_ID_PLUS1 - 1; i++)
+  {
+    m_maxSublayerForIlpPlus1[i] = m_uiMaxTLayers + 1;
+  }
 #endif
 }
@@ -1656,7 +1680,4 @@
 , m_pcmLog2MaxSize            (  5)
 , m_uiPCMLog2MinSize          (  7)
-#if !L0034_COMBINED_LIST_CLEANUP
-, m_bUseLComb                 (false)
-#endif
 , m_bitDepthY                 (  8)
 , m_bitDepthC                 (  8)
@@ -1676,16 +1697,19 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#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
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
   {
     m_uiMaxLatencyIncrease[i] = 0;
-#if L0323_DPB
     m_uiMaxDecPicBuffering[i] = 1;
-#else
-    m_uiMaxDecPicBuffering[i] = 0;
-#endif
     m_numReorderPics[i]       = 0;
   }
@@ -1693,4 +1717,12 @@
   ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps));
   ::memset(m_usedByCurrPicLtSPSFlag, 0, sizeof(m_usedByCurrPicLtSPSFlag));
+#if M0463_VUI_EXT_ILP_REF
+  for (Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    m_minSpatialSegmentOffsetPlus1[ i ] = 0;
+    m_ctuBasedOffsetEnabledFlag   [ i ] = false;
+    m_minHorizontalCtuOffsetPlus1 [ i ] = 0;
+  }
+#endif
 }
 
@@ -1717,5 +1749,4 @@
   TComHRD *hrd = vui->getHrdParameters();
 
-#if L0043_TIMING_INFO
   TimingInfo *timingInfo = vui->getTimingInfo();
   timingInfo->setTimingInfoPresentFlag( true );
@@ -1741,28 +1772,4 @@
     break;
   }
-#else
-  hrd->setTimingInfoPresentFlag( true );
-  switch( frameRate )
-  {
-  case 24:
-    hrd->setNumUnitsInTick( 1125000 );    hrd->setTimeScale    ( 27000000 );
-    break;
-  case 25:
-    hrd->setNumUnitsInTick( 1080000 );    hrd->setTimeScale    ( 27000000 );
-    break;
-  case 30:
-    hrd->setNumUnitsInTick( 900900 );     hrd->setTimeScale    ( 27000000 );
-    break;
-  case 50:
-    hrd->setNumUnitsInTick( 540000 );     hrd->setTimeScale    ( 27000000 );
-    break;
-  case 60:
-    hrd->setNumUnitsInTick( 450450 );     hrd->setTimeScale    ( 27000000 );
-    break;
-  default:
-    hrd->setNumUnitsInTick( 1001 );       hrd->setTimeScale    ( 60000 );
-    break;
-  }
-#endif
 
   Bool rateCnt = ( bitRate > 0 );
@@ -1777,7 +1784,5 @@
     hrd->setDuCpbRemovalDelayLengthMinus1( 7 );                    // 8-bit precision ( plus 1 for last DU in AU )
     hrd->setSubPicCpbParamsInPicTimingSEIFlag( true );
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
     hrd->setDpbOutputDelayDuLengthMinus1( 5 + 7 );                 // With sub-clock tick factor of 100, at least 7 bits to have the same value as AU dpb delay
-#endif
   }
   else
@@ -1808,7 +1813,5 @@
   UInt birateValue, cpbSizeValue;
   UInt ducpbSizeValue;
-#if L0363_DU_BIT_RATE
   UInt duBitRateValue = 0;
-#endif
 
   for( i = 0; i < MAX_TLAYER; i ++ )
@@ -1822,7 +1825,5 @@
     cpbSizeValue = bitRate;                                     // 1 second
     ducpbSizeValue = bitRate/numDU;
-#if L0363_DU_BIT_RATE
     duBitRateValue = bitRate;
-#endif
     for( j = 0; j < ( hrd->getCpbCntMinus1( i ) + 1 ); j ++ )
     {
@@ -1835,7 +1836,5 @@
       hrd->setCpbSizeValueMinus1( i, j, 1, ( cpbSizeValue - 1 ) );
       hrd->setDuCpbSizeValueMinus1( i, j, 1, ( ducpbSizeValue - 1 ) );
-#if L0363_DU_BIT_RATE
       hrd->setDuBitRateValueMinus1( i, j, 1, ( duBitRateValue - 1 ) );
-#endif
       hrd->setCbrFlag( i, j, 1, ( j == 0 ) );
     }
@@ -2414,10 +2413,8 @@
   , m_profileIdc      (0)
   , m_levelIdc        (0)
-#if L0046_CONSTRAINT_FLAGS
 , m_progressiveSourceFlag  (false)
 , m_interlacedSourceFlag   (false)
 , m_nonPackedConstraintFlag(false)
 , m_frameOnlyConstraintFlag(false)
-#endif
 {
   ::memset(m_profileCompatibilityFlag, 0, sizeof(m_profileCompatibilityFlag));
@@ -2450,15 +2447,4 @@
   // Copy all information related to general profile
   this->getGeneralPTL()->copyProfileInfo(ptl->getGeneralPTL());
-}
-#endif
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-TComBitRatePicRateInfo::TComBitRatePicRateInfo()
-{
-  ::memset(m_bitRateInfoPresentFlag, 0, sizeof(m_bitRateInfoPresentFlag));
-  ::memset(m_picRateInfoPresentFlag, 0, sizeof(m_picRateInfoPresentFlag));
-  ::memset(m_avgBitRate,             0, sizeof(m_avgBitRate));
-  ::memset(m_maxBitRate,             0, sizeof(m_maxBitRate));
-  ::memset(m_constantPicRateIdc,     0, sizeof(m_constantPicRateIdc));
-  ::memset(m_avgPicRate,             0, sizeof(m_avgPicRate));
 }
 #endif
@@ -2509,48 +2495,54 @@
 #endif
 
-Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt layerID )
+Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
 {  
-  if (layerID == 0)
-  {
-    m_pcBaseColPic = NULL;
+  if(m_layerId == 0)
+  {
+    memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
     return;
   }        
-  setBaseColPic(xGetRefPic(rcListPic, getPOC())); 
+  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
 }
 #endif 
 
 #if REF_IDX_MFM
-Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic *pcRefPicBL )
-{
-  //set reference picture POC of each ILP reference 
-  Int thePoc = ilpPic[0]->getPOC(); 
-  assert(thePoc >= 0); 
-  assert(thePoc == pcRefPicBL->getPOC());
-
-  ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
-
-  //copy reference pictures marking from the reference layer
-  ilpPic[0]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
-  
-  for( Int refList = 0; refList < 2; refList++ )
-  {
-    RefPicList refPicList = RefPicList( refList );
-    
-    //set reference POC of ILP
-    ilpPic[0]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
-    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
-    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
-
-    //initialize reference POC of ILP
-    for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
-    {
-      ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
-      ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
-    }
-
-    for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
-    { 
-      ilpPic[0]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
-      ilpPic[0]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic** pcRefPicRL )
+{
+  for( UInt i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+
+    TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
+    //set reference picture POC of each ILP reference 
+    Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
+    assert(thePoc >= 0); 
+    assert(thePoc == pcRefPicBL->getPOC());
+
+    ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
+
+    //copy reference pictures marking from the reference layer
+    ilpPic[refLayerIdc]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
+
+    for( Int refList = 0; refList < 2; refList++ )
+    {
+      RefPicList refPicList = RefPicList( refList );
+
+      //set reference POC of ILP
+      ilpPic[refLayerIdc]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
+      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
+      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
+
+      //initialize reference POC of ILP
+      for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
+      {
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
+      }
+
+      for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
+      { 
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+      }
     }
   }
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 310)
@@ -191,10 +191,8 @@
   Int     m_levelIdc;
 
-#if L0046_CONSTRAINT_FLAGS
   Bool m_progressiveSourceFlag;
   Bool m_interlacedSourceFlag;
   Bool m_nonPackedConstraintFlag;
   Bool m_frameOnlyConstraintFlag;
-#endif
   
 public:
@@ -216,5 +214,4 @@
   Void  setLevelIdc(Int x)      { m_levelIdc = x; }
   
-#if L0046_CONSTRAINT_FLAGS
   Bool getProgressiveSourceFlag() const { return m_progressiveSourceFlag; }
   Void setProgressiveSourceFlag(Bool b) { m_progressiveSourceFlag = b; }
@@ -228,5 +225,4 @@
   Bool getFrameOnlyConstraintFlag() const { return m_frameOnlyConstraintFlag; }
   Void setFrameOnlyConstraintFlag(Bool b) { m_frameOnlyConstraintFlag = b; }
-#endif
 #if VPS_EXTN_PROFILE_INFO
   Void copyProfileInfo(ProfileTierLevel *ptl);
@@ -257,35 +253,4 @@
 };
 /// VPS class
-
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-class TComBitRatePicRateInfo
-{
-  Bool        m_bitRateInfoPresentFlag[MAX_TLAYER];
-  Bool        m_picRateInfoPresentFlag[MAX_TLAYER];
-  Int         m_avgBitRate[MAX_TLAYER];
-  Int         m_maxBitRate[MAX_TLAYER];
-  Int         m_constantPicRateIdc[MAX_TLAYER];
-  Int         m_avgPicRate[MAX_TLAYER];
-public:
-  TComBitRatePicRateInfo();
-  Bool        getBitRateInfoPresentFlag(Int i) {return m_bitRateInfoPresentFlag[i];}
-  Void        setBitRateInfoPresentFlag(Int i, Bool x) {m_bitRateInfoPresentFlag[i] = x;}
-
-  Bool        getPicRateInfoPresentFlag(Int i) {return m_picRateInfoPresentFlag[i];}
-  Void        setPicRateInfoPresentFlag(Int i, Bool x) {m_picRateInfoPresentFlag[i] = x;}
-
-  Int         getAvgBitRate(Int i) {return m_avgBitRate[i];}
-  Void        setAvgBitRate(Int i, Int x) {m_avgBitRate[i] = x;}
-
-  Int         getMaxBitRate(Int i) {return m_maxBitRate[i];}
-  Void        setMaxBitRate(Int i, Int x) {m_maxBitRate[i] = x;}
-
-  Int         getConstantPicRateIdc(Int i) {return m_constantPicRateIdc[i];}
-  Void        setConstantPicRateIdc(Int i, Int x) {m_constantPicRateIdc[i] = x;}
-
-  Int         getAvgPicRate(Int i) {return m_avgPicRate[i];}
-  Void        setAvgPicRate(Int i, Int x) {m_avgPicRate[i] = x;}
-};
-#endif
 
 struct HrdSubLayerInfo
@@ -300,7 +265,5 @@
   UInt ducpbSizeValue    [MAX_CPB_CNT][2];
   UInt cbrFlag           [MAX_CPB_CNT][2];
-#if L0363_DU_BIT_RATE
   UInt duBitRateValue    [MAX_CPB_CNT][2];
-#endif
 };
 
@@ -308,9 +271,4 @@
 {
 private:
-#if !L0043_TIMING_INFO
-  Bool m_timingInfoPresentFlag;
-  UInt m_numUnitsInTick;
-  UInt m_timeScale;
-#endif
   Bool m_nalHrdParametersPresentFlag;
   Bool m_vclHrdParametersPresentFlag;
@@ -319,7 +277,5 @@
   UInt m_duCpbRemovalDelayLengthMinus1;
   Bool m_subPicCpbParamsInPicTimingSEIFlag;
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   UInt m_dpbOutputDelayDuLengthMinus1;
-#endif
   UInt m_bitRateScale;
   UInt m_cpbSizeScale;
@@ -333,12 +289,5 @@
 public:
   TComHRD()
-#if !L0043_TIMING_INFO
-  :m_timingInfoPresentFlag(false)
-  ,m_numUnitsInTick(1001)
-  ,m_timeScale(60000)
-  ,m_nalHrdParametersPresentFlag(0)
-#else
   :m_nalHrdParametersPresentFlag(0)
-#endif
   ,m_vclHrdParametersPresentFlag(0)
   ,m_subPicCpbParamsPresentFlag(false)
@@ -346,7 +295,5 @@
   ,m_duCpbRemovalDelayLengthMinus1(0)
   ,m_subPicCpbParamsInPicTimingSEIFlag(false)
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   ,m_dpbOutputDelayDuLengthMinus1(0)
-#endif
   ,m_bitRateScale(0)
   ,m_cpbSizeScale(0)
@@ -357,14 +304,4 @@
 
   virtual ~TComHRD() {}
-#if !L0043_TIMING_INFO
-  Void setTimingInfoPresentFlag             ( Bool flag )  { m_timingInfoPresentFlag = flag;               }
-  Bool getTimingInfoPresentFlag             ( )            { return m_timingInfoPresentFlag;               }
-
-  Void setNumUnitsInTick                    ( UInt value ) { m_numUnitsInTick = value;                     }
-  UInt getNumUnitsInTick                    ( )            { return m_numUnitsInTick;                      }
-
-  Void setTimeScale                         ( UInt value ) { m_timeScale = value;                          }
-  UInt getTimeScale                         ( )            { return m_timeScale;                           }
-#endif
 
   Void setNalHrdParametersPresentFlag       ( Bool flag )  { m_nalHrdParametersPresentFlag = flag;         }
@@ -386,8 +323,6 @@
   Bool getSubPicCpbParamsInPicTimingSEIFlag ()             { return m_subPicCpbParamsInPicTimingSEIFlag;   }
 
-#if L0044_DU_DPB_OUTPUT_DELAY_HRD
   Void setDpbOutputDelayDuLengthMinus1      (UInt value )  { m_dpbOutputDelayDuLengthMinus1 = value;       }
   UInt getDpbOutputDelayDuLengthMinus1      ()             { return m_dpbOutputDelayDuLengthMinus1;        }
-#endif
 
   Void setBitRateScale                      ( UInt value ) { m_bitRateScale = value;                       }
@@ -430,8 +365,6 @@
   Void setDuCpbSizeValueMinus1     ( Int layer, Int cpbcnt, Int nalOrVcl, UInt value ) { m_HRD[layer].ducpbSizeValue[cpbcnt][nalOrVcl] = value;       }
   UInt getDuCpbSizeValueMinus1     ( Int layer, Int cpbcnt, Int nalOrVcl            )  { return m_HRD[layer].ducpbSizeValue[cpbcnt][nalOrVcl];        }
-#if L0363_DU_BIT_RATE
   Void setDuBitRateValueMinus1     ( Int layer, Int cpbcnt, Int nalOrVcl, UInt value ) { m_HRD[layer].duBitRateValue[cpbcnt][nalOrVcl] = value;       }
   UInt getDuBitRateValueMinus1     (Int layer, Int cpbcnt, Int nalOrVcl )              { return m_HRD[layer].duBitRateValue[cpbcnt][nalOrVcl];        }
-#endif
   Void setCbrFlag                ( Int layer, Int cpbcnt, Int nalOrVcl, UInt value ) { m_HRD[layer].cbrFlag[cpbcnt][nalOrVcl] = value;            }
   Bool getCbrFlag                ( Int layer, Int cpbcnt, Int nalOrVcl             ) { return m_HRD[layer].cbrFlag[cpbcnt][nalOrVcl];             }
@@ -439,10 +372,7 @@
   Void setNumDU                              ( UInt value ) { m_numDU = value;                            }
   UInt getNumDU                              ( )            { return m_numDU;          }
-#if L0045_CONDITION_SIGNALLING
   Bool getCpbDpbDelaysPresentFlag() { return getNalHrdParametersPresentFlag() || getVclHrdParametersPresentFlag(); }
-#endif
 };
 
-#if L0043_TIMING_INFO
 class TimingInfo
 {
@@ -475,5 +405,4 @@
   Void setNumTicksPocDiffOneMinus1          (Int x       ) { m_numTicksPocDiffOneMinus1 = x;               }
 };
-#endif
 
 class TComVPS
@@ -487,5 +416,5 @@
   UInt        m_numReorderPics[MAX_TLAYER];
   UInt        m_uiMaxDecPicBuffering[MAX_TLAYER]; 
-  UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];
+  UInt        m_uiMaxLatencyIncrease[MAX_TLAYER]; // Really max latency increase plus 1 (value 0 expresses no limit)
 
   UInt        m_numHrdParameters;
@@ -509,10 +438,5 @@
 #endif
   TComPTL     m_pcPTL;
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  TComBitRatePicRateInfo    m_bitRatePicRateInfo;
-#endif
-#if L0043_TIMING_INFO
   TimingInfo  m_timingInfo;
-#endif
 
   // ------------------------------------------
@@ -549,4 +473,8 @@
   UInt       m_numDirectRefLayers[MAX_VPS_LAYER_ID_PLUS1];
   UInt       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#if M0457_PREDICTION_INDICATIONS
+  UInt       m_directDepTypeLen;
+  UInt       m_directDependencyType[MAX_VPS_LAYER_ID_PLUS1][MAX_VPS_LAYER_ID_PLUS1];
+#endif
 #endif
 #if VPS_PROFILE_OUTPUT_LAYERS
@@ -560,4 +488,10 @@
   Bool       m_maxOneActiveRefLayerFlag;
 #endif
+#if JCTVC_M0203_INTERLAYER_PRED_IDC
+  UInt       m_maxSublayerForIlpPlus1[MAX_VPS_LAYER_ID_PLUS1 - 1];
+#endif
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  Bool       m_singleLayerForNonIrapFlag;
+#endif
 public:
   TComVPS();
@@ -626,10 +560,5 @@
 #endif
   TComPTL* getPTL() { return &m_pcPTL; }
-#if SIGNAL_BITRATE_PICRATE_IN_VPS
-  TComBitRatePicRateInfo *getBitratePicrateInfo() { return &m_bitRatePicRateInfo; }
-#endif
-#if L0043_TIMING_INFO
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
-#endif
 #if VPS_EXTN_MASK_AND_DIM_INFO
   Bool   getAvcBaseLayerFlag()                                  { return m_avcBaseLayerFlag;       }
@@ -691,4 +620,12 @@
   UInt   getRefLayerId(Int layerId, Int refLayerIdx)                            { return m_refLayerId[layerId][refLayerIdx];              }
   Void   setRefLayerId(Int layerId, Int refLayerIdx, UInt refLayerId)           { m_refLayerId[layerId][refLayerIdx] = refLayerId;        }
+
+#if M0457_PREDICTION_INDICATIONS
+  UInt   getDirectDepTypeLen()                                                  { return m_directDepTypeLen;                              }
+  Void   setDirectDepTypeLen(UInt x)                                            { m_directDepTypeLen = x;                                 }
+
+  UInt   getDirectDependencyType(Int currLayerId, Int refLayerId)               { return m_directDependencyType[currLayerId][refLayerId]; }
+  Void   setDirectDependencyType(Int currLayerId, Int refLayerId, UInt x)       { m_directDependencyType[currLayerId][refLayerId] = x;    }
+#endif
 #endif
 #if VPS_PROFILE_OUTPUT_LAYERS
@@ -712,4 +649,12 @@
   Void   setMaxOneActiveRefLayerFlag(Bool x)                                    { m_maxOneActiveRefLayerFlag = x;                         }
 #endif 
+#if JCTVC_M0203_INTERLAYER_PRED_IDC
+  Bool   getMaxSublayerForIlpPlus1(Int layerId)                     { return m_maxSublayerForIlpPlus1[layerId];                   }
+  Void   setMaxSublayerForIlpPlus1(Int layerId, UInt maxSublayer)   { m_maxSublayerForIlpPlus1[layerId] = maxSublayer;            }
+#endif
+#if M0040_ADAPTIVE_RESOLUTION_CHANGE
+  Bool   getSingleLayerForNonIrapFlag()                             { return m_singleLayerForNonIrapFlag; }
+  Void   setSingleLayerForNonIrapFlag(Bool x)                       { m_singleLayerForNonIrapFlag = x;    }
+#endif
 };
 
@@ -788,10 +733,9 @@
   Int  m_log2MaxMvLengthVertical;
   TComHRD m_hrdParameters;
-#if L0043_TIMING_INFO
   TimingInfo m_timingInfo;
-#else
-  Bool m_pocProportionalToTimingFlag;
-  Int  m_numTicksPocDiffOneMinus1;
-#endif
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+  Bool m_tileBoundariesAlignedFlag;
+#endif
+
 
 public:
@@ -826,7 +770,6 @@
     ,m_log2MaxMvLengthHorizontal(15)
     ,m_log2MaxMvLengthVertical(15)
-#if !L0043_TIMING_INFO  
-    ,m_pocProportionalToTimingFlag(false)
-    ,m_numTicksPocDiffOneMinus1(0)
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+    ,m_tileBoundariesAlignedFlag(true)
 #endif
   {}
@@ -924,11 +867,8 @@
 
   TComHRD* getHrdParameters                 ()             { return &m_hrdParameters; }
-#if L0043_TIMING_INFO
   TimingInfo* getTimingInfo() { return &m_timingInfo; }
-#else
-  Bool getPocProportionalToTimingFlag() {return m_pocProportionalToTimingFlag; }
-  Void setPocProportionalToTimingFlag(Bool x) {m_pocProportionalToTimingFlag = x;}
-  Int  getNumTicksPocDiffOneMinus1() {return m_numTicksPocDiffOneMinus1;}
-  Void setNumTicksPocDiffOneMinus1(Int x) { m_numTicksPocDiffOneMinus1 = x;}
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+  Bool getTileBoundariesAlignedFlag(  ) { return m_tileBoundariesAlignedFlag; } 
+  Void setTileBoundariesAlignedFlag( Bool flag ) { m_tileBoundariesAlignedFlag = flag; } 
 #endif
 };
@@ -971,8 +911,4 @@
   Bool        m_useAMP;
 
-#if !L0034_COMBINED_LIST_CLEANUP
-  Bool        m_bUseLComb;
-#endif
-  
   // Parameter
   Int         m_bitDepthY;
@@ -1003,5 +939,5 @@
   TComScalingList*     m_scalingList;   //!< ScalingList class pointer
   UInt        m_uiMaxDecPicBuffering[MAX_TLAYER]; 
-  UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];
+  UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];  // Really max latency increase plus 1 (value 0 expresses no limit)
 
   Bool        m_useDF;
@@ -1015,12 +951,23 @@
   TComPTL     m_pcPTL;
 
+#if M0463_VUI_EXT_ILP_REF
+  Bool        m_interViewMvVertConstraintFlag;
+  Int         m_numIlpRestrictedRefLayers        ;
+  Int         m_minSpatialSegmentOffsetPlus1[MAX_LAYERS];
+  Bool        m_ctuBasedOffsetEnabledFlag   [MAX_LAYERS];
+  Int         m_minHorizontalCtuOffsetPlus1 [MAX_LAYERS];
+#endif
+
 #if SVC_EXTENSION
   UInt m_layerId;
 #endif
 #if REF_IDX_MFM
+#if !M0457_COL_PICTURE_SIGNALING
   Bool m_bMFMEnabledFlag;
 #endif
+#endif
 #if SCALED_REF_LAYER_OFFSETS
-  Window      m_scaledRefLayerWindow;
+  UInt        m_numScaledRefLayerOffsets;
+  Window      m_scaledRefLayerWindow[MAX_LAYERS];
 #endif
 public:
@@ -1098,9 +1045,4 @@
   
   // Tool list
-#if !L0034_COMBINED_LIST_CLEANUP
-  Void setUseLComb    (Bool b)   { m_bUseLComb = b;         }
-  Bool getUseLComb    ()         { return m_bUseLComb;      }
-#endif
-
   Bool getUseLossless ()         { return m_useLossless; }
   Void setUseLossless ( Bool b ) { m_useLossless  = b; }
@@ -1156,13 +1098,34 @@
 
 #if SVC_EXTENSION
+#if M0463_VUI_EXT_ILP_REF
+  Void setInterViewMvVertConstraintFlag(Bool val) { m_interViewMvVertConstraintFlag = val; }
+  Bool getInterViewMvVertConstraintFlag()         { return m_interViewMvVertConstraintFlag;}
+
+  ////  sps_extension_vui_parameters( )
+  Void setNumIlpRestrictedRefLayers   ( Int val )        { m_numIlpRestrictedRefLayers         = val;}
+  Int  getNumIlpRestrictedRefLayers   ( )                { return m_numIlpRestrictedRefLayers        ;}
+
+  Void setMinSpatialSegmentOffsetPlus1( Int i, Int val ) { m_minSpatialSegmentOffsetPlus1[ i ] = val;}
+  Int  getMinSpatialSegmentOffsetPlus1( Int i )          { return m_minSpatialSegmentOffsetPlus1[ i ];}
+
+  Void setCtuBasedOffsetEnabledFlag   ( Int i, Bool flag ) { m_ctuBasedOffsetEnabledFlag   [ i ] = flag;}
+  Bool getCtuBasedOffsetEnabledFlag   ( Int i )            { return m_ctuBasedOffsetEnabledFlag   [ i ];}
+
+  Void setMinHorizontalCtuOffsetPlus1 ( Int i, Int val )   { m_minHorizontalCtuOffsetPlus1 [ i ] = val;}
+  Int  getMinHorizontalCtuOffsetPlus1 ( Int i )            { return m_minHorizontalCtuOffsetPlus1 [ i ];}
+#endif
   Void     setLayerId(UInt layerId) { m_layerId = layerId; }
   UInt     getLayerId() { return m_layerId; }
 #endif
 #if REF_IDX_MFM
+#if !M0457_COL_PICTURE_SIGNALING
   Void     setMFMEnabledFlag(Bool flag) {m_bMFMEnabledFlag = flag;}
   Bool     getMFMEnabledFlag()          {return m_bMFMEnabledFlag;}
 #endif
+#endif
 #if SCALED_REF_LAYER_OFFSETS
-  Window&  getScaledRefLayerWindow(     )   { return m_scaledRefLayerWindow; }
+  UInt     getNumScaledRefLayerOffsets()  { return m_numScaledRefLayerOffsets; }
+  Void     setNumScaledRefLayerOffsets(Int x)  { m_numScaledRefLayerOffsets = x; }
+  Window&  getScaledRefLayerWindow( Int x )   { return m_scaledRefLayerWindow[x]; }
 #endif
 };
@@ -1431,17 +1394,10 @@
 #endif
 #endif 
-#if L0034_COMBINED_LIST_CLEANUP
+#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
-#else
-  Int         m_aiNumRefIdx   [3];    //  for multiple reference of current slice
-  Int         m_iRefIdxOfLC[2][MAX_NUM_REF_LC];
-  Int         m_eListIdFromIdxOfLC[MAX_NUM_REF_LC];
-  Int         m_iRefIdxFromIdxOfLC[MAX_NUM_REF_LC];
-  Int         m_iRefIdxOfL1FromRefIdxOfL0[MAX_NUM_REF_LC];
-  Int         m_iRefIdxOfL0FromRefIdxOfL1[MAX_NUM_REF_LC];
-  Bool        m_bRefPicListModificationFlagLC;
-  Bool        m_bRefPicListCombinationFlag;
-#endif
 
   Bool        m_bCheckLDC;
@@ -1459,4 +1415,8 @@
   Bool        m_bRefenced;
   
+#if SH_DISCARDABLE_FLAG
+  Bool        m_bDiscardableFlag;
+#endif
+
   // access channel
   TComVPS*    m_pcVPS;
@@ -1481,12 +1441,18 @@
 
   Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
-#if !L0034_COMBINED_LIST_CLEANUP
-  Bool        m_bNoBackPredFlag;
-#endif
   UInt        m_uiTLayer;
 #if SVC_EXTENSION
   UInt        m_layerId;
-  TComPic*    m_pcBaseColPic;
-  TComPicYuv* m_pcFullPelBaseRec;
+  TComPic*    m_pcBaseColPic[MAX_LAYERS];
+  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
+#if REF_IDX_FRAMEWORK && 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;
@@ -1525,5 +1491,4 @@
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
   Bool       m_interLayerPredEnabledFlag;
-  Int        m_numInterLayerRefPics;
 #endif 
 public:
@@ -1595,17 +1560,5 @@
   Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
   Int       getNumRpsCurrTempList();
-#if L0034_COMBINED_LIST_CLEANUP
   Int       getList1IdxToList0Idx ( Int list1Idx )               { return m_list1IdxToList0Idx[list1Idx]; }
-#else
-  Int       getRefIdxOfLC       (RefPicList e, Int iRefIdx)     { return m_iRefIdxOfLC[e][iRefIdx];           }
-  Int       getListIdFromIdxOfLC(Int iRefIdx)                   { return m_eListIdFromIdxOfLC[iRefIdx];       }
-  Int       getRefIdxFromIdxOfLC(Int iRefIdx)                   { return m_iRefIdxFromIdxOfLC[iRefIdx];       }
-  Int       getRefIdxOfL0FromRefIdxOfL1(Int iRefIdx)            { return m_iRefIdxOfL0FromRefIdxOfL1[iRefIdx];}
-  Int       getRefIdxOfL1FromRefIdxOfL0(Int iRefIdx)            { return m_iRefIdxOfL1FromRefIdxOfL0[iRefIdx];}
-  Bool      getRefPicListModificationFlagLC()                   {return m_bRefPicListModificationFlagLC;}
-  Void      setRefPicListModificationFlagLC(Bool bflag)         {m_bRefPicListModificationFlagLC=bflag;}     
-  Bool      getRefPicListCombinationFlag()                      {return m_bRefPicListCombinationFlag;}
-  Void      setRefPicListCombinationFlag(Bool bflag)            {m_bRefPicListCombinationFlag=bflag;}   
-#endif
   Void      setReferenced(Bool b)                               { m_bRefenced = b; }
   Bool      isReferenced()                                      { return m_bRefenced; }
@@ -1616,4 +1569,14 @@
   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 SH_DISCARDABLE_FLAG
+  Bool      getDiscardableFlag  ()                              { return m_bDiscardableFlag; }
+  Void      setDiscardableFlag  (Bool b)                        { m_bDiscardableFlag = b; }
+#endif
+
   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
   Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
@@ -1638,5 +1601,9 @@
 
 #if FIX1071
+#if SVC_EXTENSION
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL );
+#else
+  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
+#endif
 #else
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
@@ -1674,11 +1641,5 @@
   
   static Void      sortPicList         ( TComList<TComPic*>& rcListPic );
-#if L0034_COMBINED_LIST_CLEANUP
   Void setList1IdxToList0Idx();
-#else
-  Bool getNoBackPredFlag() { return m_bNoBackPredFlag; }
-  Void setNoBackPredFlag( Bool b ) { m_bNoBackPredFlag = b; }
-  Void generateCombinedList       ();
-#endif
 
   UInt getTLayer             ()                            { return m_uiTLayer;                      }
@@ -1691,5 +1652,9 @@
   Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
   Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
+#if FIX1071
+  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
+#else
   Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet);
+#endif
 
   Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
@@ -1764,13 +1729,14 @@
 
 #if SVC_EXTENSION
-  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
-  Void      setBaseColPic       ( TComPic* p)     { m_pcBaseColPic = p; }
-  TComPic*  getBaseColPic       ()                { return m_pcBaseColPic; }
+  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt refLayerIdc );
+  Void      setBaseColPic       (UInt refLayerIdc, TComPic* p)     { m_pcBaseColPic[refLayerIdc] = p; }
+  TComPic*  getBaseColPic       (UInt refLayerIdc)                { return m_pcBaseColPic[refLayerIdc]; }
+  TComPic** getBaseColPic       ()                { return &m_pcBaseColPic[0]; }
 
   Void      setLayerId (UInt layerId)   { m_layerId = layerId; }
   UInt      getLayerId ()               { return m_layerId;    }
 
-  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
-  TComPicYuv* getFullPelBaseRec   ()               { return  m_pcFullPelBaseRec;  }
+  Void        setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
+  TComPicYuv* getFullPelBaseRec   (UInt refLayerIdc)               { return  m_pcFullPelBaseRec[refLayerIdc];  }
 
 #if AVC_SYNTAX
@@ -1783,5 +1749,5 @@
 
 #if REF_IDX_MFM
-  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
+  Void      setRefPOCListILP(TComPic** ilpPic, TComPic** pcRefPicRL);
 #endif
 
@@ -1790,16 +1756,44 @@
   Void      setActiveNumILRRefIdx     ( Int i )         { m_activeNumILRRefIdx = i;     }  
 
-  Int       getInterLayerPredLayerIdc (UInt Idx )               { return  m_interLayerPredLayerIdc[Idx];}
-  Void      setInterLayerPredLayerIdc (UInt val, UInt Idx)      { m_interLayerPredLayerIdc[Idx] = val;  }
+  Int       getInterLayerPredLayerIdc (UInt layerIdx)                        { return  m_interLayerPredLayerIdc[layerIdx];}
+  Void      setInterLayerPredLayerIdc (UInt refLayerIdc, UInt layerIdx)      { m_interLayerPredLayerIdc[layerIdx] = refLayerIdc;  }
 
   Void      setInterLayerPredEnabledFlag     ( Bool   val )    { m_interLayerPredEnabledFlag = val; }
   Bool      getInterLayerPredEnabledFlag     ()                { return m_interLayerPredEnabledFlag;}
-
-  Void      setNumInterLayerRefPics          ( UInt   val )    { m_numInterLayerRefPics = val; }
-  UInt      getNumInterLayerRefPics          ()                { return m_numInterLayerRefPics;}  
 #else
   Void      setNumILRRefIdx     ( Int i )               { m_numILRRefIdx = i;     }
 #endif 
-#endif
+
+#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
+  Int       getNumSamplePredRefLayers      ( )          { return  m_numSamplePredRefLayers;       }
+  Void      setNumSamplePredRefLayers      ( Int i )    { m_numSamplePredRefLayers = i;           }
+  Bool      getInterLayerSamplePredOnlyFlag( )          { return  m_interLayerSamplePredOnlyFlag; }
+  Void      setInterLayerSamplePredOnlyFlag( Bool val ) { m_interLayerSamplePredOnlyFlag = val;   }
+#endif
+
+#if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
+  Void      setNumMotionPredRefLayers(int i)            { m_numMotionPredRefLayers = i; }
+  Int       getNumMotionPredRefLayers()                 { return m_numMotionPredRefLayers; }
+#if REF_IDX_MFM
+  Void      setMFMEnabledFlag(Bool flag)                { m_bMFMEnabledFlag = flag; }
+  Bool      getMFMEnabledFlag()                         { return m_bMFMEnabledFlag; }
+  Void      setColRefLayerIdx(Int i)                    { m_colRefLayerIdx = i;     }
+  Int       getColRefLayerIdx()                         { return m_colRefLayerIdx;  }
+  Void      setAltColIndicationFlag(Bool i)             { m_altColIndicationFlag = i; }
+  Bool      getAltColIndicationFlag()                   { return m_altColIndicationFlag; }
+  Void      setMotionPredIlp(TComPic *ilpPic)           { m_pcIlpPic = ilpPic; }
+  TComPic*  getMotionPredIlp()                          { return m_pcIlpPic; }
+#endif
+#endif
+
+#else
+  // temporal solution for IntraBL. Only one reference layer is supported.
+  Int       getActiveNumILRRefIdx     ( )               { return  1; }
+  Int       getInterLayerPredLayerIdc (UInt layerIdx)   { return  m_layerId - 1;}
+  Void      setActiveNumILRRefIdx     ( Int i )         {}
+  Void      setInterLayerPredEnabledFlag( Bool   val )  {}
+#endif
+
+TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
 
 #endif //SVC_EXTENSION
Index: trunk/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 310)
@@ -1075,13 +1075,12 @@
     Int iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;  // Represents scaling through forward transform
 
-    Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
-
-    iAdd = (pcCU->getSlice()->getSliceType()==I_SLICE ? 171 : 85) << (iQBits-9);
-
 #if ADAPTIVE_QP_SELECTION
-    iQBits = QUANT_SHIFT + cQpBase.m_iPer + iTransformShift;
+    Int iQBits = QUANT_SHIFT + cQpBase.m_iPer + iTransformShift;
     iAdd = (pcCU->getSlice()->getSliceType()==I_SLICE ? 171 : 85) << (iQBits-9);
     Int iQBitsC = QUANT_SHIFT + cQpBase.m_iPer + iTransformShift - ARL_C_PRECISION;  
     Int iAddC   = 1 << (iQBitsC-1);
+#else
+    Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
+    iAdd = (pcCU->getSlice()->getSliceType()==I_SLICE ? 171 : 85) << (iQBits-9);
 #endif
 
@@ -1364,19 +1363,14 @@
 #else
   Int j;
-  {
-    Short block[ 64 * 64 ];
-    Short coeff[ 64 * 64 ];
-    {
-      for (j = 0; j < iHeight; j++)
-      {    
-        memcpy( block + j * iWidth, piBlkResi + j * uiStride, iWidth * sizeof( Short ) );
-      }
-    }
-    xTrMxN(bitDepth, block, coeff, iWidth, iHeight, uiMode );
-    for ( j = 0; j < iHeight * iWidth; j++ )
-    {    
-      psCoeff[ j ] = coeff[ j ];
-    }
-    return ;
+  Short block[ 32 * 32 ];
+  Short coeff[ 32 * 32 ];
+  for (j = 0; j < iHeight; j++)
+  {    
+    memcpy( block + j * iWidth, piBlkResi + j * uiStride, iWidth * sizeof( Short ) );
+  }
+  xTrMxN(bitDepth, block, coeff, iWidth, iHeight, uiMode );
+  for ( j = 0; j < iHeight * iWidth; j++ )
+  {    
+    psCoeff[ j ] = coeff[ j ];
   }
 #endif  
@@ -1399,6 +1393,6 @@
   Int j;
   {
-    Short block[ 64 * 64 ];
-    Short coeff[ 64 * 64 ];
+    Short block[ 32 * 32 ];
+    Short coeff[ 32 * 32 ];
     for ( j = 0; j < iHeight * iWidth; j++ )
     {    
@@ -1522,8 +1516,5 @@
                                                       UInt                            uiAbsPartIdx )
 {
-  Int    iQBits      = m_cQP.m_iBits;
-  Double dTemp       = 0;
   UInt uiLog2TrSize = g_aucConvertToBit[ uiWidth ] + 2;
-  Int uiQ = g_quantScales[m_cQP.rem()];
   
   UInt uiBitDepth = eTType == TEXT_LUMA ? g_bitDepthY : g_bitDepthC;
@@ -1536,6 +1527,5 @@
   assert(scalingListType < 6);
   
-  iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                   // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
-  Double dErrScale   = 0;
+  Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                   // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
   Double *pdErrScaleOrg = getErrScaleCoeff(scalingListType,uiLog2TrSize-2,m_cQP.m_iRem);
   Int *piQCoefOrg = getQuantCoeff(scalingListType,m_cQP.m_iRem,uiLog2TrSize-2);
@@ -1589,5 +1579,4 @@
   Double  d64BaseCost         = 0;
   Int     iLastScanPos        = -1;
-  dTemp                       = dErrScale;
   
   UInt    c1Idx     = 0;
@@ -1618,6 +1607,6 @@
       UInt    uiBlkPos          = scan[iScanPos];
       // set coeff
-      uiQ  = piQCoef[uiBlkPos];
-      dTemp = pdErrScale[uiBlkPos];
+      Int uiQ  = piQCoef[uiBlkPos];
+      Double dTemp = pdErrScale[uiBlkPos];
       Int lLevelDouble          = plSrcCoeff[ uiBlkPos ];
       lLevelDouble              = (Int)min<Int64>((Int64)abs((Int)lLevelDouble) * uiQ , MAX_INT - (1 << (iQBits - 1)));
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 310)
@@ -4,16 +4,6 @@
 
 #if SVC_UPSAMPLING
-// ====================================================================================================================
-// Tables:
-// 1. PHASE_DERIVATION_IN_INTEGER = 0 is the implementation using 2 multi-phase (12 phase and 8 phase) filter sets 
-//    by following K0378.
-// 2. PHASE_DERIVATION_IN_INTEGER = 1 is the implemetation using a 16-phase filter set just for speed up. Some phases 
-//    is approximated to x/16 (e.g. 1/3 -> 5/16). 
-// 3. It was confirmed that two implementations provides the identical result. 
-// 4. By default, PHASE_DERIVATION_IN_INTEGER is set to 1. 
-// ====================================================================================================================
 #define CNU -1 ///< Coefficients Not Used
 
-#if PHASE_DERIVATION_IN_INTEGER
 const Int TComUpsampleFilter::m_lumaFixedFilter[16][NTAPS_US_LUMA] =
 {
@@ -74,49 +64,4 @@
 #endif
 };
-#else
-const Int TComUpsampleFilter::m_lumaFixedFilter[12][NTAPS_US_LUMA] =
-{
-  { 0,  0,   0, 64,  0,   0, 0,  0},
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//1/12 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//2/12 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//3/12 
-  { -1, 4, -11, 52, 26,  -8, 3, -1},//4/12 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//5/12 
-  { -1, 4, -11, 40, 40, -11, 4, -1},//6/12       
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//7/12 
-  { -1, 3,  -8, 26, 52, -11, 4, -1},//8/12 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//9/12 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//10/12
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU},//11/12
-};
-
-const Int TComUpsampleFilter::m_chromaFixedFilter15[12][NTAPS_US_CHROMA] =
-{
-  {  0, 64,  0,  0},
-  {CNU,CNU,CNU,CNU},//1/12 
-  {CNU,CNU,CNU,CNU},//2/12 
-  { -4, 54, 16, -2},//3/12 
-  { -5, 50, 22, -3},//4/12 
-  {CNU,CNU,CNU,CNU},//5/12 
-  {CNU,CNU,CNU,CNU},//6/12 
-  { -4, 30, 43, -5},//7/12 
-  { -3, 22, 50, -5},//8/12 
-  {CNU,CNU,CNU,CNU},//9/12 
-  {CNU,CNU,CNU,CNU},//10/12
-  { -1,  5, 62, -2} //11/12
-};
-
-const Int TComUpsampleFilter::m_chromaFixedFilter20[8][NTAPS_US_CHROMA] =
-{
-  {  0, 64,  0,  0},
-  {CNU,CNU,CNU,CNU},//1/8 
-  {CNU,CNU,CNU,CNU},//2/8 
-  { -6, 46, 28, -4},//3/8 
-  { -4, 36, 36, -4},//4/8 
-  {CNU,CNU,CNU,CNU},//5/8 
-  {CNU,CNU,CNU,CNU},//6/8 
-  { -2, 10, 58, -2},//7/8 
-};
-#endif
 
 TComUpsampleFilter::TComUpsampleFilter(void)
@@ -129,7 +74,7 @@
 
 #if SCALED_REF_LAYER_OFFSETS
-Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
-#else
-Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+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
 {
@@ -165,50 +110,30 @@
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
   Pel* piDstBufY  = pcUsPic->getLumaAddr();
-  
+
   Pel* piSrcY;
   Pel* piDstY;
-  
+
   Pel* piTempBufU = pcTempPic->getCbAddr();
   Pel* piSrcBufU  = pcBasePic->getCbAddr();
   Pel* piDstBufU  = pcUsPic->getCbAddr();
-  
+
   Pel* piTempBufV = pcTempPic->getCrAddr();
   Pel* piSrcBufV  = pcBasePic->getCrAddr();
   Pel* piDstBufV  = pcUsPic->getCrAddr();
-  
+
   Pel* piSrcU;
   Pel* piDstU;
   Pel* piSrcV;
   Pel* piDstV;
-  
-#if JCTVC_L0178
-  Pel *tempBufRight = NULL, *tempBufBottom = NULL;
-  Int tempBufSizeRight = 0, tempBufSizeBottom = 0;
-  
-  if( confBL.getWindowRightOffset())
-  {
-    tempBufSizeRight = confBL.getWindowRightOffset() * pcBasePic->getHeight();
-  }
-  
-  if( confBL.getWindowBottomOffset() )
-  {
-    tempBufSizeBottom = confBL.getWindowBottomOffset() * pcBasePic->getWidth ();
-  }
-  
-  if( tempBufSizeRight )
-  {
-    tempBufRight = (Pel *) xMalloc(Pel, tempBufSizeRight + (tempBufSizeRight>>1) );
-    assert( tempBufRight );
-  }
-  
-  if( tempBufSizeBottom )
-  {
-    tempBufBottom = (Pel *) xMalloc(Pel, tempBufSizeBottom + (tempBufSizeBottom>>1) );
-    assert( tempBufBottom );
-  }
- 
-#endif
-
-  if( widthEL == widthBL && heightEL == heightBL )
+
+#if SIMPLIFIED_MV_POS_SCALING
+  Int scaleX = g_posScalingFactor[refLayerIdc][0];
+  Int scaleY = g_posScalingFactor[refLayerIdc][1];
+#else
+  Int   scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
+  Int   scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
+#endif
+
+  if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
   {
     piSrcY = piSrcBufY - scalEL.getWindowLeftOffset() - scalEL.getWindowTopOffset() * strideEL;
@@ -248,514 +173,344 @@
   else
   {
-#if PHASE_DERIVATION_IN_INTEGER
-  Int refPos16 = 0;
-  Int phase    = 0;
-  Int refPos   = 0; 
-  Int* coeff = m_chromaFilter[phase];
-  for ( i = 0; i < 16; i++)
-  {
-    memcpy(   m_lumaFilter[i],   m_lumaFixedFilter[i], sizeof(Int) * NTAPS_US_LUMA   );
-    memcpy( m_chromaFilter[i], m_chromaFixedFilter[i], sizeof(Int) * NTAPS_US_CHROMA );
-  }
-#else
-  for ( i = 0; i < 12; i++)
-  {
-    memcpy( m_lumaFilter[i], m_lumaFixedFilter[i], sizeof(Int) * NTAPS_US_LUMA );
-  }
-
-  Int chromaPhaseDenominator;
-  if (widthEL == 2*widthBL) // 2x scalability
-  {
-    for ( i = 0; i < 8; i++)
-    {
-      memcpy( m_chromaFilter[i], m_chromaFixedFilter20[i], sizeof(Int) * NTAPS_US_CHROMA );
-    }
-    chromaPhaseDenominator = 8;
-  }
-  else
-  {
-    for ( i = 0; i < 12; i++) // 1.5x scalability
-    {
-      memcpy( m_chromaFilter[i], m_chromaFixedFilter15[i], sizeof(Int) * NTAPS_US_CHROMA );
-    }
-    chromaPhaseDenominator = 12;
-  }
-#endif
-
-  assert ( widthEL == widthBL || widthEL == 2*widthBL || 2*widthEL == 3*widthBL );
-  assert ( heightEL == heightBL || heightEL == 2*heightBL || 2*heightEL == 3*heightBL );
-
-#if JCTVC_L0178
-  // save the cropped region to copy back to the base picture since the base picture might be used as a reference picture
-  if( tempBufSizeRight )
-  {
-    piSrcY = piSrcBufY + widthBL;
-    piDstY = tempBufRight;
-    for( i = 0; i < pcBasePic->getHeight(); i++ )
-    {
-      memcpy(piDstY, piSrcY, sizeof(Pel) * confBL.getWindowRightOffset());
-      piSrcY += strideBL;
-      piDstY += confBL.getWindowRightOffset();
-    }
-    
-    if(confBL.getWindowRightOffset()>>1)
-    {
-      Int strideBLChroma = (strideBL>>1);
-      piSrcU = piSrcBufU + (widthBL>>1);
-      piDstU = tempBufRight + confBL.getWindowRightOffset() * pcBasePic->getHeight();
-      piSrcV = piSrcBufV + (widthBL>>1);
-      piDstV = piDstU + (confBL.getWindowRightOffset()>>1) * (pcBasePic->getHeight()>>1);
-    
-      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
-      {
-        memcpy(piDstU, piSrcU, sizeof(Pel) * (confBL.getWindowRightOffset()>>1));
-        piSrcU += strideBLChroma;
-        piDstU += (confBL.getWindowRightOffset()>>1);
-        
-        memcpy(piDstV, piSrcV, sizeof(Pel) * (confBL.getWindowRightOffset()>>1));
-        piSrcV += strideBLChroma;
-        piDstV += (confBL.getWindowRightOffset()>>1);
-      }
-    }
-    
-    pcBasePic->setWidth(widthBL);
-  }
-  
-  if( tempBufSizeBottom )
-  {
-    piSrcY = piSrcBufY + heightBL * strideBL;
-    piDstY = tempBufBottom;
-    for( i = 0; i < confBL.getWindowBottomOffset(); i++ )
-    {
-      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
-      piSrcY += strideBL;
-      piDstY += pcBasePic->getWidth();
-    }
-    
-    if(confBL.getWindowBottomOffset()>>1)
-    {
-      Int strideBLChroma = (strideBL>>1);
-      piSrcU = piSrcBufU + (heightBL>>1) * strideBLChroma;
-      piDstU = tempBufBottom + confBL.getWindowBottomOffset() * pcBasePic->getWidth();
-      piSrcV = piSrcBufV + (heightBL>>1) * strideBLChroma;
-      piDstV = piDstU + (confBL.getWindowBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
+    Int refPos16 = 0;
+    Int phase    = 0;
+    Int refPos   = 0; 
+    Int* coeff = m_chromaFilter[phase];
+    for ( i = 0; i < 16; i++)
+    {
+      memcpy(   m_lumaFilter[i],   m_lumaFixedFilter[i], sizeof(Int) * NTAPS_US_LUMA   );
+      memcpy( m_chromaFilter[i], m_chromaFixedFilter[i], sizeof(Int) * NTAPS_US_CHROMA );
+    }
+
+    assert ( widthEL == widthBL || widthEL == 2*widthBL || 2*widthEL == 3*widthBL );
+    assert ( heightEL == heightBL || heightEL == 2*heightBL || 2*heightEL == 3*heightBL );
+
+    pcBasePic->setBorderExtension(false);
+    pcBasePic->extendPicBorder   (); // extend the border.
+
+    Int   shiftX = 16;
+    Int   shiftY = 16;
+
+    Int   phaseX = 0;
+    Int   phaseY = 0;
+
+    Int   addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    Int   addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+
+    Int   deltaX     = 4 * phaseX;
+    Int   deltaY     = 4 * phaseY;  
+
+    Int shiftXM4 = shiftX - 4;
+    Int shiftYM4 = shiftY - 4;
+
+#if ILP_DECODED_PICTURE
+    widthEL   = pcUsPic->getWidth ();
+    heightEL  = pcUsPic->getHeight();
+
+    widthBL   = pcBasePic->getWidth ();
+    heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
+#endif
+#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();
+#endif
+
+    //========== horizontal upsampling ===========
+    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;
+      coeff = m_lumaFilter[phase];
+
+      piSrcY = piSrcBufY + refPos -((NTAPS_US_LUMA>>1) - 1);
+      piDstY = piTempBufY + i;
+
+      for( j = 0; j < heightBL ; j++ )
+      {
+        *piDstY = sumLumaHor(piSrcY, coeff);
+        piSrcY += strideBL;
+        piDstY += strideEL;
+      }
+    }
+
+    //========== vertical upsampling ===========
+    pcTempPic->setBorderExtension(false);
+    pcTempPic->setHeight(heightBL);
+    pcTempPic->extendPicBorder   (); // extend the border.
+    pcTempPic->setHeight(heightEL);
+
+    const Int nShift = US_FILTER_PREC*2;
+    Int iOffset = 1 << (nShift - 1); 
+
+#if SCALED_REF_LAYER_OFFSETS
+    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;
+      coeff = m_lumaFilter[phase];
+
+      piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
+#if SCALED_REF_LAYER_OFFSETS
+#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
+#else
+      piDstY = piDstBufY + j * strideEL;
+
+      for( i = 0; i < widthEL; i++ )
+      {
+        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcY++;
+        piDstY++;
+      }
+#endif
+    }
+
+#if ILP_DECODED_PICTURE
+#if SCALED_REF_LAYER_OFFSETS
+    widthBL   = pcBasePic->getWidth ();
+    heightBL  = pcBasePic->getHeight();
+
+    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
+#endif
+
+    //========== UV component upsampling ===========
+
+    widthEL  >>= 1;
+    heightEL >>= 1;
+
+    widthBL  >>= 1;
+    heightBL >>= 1;
+
+    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);
+#endif
+
+    shiftX = 16;
+    shiftY = 16;
+
+    phaseX = 0;
+    phaseY = 1;
+
+    addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
+    addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
+
+    deltaX     = 4 * phaseX;
+    deltaY     = 4 * phaseY;
+
+    shiftXM4 = shiftX - 4;
+    shiftYM4 = shiftY - 4;
+
+#if !SIMPLIFIED_MV_POS_SCALING
+    scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
+    scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
+#endif
+
+#if ILP_DECODED_PICTURE
+    widthEL   = pcUsPic->getWidth () >> 1;
+    heightEL  = pcUsPic->getHeight() >> 1;
+
+    widthBL   = pcBasePic->getWidth () >> 1;
+    heightBL  = min<Int>( pcBasePic->getHeight() >> 1, heightEL );
+#endif
+
+    //========== horizontal upsampling ===========
+    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;
+      coeff = m_chromaFilter[phase];
+
+      piSrcU = piSrcBufU + refPos -((NTAPS_US_CHROMA>>1) - 1);
+      piSrcV = piSrcBufV + refPos -((NTAPS_US_CHROMA>>1) - 1);
+      piDstU = piTempBufU + i;
+      piDstV = piTempBufV + i;
+
+      for( j = 0; j < heightBL ; j++ )
+      {
+        *piDstU = sumChromaHor(piSrcU, coeff);
+        *piDstV = sumChromaHor(piSrcV, coeff);
+
+        piSrcU += strideBL;
+        piSrcV += strideBL;
+        piDstU += strideEL;
+        piDstV += strideEL;
+      }
+    }
+
+    //========== vertical upsampling ===========
+    pcTempPic->setBorderExtension(false);
+    pcTempPic->setHeight(heightBL << 1);
+    pcTempPic->extendPicBorder   (); // extend the border.
+    pcTempPic->setHeight(heightEL << 1);
+
+#if SCALED_REF_LAYER_OFFSETS
+    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; 
+      coeff = m_chromaFilter[phase];
       
-      for( i = 0; i < confBL.getWindowBottomOffset()>>1; i++ )
-      {
-        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
-        piSrcU += strideBLChroma;
-        piDstU += (pcBasePic->getWidth()>>1);
-        
-        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
-        piSrcV += strideBLChroma;
-        piDstV += (pcBasePic->getWidth()>>1);
-      }
-    }
-
-    pcBasePic->setHeight(heightBL);
-  }
-#endif
-  
-  pcBasePic->setBorderExtension(false);
-  pcBasePic->extendPicBorder   (); // extend the border.
-
-#if PHASE_DERIVATION_IN_INTEGER
-  Int   shiftX = 16;
-  Int   shiftY = 16;
-
-  Int   phaseX = 0;
-  Int   phaseY = 0;
-
-  Int   addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-  Int   addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-
-  Int   deltaX     = 4 * phaseX;
-  Int   deltaY     = 4 * phaseY;  
-  
-  Int shiftXM4 = shiftX - 4;
-  Int shiftYM4 = shiftY - 4;
-
-  Int   scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
-  Int   scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
-#else
-  const Double sFactor = 1.0 * widthBL / widthEL;
-  const Double sFactor12 = sFactor * 12;
-#endif
-#if ILP_DECODED_PICTURE
-  widthEL   = pcUsPic->getWidth ();
-  heightEL  = pcUsPic->getHeight();
-
-  widthBL   = pcBasePic->getWidth ();
-  heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-#endif
-#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();
-#endif
-
-  //========== horizontal upsampling ===========
-  for( i = 0; i < widthEL; i++ )
-  {
-#if SCALED_REF_LAYER_OFFSETS
-    Int x = Clip3( leftStartL, rightEndL - 1, i );
-#endif
-#if PHASE_DERIVATION_IN_INTEGER
-#if SCALED_REF_LAYER_OFFSETS
-    refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-    refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
-    phase    = refPos16 & 15;
-    refPos   = refPos16 >> 4;
-    coeff = m_lumaFilter[phase];
-#else
-    Int refPos12 = (Int) ( i * sFactor12 );
-    Int refPos = (Int)( i * sFactor );
-    Int phase = (refPos12 + 12) % 12; 
-    Int* coeff = m_lumaFilter[phase];
-#endif
-
-    piSrcY = piSrcBufY + refPos -((NTAPS_US_LUMA>>1) - 1);
-    piDstY = piTempBufY + i;
-
-    for( j = 0; j < heightBL ; j++ )
-    {
-      *piDstY = sumLumaHor(piSrcY, coeff);
-      piSrcY += strideBL;
-      piDstY += strideEL;
-    }
-  }
-
-
-  //========== vertical upsampling ===========
-  pcTempPic->setBorderExtension(false);
-  pcTempPic->setHeight(heightBL);
-  pcTempPic->extendPicBorder   (); // extend the border.
-  pcTempPic->setHeight(heightEL);
-
-  const Int nShift = US_FILTER_PREC*2;
-  Int iOffset = 1 << (nShift - 1); 
-
-#if SCALED_REF_LAYER_OFFSETS
-  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);
-#endif
-#if PHASE_DERIVATION_IN_INTEGER
-#if SCALED_REF_LAYER_OFFSETS
-    refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-    refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
-    phase    = refPos16 & 15;
-    refPos   = refPos16 >> 4;
-    coeff = m_lumaFilter[phase];
-#else
-    Int refPos12 = (Int) (j * sFactor12 );
-    Int refPos = (Int)( j * sFactor );
-    Int phase = (refPos12 + 12) % 12;
-    Int* coeff = m_lumaFilter[phase];
-#endif
-
-    piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
-    piDstY = piDstBufY + j * strideEL;
-#if SCALED_REF_LAYER_OFFSETS
-    for( i = 0; i < pcTempPic->getWidth(); i++ )
-#else
-    for( i = 0; i < widthEL; i++ )
-#endif
-    {
-      *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
-#if SCALED_REF_LAYER_OFFSETS
-      // 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++;
-      }
-#else
-      piSrcY++;
-#endif
-      piDstY++;
-    }
-  }
-
-#if ILP_DECODED_PICTURE
-#if SCALED_REF_LAYER_OFFSETS
-  widthBL   = pcBasePic->getWidth ();
-  heightBL  = pcBasePic->getHeight();
-
-  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
-#endif
-
-  //========== UV component upsampling ===========
-
-  widthEL  >>= 1;
-  heightEL >>= 1;
-
-  widthBL  >>= 1;
-  heightBL >>= 1;
-
-  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);
-#endif
-
-#if PHASE_DERIVATION_IN_INTEGER
-  shiftX = 16;
-  shiftY = 16;
-
-  phaseX = 0;
-  phaseY = 1;
-
-  addX       = ( ( ( widthBL * phaseX ) << ( shiftX - 2 ) ) + ( widthEL >> 1 ) ) / widthEL + ( 1 << ( shiftX - 5 ) );
-  addY       = ( ( ( heightBL * phaseY ) << ( shiftY - 2 ) ) + ( heightEL >> 1 ) ) / heightEL+ ( 1 << ( shiftY - 5 ) );
-
-  deltaX     = 4 * phaseX;
-  deltaY     = 4 * phaseY;
-
-  shiftXM4 = shiftX - 4;
-  shiftYM4 = shiftY - 4;
-
-  scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
-  scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
-#endif
-
-#if ILP_DECODED_PICTURE
-  widthEL   = pcUsPic->getWidth () >> 1;
-  heightEL  = pcUsPic->getHeight() >> 1;
-
-  widthBL   = pcBasePic->getWidth () >> 1;
-  heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-#endif
-
-  //========== horizontal upsampling ===========
-  for( i = 0; i < widthEL; i++ )
-  {
-#if SCALED_REF_LAYER_OFFSETS
-    Int x = Clip3(leftStartC, rightEndC - 1, i);
-#endif
-#if PHASE_DERIVATION_IN_INTEGER
-#if SCALED_REF_LAYER_OFFSETS
-    refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
-#else
-    refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
-#endif
-    phase    = refPos16 & 15;
-    refPos   = refPos16 >> 4;
-    coeff = m_chromaFilter[phase];
-#else
-    Int refPosM = (Int) ( i * chromaPhaseDenominator * sFactor );
-    Int refPos = (Int)( i * sFactor );
-    Int phase = (refPosM + chromaPhaseDenominator) % chromaPhaseDenominator;
-    Int* coeff = m_chromaFilter[phase];
-#endif
-
-    piSrcU = piSrcBufU + refPos -((NTAPS_US_CHROMA>>1) - 1);
-    piSrcV = piSrcBufV + refPos -((NTAPS_US_CHROMA>>1) - 1);
-    piDstU = piTempBufU + i;
-    piDstV = piTempBufV + i;
-
-    for( j = 0; j < heightBL ; j++ )
-    {
-      *piDstU = sumChromaHor(piSrcU, coeff);
-      *piDstV = sumChromaHor(piSrcV, coeff);
-
-      piSrcU += strideBL;
-      piSrcV += strideBL;
-      piDstU += strideEL;
-      piDstV += strideEL;
-    }
-  }
-
-  //========== vertical upsampling ===========
-  pcTempPic->setBorderExtension(false);
-  pcTempPic->setHeight(heightBL << 1);
-  pcTempPic->extendPicBorder   (); // extend the border.
-  pcTempPic->setHeight(heightEL << 1);
-
-#if SCALED_REF_LAYER_OFFSETS
-  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);
-#endif
-#if PHASE_DERIVATION_IN_INTEGER
-#if SCALED_REF_LAYER_OFFSETS
-    refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
-#else
-    refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
-#endif
-    phase    = refPos16 & 15;
-    refPos   = refPos16 >> 4; 
-    coeff = m_chromaFilter[phase];
-#else
-    Int refPosM = (Int) (j * chromaPhaseDenominator * sFactor) - 1;
-    Int refPos; 
-    if ( refPosM < 0 )
-    {
-      refPos = (Int)( j * sFactor ) - 1;
-    }
-    else
-    {
-      refPos = refPosM / chromaPhaseDenominator;
-    }
-    Int phase = (refPosM + chromaPhaseDenominator) % chromaPhaseDenominator;
-    Int* coeff = m_chromaFilter[phase];
-#endif
-
-    piSrcU = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
-    piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
-
-    piDstU = piDstBufU + j*strideEL;
-    piDstV = piDstBufV + j*strideEL;
-
-#if SCALED_REF_LAYER_OFFSETS
-    for( i = 0; i < pcTempPic->getWidth() >> 1; i++ )
-#else
-    for( i = 0; i < widthEL; i++ )
-#endif
-    {
-      *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
-      *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
-
-#if SCALED_REF_LAYER_OFFSETS
-      // 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 = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
+      piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
+#if SCALED_REF_LAYER_OFFSETS
+#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++;
-      }
-#else
-      piSrcU++;
-      piSrcV++;
-#endif
-      piDstU++;
-      piDstV++;
-    }
-  }
-
-  pcUsPic->setBorderExtension(false);
-  pcUsPic->extendPicBorder   (); // extend the border.
-
-  //Reset the Border extension flag
-  pcUsPic->setBorderExtension(false);
-  pcTempPic->setBorderExtension(false);
-  pcBasePic->setBorderExtension(false);
-  
-#if JCTVC_L0178
-  // copy back the saved cropped region
-  if( tempBufSizeRight )
-  {
-    // put the correct width back
-    pcBasePic->setWidth(pcBasePic->getWidth() + confBL.getWindowRightOffset());
-  }
-  if( tempBufSizeBottom )
-  {
-    pcBasePic->setHeight(pcBasePic->getHeight() + confBL.getWindowBottomOffset());
-  }
-  
-  widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-  
-  strideBL  = pcBasePic->getStride();
-  
-  if( tempBufSizeRight )
-  {
-    piSrcY = tempBufRight;
-    piDstY = piSrcBufY + widthBL;
-    
-    for( i = 0; i < pcBasePic->getHeight(); i++ )
-    {
-      memcpy(piDstY, piSrcY, sizeof(Pel) * confBL.getWindowRightOffset() );
-      piSrcY += confBL.getWindowRightOffset();
-      piDstY += strideBL;
-    }
-    
-    if(confBL.getWindowRightOffset()>>1)
-    {
-      Int strideBLChroma = (strideBL>>1);
-      piSrcU = tempBufRight + confBL.getWindowRightOffset() * pcBasePic->getHeight();
-      piDstU = piSrcBufU + (widthBL>>1);
-      piSrcV = piSrcU + (confBL.getWindowRightOffset()>>1) * (pcBasePic->getHeight()>>1);
-      piDstV = piSrcBufV + (widthBL>>1);
-
-      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
-      {
-        memcpy(piDstU, piSrcU, sizeof(Pel) * (confBL.getWindowRightOffset()>>1));
-        piSrcU += (confBL.getWindowRightOffset()>>1);
-        piDstU += strideBLChroma;
-        
-        memcpy(piDstV, piSrcV, sizeof(Pel) * (confBL.getWindowRightOffset()>>1));
-        piSrcV += (confBL.getWindowRightOffset()>>1);
-        piDstV += strideBLChroma;
-      }
-    }
-  }
-  
-  if( tempBufSizeBottom )
-  {
-    piDstY = piSrcBufY + heightBL * strideBL;
-    piSrcY = tempBufBottom;
-    for( i = 0; i < confBL.getWindowBottomOffset(); i++ )
-    {
-      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
-      piDstY += strideBL;
-      piSrcY += pcBasePic->getWidth();
-    }
-    
-    if(confBL.getWindowBottomOffset()>>1)
-    {
-      Int strideBLChroma = (strideBL>>1);
-      piSrcU = tempBufBottom + confBL.getWindowBottomOffset() * pcBasePic->getWidth();
-      piDstU = piSrcBufU + (heightBL>>1) * strideBLChroma;
-      piSrcV = piSrcU + (confBL.getWindowBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
-      piDstV = piSrcBufV + (heightBL>>1) * strideBLChroma;
-            
-      for( i = 0; i < confBL.getWindowBottomOffset()>>1; i++ )
-      {
-        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
-        piSrcU += (pcBasePic->getWidth()>>1);
-        piDstU += strideBLChroma;
-        
-        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
-        piSrcV += (pcBasePic->getWidth()>>1);
-        piDstV += strideBLChroma;
-      }
-    }
-  
-  }
-
-  if( tempBufSizeRight )
-  {
-    xFree( tempBufRight );
-  }
-  if( tempBufSizeBottom )
-  {
-    xFree( tempBufBottom );
-  }
-#endif
+        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
+#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
+    }
+
+    pcUsPic->setBorderExtension(false);
+    pcUsPic->extendPicBorder   (); // extend the border.
+
+    //Reset the Border extension flag
+    pcUsPic->setBorderExtension(false);
+    pcTempPic->setBorderExtension(false);
+    pcBasePic->setBorderExtension(false);
   }
 }
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 310)
@@ -13,5 +13,4 @@
 {
 private:
-#if PHASE_DERIVATION_IN_INTEGER
   static const Int m_lumaFixedFilter[16][NTAPS_US_LUMA];     ///< Luma filter taps for both 1.5x and 2x scalability
   static const Int m_chromaFixedFilter[16][NTAPS_US_CHROMA]; ///< Chroma filter taps for 1.5x scalability
@@ -19,12 +18,4 @@
   Int m_lumaFilter[16][NTAPS_US_LUMA];
   Int m_chromaFilter[16][NTAPS_US_CHROMA];
-#else
-  static const Int m_lumaFixedFilter[12][NTAPS_US_LUMA];     ///< Luma filter taps for both 1.5x and 2x scalability
-  static const Int m_chromaFixedFilter20[8][NTAPS_US_CHROMA]; ///< Chroma filter taps for 2x scalability
-  static const Int m_chromaFixedFilter15[12][NTAPS_US_CHROMA]; ///< Chroma filter taps for 1.5x scalability
-
-  Int m_lumaFilter[12][NTAPS_US_LUMA];
-  Int m_chromaFilter[12][NTAPS_US_CHROMA];
-#endif
 
   static inline Int sumLumaHor( Pel* pel, Int* coeff )
@@ -53,7 +44,7 @@
 
 #if SCALED_REF_LAYER_OFFSETS
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
 #else
- Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+ Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 };
Index: trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp	(revision 230)
+++ trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp	(revision 310)
@@ -271,4 +271,6 @@
 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1)
 {
+  assert(iRefIdx0 >= 0 || iRefIdx1 >= 0);
+  
   TComSlice*      pcSlice       = pcCU->getSlice();
   TComPPS*        pps           = pcCU->getSlice()->getPPS();
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 230)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 310)
@@ -44,6 +44,11 @@
 
 #if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 1      ///< VUI flag to indicate tile boundary alignment
+#define M0463_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
+#define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
+#define SCALED_REF_LAYER_OFFSET_FLAG     0      ///< M0309: Signal scaled reference layer offsets in SPS
 #define SCALED_REF_LAYER_OFFSETS         1      ///< M0309: Signal scaled reference layer offsets in SPS
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
 
 #define VPS_RENAME                       1      ///< Rename variables max_layer_id and num_layer_sets_minus1 in VPS
@@ -54,9 +59,14 @@
 #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_EXTN_DIRECT_REF_LAYERS_CONTINUE   1
 #define VPS_OUTPUT_LAYER_SET_IDX         1      ///< M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
 #define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
 #define VPS_PROFILE_OUTPUT_LAYERS        1      ///< M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
-#endif
+#define SPS_SUB_LAYER_INFO               1      ///< 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      ///< 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
+#endif
+
+#define SH_DISCARDABLE_FLAG              1      ///< 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
@@ -64,6 +74,4 @@
 #define SVC_COL_BLK                      1      ///< get co-located block
 #define SVC_UPSAMPLING                   1      ///< upsampling filters
-#define PHASE_DERIVATION_IN_INTEGER      1      ///< upsampling filters implementation using only integer arithmetic
-#define ENCODER_BUGFIX                   1      ///< L0167: encoder bug fix for inter mode
 #define CHROMA_UPSAMPLING                1      ///< L0335: Chroma upsampling with 5 bits coefficients
 
@@ -71,10 +79,8 @@
 #define ILP_DECODED_PICTURE              1      ///< M0274: use decoded picture for inter-layer prediction
 #define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
+#define RESTR_CHK                        1      ///< JCTVC-M0208 proposal 1
+#define ILP_RAP                          1      ///< JCTVC-M0208 proposal 3
 
 #define REF_IDX_FRAMEWORK                1      ///< inter-layer reference framework
-
-#if SVC_UPSAMPLING && !ILP_DECODED_PICTURE
-#define JCTVC_L0178                      1      ///< implementation of JCTVC-L0178 (code only supports right and bottom croppping offsets)
-#endif
 
 #define IDR_ALIGNMENT                    1      ///< align IDR picures across layers 
@@ -89,8 +95,21 @@
 #define ENCODER_FAST_MODE                1      ///< L0174: enable encoder fast mode. TestMethod 1 is enabled by setting to 1 and TestMethod 2 is enable by setting to 2. By default it is set to 1.
 #define REF_IDX_MFM                      1      ///< L0336: motion vector mapping of inter-layer reference picture
-#define JCTVC_M0458_INTERLAYER_RPS_SIG   1      ///< implementation of JCTVC-L0178 (currently only one reference layer is supported )
+#define JCTVC_M0458_INTERLAYER_RPS_SIG   1      ///< implementation of JCTVC-L0178
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
 #define ZERO_NUM_DIRECT_LAYERS           1      ///< support of zero direct reference layers
-#endif
+#define MAX_ONE_RESAMPLING_DIRECT_LAYERS 1      ///< Allow maximum of one resampling process for direct reference layers
+#endif
+#define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< implementation of JCTVC-M0203 Inter-layer Prediction Indication
+#if JCTVC_M0203_INTERLAYER_PRED_IDC
+#define ILR_RESTR                        1     ///< JCTVC-M0209 Inter-layer RPS and RPL
+#endif
+#define M0457_COL_PICTURE_SIGNALING      1
+
+#if !VPS_EXTN_DIRECT_REF_LAYERS || !M0457_PREDICTION_INDICATIONS || !JCTVC_M0458_INTERLAYER_RPS_SIG
+#define M0457_IL_SAMPLE_PRED_ONLY_FLAG   0
+#else
+#define M0457_IL_SAMPLE_PRED_ONLY_FLAG   0
+#endif
+
 #else
 #define INTRA_BL                         1      ///< inter-layer texture prediction
@@ -110,50 +129,28 @@
 #endif
 #endif
+
+#define FAST_INTRA_SHVC                  1      ///< M0115: reduction number of intra modes in the EL (encoder only)
+#if FAST_INTRA_SHVC
+  #define NB_REMAIN_MODES                2      ///< nb of remaining modes (M0115)
+#endif
+
+#define RC_SHVC_HARMONIZATION            1  ///< JCTVC-M0037, rate control for SHVC
+
 #else
 #define ILP_DECODED_PICTURE              0
 #define SYNTAX_OUTPUT                    0
-#endif
+#endif // SVC_EXTENSION
+
 
 //! \ingroup TLibCommon
 //! \{
 
-#define FIX1071 1 ///< Temporary fix for issue #1071
-
-#define L0208_SOP_DESCRIPTION_SEI     1 ///< L0208: add SOP descrioption SEI
+#define FIX1071 1 ///< fix for issue #1071
+#define M0043_LAYERS_PRESENT_SEI         0 ///< M0043: add layers present SEI
+
 #define MAX_NUM_PICS_IN_SOP           1024
 
-#define K0180_SCALABLE_NESTING_SEI  1   ///JCTVC-K0180 scalable nesting sei message
 #define MAX_NESTING_NUM_OPS         1024
 #define MAX_NESTING_NUM_LAYER       64
-
-#define J0149_TONE_MAPPING_SEI        1 ///< J0149: Tone mapping information SEI
-#define L0363_DU_BIT_RATE             1 ///< L0363: add bit_rate_du_value_minus1 to HRD parameters
-#define L0328_SPLICING                1 ///< L0328: splicing support in HRD
-#define L0044_DU_DPB_OUTPUT_DELAY_HRD 1 ///< L0044: Include dpb_output_delay_du_length_minus1 in hrd_parameters(), dpb_output_du_delay in
-                                        ///<        picture timing SEI and DU information SEI
-#define L0045_PERSISTENCE_FLAGS  1      ///< L0045: Replace "repetition_period" syntax elements in SEI with "persistence_flag"
-#define L0045_NON_NESTED_SEI_RESTRICTIONS 1 ///< L0045; Include restriction on the order of APS and non-nested BP, PT and DU info SEI messages
-#define L0044_CPB_DPB_DELAY_OFFSET 1  ///< L0044: Include syntax elements cpb_delay_offset and dpb_delay_offset in the BP SEI message
-#define L0047_APS_FLAGS            1  ///< L0047: Include full_random_access_flag and no_param_set_update_flag in the active parameter set SEI message
-#define L0043_TIMING_INFO          1  ///< L0043: Timing information is signalled in VUI outside hrd_parameters()
-#define L0046_RENAME_PROG_SRC_IDC  1  ///< L0046: Rename progressive_source_idc to source_scan_type
-#define L0045_CONDITION_SIGNALLING 1  ///< L0045: Condition the signaling of some syntax elements in picture timing SEI message
-#define L0043_MSS_IDC 1
-#define L0116_ENTRY_POINT 1
-#define L0363_MORE_BITS 1
-#define L0363_MVP_POC 1
-#define L0363_BYTE_ALIGN 1
-#define L0363_SEI_ALLOW_SUFFIX 1
-#define L0323_LIMIT_DEFAULT_LIST_SIZE 1
-#define L0046_CONSTRAINT_FLAGS 1
-#define L0255_MOVE_PPS_FLAGS       1  ///< move some flags to earlier positions in the PPS
-#define L0444_FPA_TYPE             1  ///< allow only FPA types 3, 4 and 5
-#define L0372 1
-#define SIGNAL_BITRATE_PICRATE_IN_VPS               0  ///< K0125: Signal bit_rate and pic_rate in VPS
-#define L0232_RD_PENALTY           1  ///< L0232: RD-penalty for 32x32 TU for intra in non-intra slices
-#define L0386_DB_METRIC            1  ///< L0386: non-normative blockiness metric (automatically configures deblocking parameters in bitstream)
-#define L0323_DPB                     1 ///< L0323: Specification of active reference indices and decoded picture buffer
-
-#define L0034_COMBINED_LIST_CLEANUP 1
 
 #if VPS_EXTN_MASK_AND_DIM_INFO
@@ -169,5 +166,9 @@
 #endif
 #define RATE_CONTROL_LAMBDA_DOMAIN                  1  ///< JCTVC-K0103, rate control by R-lambda model
-#define L0033_RC_BUGFIX                             1  ///< JCTVC-L0033, bug fix for R-lambda model based rate control
+#define M0036_RC_IMPROVEMENT                        1  ///< JCTVC-M0036, improvement for R-lambda model based rate control
+#define TICKET_1090_FIX                             1
+
+#define RC_FIX                                      1  /// suggested fix for M0036
+#define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra 
 
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
@@ -190,6 +191,4 @@
 
 #define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1  ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode
-
-#define REMOVE_SINGLE_SEI_EXTENSION_FLAGS 1 ///< remove display orientation SEI extension flag (there is a generic SEI extension mechanism now) 
 
 #define SAO_ENCODING_CHOICE              1  ///< I0184: picture early termination
@@ -205,6 +204,4 @@
 #define MAX_NUM_SPS                16
 #define MAX_NUM_PPS                64
-
-
 
 #define WEIGHTED_CHROMA_DISTORTION  1   ///< F386: weighting of chroma for RDO
@@ -495,7 +492,4 @@
   REF_PIC_LIST_0 = 0,   ///< reference list 0
   REF_PIC_LIST_1 = 1,   ///< reference list 1
-#if !L0034_COMBINED_LIST_CLEANUP
-  REF_PIC_LIST_C = 2,   ///< combined reference list for uni-prediction in B-Slices
-#endif
   REF_PIC_LIST_X = 100  ///< special mark
 };
