Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/CommonDef.h	(revision 54)
@@ -56,5 +56,5 @@
 // ====================================================================================================================
 
-#define NV_VERSION        "10.0"                 ///< Current software version
+#define NV_VERSION        "1.2"                 ///< Current software version
 
 // ====================================================================================================================
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/ContextTables.h	(revision 54)
@@ -92,4 +92,7 @@
 #define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
 #define NUM_SAO_TYPE_IDX_CTX          1       ///< number of context models for SAO type index
+#if INTRA_BL
+#define NUM_INTRA_BL_PRED_CTX         3
+#endif
 
 #define NUM_TRANSFORMSKIP_FLAG_CTX    1       ///< number of context models for transform skipping 
@@ -327,4 +330,13 @@
 };
 
+#if INTRA_BL
+static const UChar 
+INIT_INTRA_BL_PRED_FLAG[3][NUM_INTRA_BL_PRED_CTX] = 
+{
+  { 185,  185,  201, }, 
+  { 197,  197,  185, }, 
+  { 197,  197,  185, }, 
+};
+#endif
 static const UChar
 INIT_TRANSFORMSKIP_FLAG[3][2*NUM_TRANSFORMSKIP_FLAG_CTX] = 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/NAL.h	(revision 54)
@@ -47,4 +47,7 @@
   NalUnitType m_nalUnitType; ///< nal_unit_type
   UInt        m_temporalId;  ///< temporal_id
+#if SVC_EXTENSION
+  UInt        m_layerId;   ///< layer id
+#endif
   UInt        m_reservedZero6Bits; ///< reserved_zero_6bits
 
@@ -53,7 +56,13 @@
     NalUnitType nalUnitType,
     Int         temporalId = 0,
+#if SVC_EXTENSION
+    UInt        layerId = 0,
+#endif
     Int         reservedZero6Bits = 0)
     :m_nalUnitType (nalUnitType)
     ,m_temporalId  (temporalId)
+#if SVC_EXTENSION
+    ,m_layerId   (layerId)
+#endif
     ,m_reservedZero6Bits(reservedZero6Bits)
   {}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.cpp	(revision 54)
@@ -359,4 +359,8 @@
   m_uiTotalBins        = 0;
   m_uiNumPartition     = pcPic->getNumPartInCU();
+
+#if SVC_EXTENSION
+  m_layerId           = pcPic->getLayerId();
+#endif 
   
   for(Int i=0; i<pcPic->getNumPartInCU(); i++)
@@ -1647,10 +1651,48 @@
   pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
   
+#if INTRA_BL
+  iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#else
   iLeftIntraDir  = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#endif
   
   // Get intra direction of above PU
   pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, true );
   
+#if INTRA_BL
+  iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) && ( !pcTempCU->isIntraBL( uiTempPartIdx ) ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#else
   iAboveIntraDir = pcTempCU ? ( pcTempCU->isIntra( uiTempPartIdx ) ? pcTempCU->getLumaIntraDir( uiTempPartIdx ) : DC_IDX ) : DC_IDX;
+#endif 
+  
+#if SVC_BL_CAND_INTRA
+  if(m_layerId > 0)
+  {
+    UInt uiCUAddrBase, uiAbsPartAddrBase;
+    pcTempCU = getBaseColCU( uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
+
+    if(pcTempCU->getPredictionMode( uiAbsPartAddrBase ) == MODE_INTRA )
+    {
+      Int iColBaseDir = pcTempCU->getLumaIntraDir( uiAbsPartAddrBase );
+      if( iColBaseDir != iAboveIntraDir && iColBaseDir != iLeftIntraDir && iAboveIntraDir != iLeftIntraDir)
+      {
+        uiIntraDirPred[0] = iColBaseDir;
+        uiIntraDirPred[1] = iLeftIntraDir;
+        uiIntraDirPred[2] = iAboveIntraDir;
+        if( piMode )
+        {
+          *piMode = 2;
+        }
+        uiPredNum = 3;
+        return uiPredNum;
+      }
+      else 
+      {
+        iAboveIntraDir = (iColBaseDir == iLeftIntraDir) ? iAboveIntraDir : iLeftIntraDir;
+        iLeftIntraDir  = iColBaseDir;
+      }
+    }
+  }
+#endif
   
   uiPredNum = 3;
@@ -1730,5 +1772,9 @@
   UInt log2CbSize = g_aucConvertToBit[getWidth( absPartIdx )] + 2;
   PartSize  partSize  = getPartitionSize( absPartIdx );
+#if INTRA_BL
+  UInt quadtreeTUMaxDepth = isIntra( absPartIdx ) ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
+#else
   UInt quadtreeTUMaxDepth = getPredictionMode( absPartIdx ) == MODE_INTRA ? m_pcSlice->getSPS()->getQuadtreeTUMaxDepthIntra() : m_pcSlice->getSPS()->getQuadtreeTUMaxDepthInter(); 
+#endif
   Int intraSplitFlag = ( getPredictionMode( absPartIdx ) == MODE_INTRA && partSize == SIZE_NxN ) ? 1 : 0;
   Int interSplitFlag = ((quadtreeTUMaxDepth == 1) && (getPredictionMode( absPartIdx ) == MODE_INTER) && (partSize != SIZE_2Nx2N) );
@@ -1752,4 +1798,71 @@
   return log2MinTUSizeInCU;
 }
+
+#if INTRA_BL
+UInt TComDataCU::getCtxIntraBLFlag( UInt uiAbsPartIdx )
+{
+  TComDataCU* pcTempCU;
+  UInt        uiTempPartIdx;
+  UInt        uiCtx = 0;
+  
+  // Get BCBP of left PU
+#if DEPENDENT_SLICES
+  Bool bDepSliceRestriction = ( !m_pcSlice->getPPS()->getDependentSliceEnabledFlag());
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
+#else
+  pcTempCU = getPULeft( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+#endif  
+  uiCtx    = ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
+  
+  // Get BCBP of above PU
+#if DEPENDENT_SLICES
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx, true, bDepSliceRestriction );
+#else
+  pcTempCU = getPUAbove( uiTempPartIdx, m_uiAbsIdxInLCU + uiAbsPartIdx );
+#endif  
+  uiCtx   += ( pcTempCU ) ? pcTempCU->isIntraBL( uiTempPartIdx ) : 0;
+  
+  return uiCtx;
+}
+#endif
+
+#if REF_IDX_ME_ZEROMV
+Bool TComDataCU::xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1)
+{
+  Bool checkZeroMVILR = true;
+
+  if(uhInterDir&0x1)  //list0
+  {
+    Int refIdxL0 = cMvFieldL0.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_0, refIdxL0)->getIsILR())
+      checkZeroMVILR &= (cMvFieldL0.getHor() == 0 && cMvFieldL0.getVer() == 0);
+  }
+  if(uhInterDir&0x2)  //list1
+  {
+    Int refIdxL1  = cMvFieldL1.getRefIdx();
+    if(getSlice()->getRefPic(REF_PIC_LIST_1, refIdxL1)->getIsILR())
+      checkZeroMVILR &= (cMvFieldL1.getHor() == 0 && cMvFieldL1.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+
+Bool TComDataCU::xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx)
+{
+  RefPicList eRefPicList = iRefList > 0? REF_PIC_LIST_1: REF_PIC_LIST_0;
+  assert(eRefPicList == REF_PIC_LIST_1);
+
+  Bool checkZeroMVILR = true;
+
+  if(getSlice()->getRefPic(eRefPicList, iRefIdx)->getIsILR())
+  {
+    AMVPInfo* pcAMVPInfo = getCUMvField(eRefPicList)->getAMVPInfo();
+    TComMv    cMv        = pcAMVPInfo->m_acMvCand[MvpIdx];
+    checkZeroMVILR &= (cMv.getHor() == 0 && cMv.getVer() == 0);
+  }
+
+  return checkZeroMVILR;
+}
+#endif
 
 UInt TComDataCU::getCtxSkipFlag( UInt uiAbsPartIdx )
@@ -2406,4 +2519,60 @@
   deriveLeftRightTopIdxGeneral( uiAbsPartIdx, uiPUIdx, uiPartIdxLT, uiPartIdxRT );
   deriveLeftBottomIdxGeneral  ( uiAbsPartIdx, uiPUIdx, uiPartIdxLB );
+#if SVC_MVP
+  // BL collocated
+  TComDataCU *pcColCU = 0;
+  UInt uiCUAddrBase, uiAbsPartAddrBase ;
+  TComMvField cMvFieldBaseColCU[2];
+  if(m_layerId)  
+  {
+#if MV_SCALING_POS_FIX
+    pcColCU = getBaseColCU( xP + nPSW/2, yP + nPSH/2, uiCUAddrBase, uiAbsPartAddrBase );
+#else
+    UInt uiPartIdxCenter;
+    xDeriveCenterIdx( cCurPS, uiPUIdx, uiPartIdxCenter );
+    uiPartIdxCenter -= m_uiAbsIdxInLCU;
+    pcColCU = getBaseColCU( uiPartIdxCenter, uiCUAddrBase, uiAbsPartAddrBase );
+#endif
+    
+#if INTRA_BL
+    if( pcColCU && pcColCU->isIntraBL( uiAbsPartAddrBase ) )
+    {
+      pcColCU = NULL;
+    }
+#endif
+    
+    if(pcColCU && !pcColCU->isIntra( uiAbsPartAddrBase ) )
+    {
+      abCandIsInter[iCount] = true;
+
+      // get interDir
+      puhInterDirNeighbours[iCount] = pcColCU->getInterDir( uiAbsPartAddrBase );
+
+      pcMvFieldNeighbours[(iCount << 1)].setMvField( TComMv(0,0), -1);
+      pcMvFieldNeighbours[(iCount << 1) + 1].setMvField( TComMv(0,0), -1);
+
+      if( puhInterDirNeighbours[iCount] & 1 )
+      {
+        pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_0, cMvFieldBaseColCU[0]);
+        scaleBaseMV( pcMvFieldNeighbours[iCount<<1], cMvFieldBaseColCU[0] );
+      }
+
+      if ( getSlice()->isInterB() && puhInterDirNeighbours[iCount] & 2 )
+      {
+        pcColCU->getMvField( pcColCU, uiAbsPartAddrBase, REF_PIC_LIST_1, cMvFieldBaseColCU[1] );
+        scaleBaseMV( pcMvFieldNeighbours[(iCount<<1)+1], cMvFieldBaseColCU[1] );
+      }
+
+      if( puhInterDirNeighbours[iCount] > 0 )
+      {
+        if ( mrgCandIdx == iCount )
+        {
+          return;
+        }
+        iCount ++;
+      }
+    }
+  }
+#endif
 
   //left
@@ -2411,6 +2580,15 @@
   TComDataCU* pcCULeft = 0;
   pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
+#if INTRA_BL
+  if( pcCULeft && pcCULeft->isIntraBL( uiLeftPartIdx ) )
+  {
+    pcCULeft = NULL;
+  }
+#endif
   Bool isAvailableA1 = pcCULeft &&
   pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeft->hasEqualMotion( uiLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0])) &&
+#endif
   !( uiPUIdx == 1 && (cCurPS == SIZE_Nx2N || cCurPS == SIZE_nLx2N || cCurPS == SIZE_nRx2N) ) &&
   !pcCULeft->isIntra( uiLeftPartIdx ) ;
@@ -2442,5 +2620,14 @@
   TComDataCU* pcCUAbove = 0;
   pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
+#if INTRA_BL
+  if( pcCUAbove && pcCUAbove->isIntraBL( uiAbovePartIdx ) )
+  {
+    pcCUAbove = NULL;
+  }
+#endif
   Bool isAvailableB1 = pcCUAbove &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAbove->hasEqualMotion( uiAbovePartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
+#endif
   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
   !( uiPUIdx == 1 && (cCurPS == SIZE_2NxN || cCurPS == SIZE_2NxnU || cCurPS == SIZE_2NxnD) ) &&
@@ -2473,5 +2660,14 @@
   TComDataCU* pcCUAboveRight = 0;
   pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
+#if INTRA_BL
+  if( pcCUAboveRight && pcCUAboveRight->isIntraBL( uiAboveRightPartIdx ) )
+  {
+    pcCUAboveRight = NULL;
+  }
+#endif
   Bool isAvailableB0 = pcCUAboveRight &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveRight->hasEqualMotion( uiAboveRightPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] )) &&
+#endif
   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
   !pcCUAboveRight->isIntra( uiAboveRightPartIdx );
@@ -2500,9 +2696,22 @@
 
   //left bottom
+#if SVC_MVP
+  if( iCount < 4 )
+  {
+#endif
   UInt uiLeftBottomPartIdx = 0;
   TComDataCU* pcCULeftBottom = 0;
   pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
+#if INTRA_BL
+  if( pcCULeftBottom && pcCULeftBottom->isIntraBL( uiLeftBottomPartIdx ) )
+  {
+    pcCULeftBottom = NULL;
+  }
+#endif
   Bool isAvailableA0 = pcCULeftBottom &&
   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
+#if SVC_MVP
+  ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCULeftBottom->hasEqualMotion( uiLeftBottomPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0]))
+#endif
   !pcCULeftBottom->isIntra( uiLeftBottomPartIdx ) ;
   if ( isAvailableA0 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCULeftBottom, uiLeftBottomPartIdx ) ) )
@@ -2528,4 +2737,8 @@
     return;
   }
+#if SVC_MVP
+  }
+#endif
+
   // above left 
   if( iCount < 4 )
@@ -2534,6 +2747,15 @@
     TComDataCU* pcCUAboveLeft = 0;
     pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
+#if INTRA_BL
+    if( pcCUAboveLeft && pcCUAboveLeft->isIntraBL( uiAboveLeftPartIdx ) )
+    {
+      pcCUAboveLeft = NULL;
+    }
+#endif
     Bool isAvailableB2 = pcCUAboveLeft &&
     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
+#if SVC_MVP
+    ( !pcColCU || pcColCU->isIntra( uiAbsPartAddrBase ) || !pcCUAboveLeft->hasEqualMotion( uiAboveLeftPartIdx, puhInterDirNeighbours[0], &pcMvFieldNeighbours[0] ))
+#endif
     !pcCUAboveLeft->isIntra( uiAboveLeftPartIdx );
     if ( isAvailableB2 && ( !isAvailableA1 || !pcCULeft->hasEqualMotion( uiLeftPartIdx, pcCUAboveLeft, uiAboveLeftPartIdx ) )
@@ -2840,10 +3062,18 @@
   UInt idx;
   tmpCU = getPUBelowLeft(idx, uiPartIdxLB);
+#if INTRA_BL
+  bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
+#else
   bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
+#endif
 
   if (!bAddedSmvp)
   {
     tmpCU = getPULeft(idx, uiPartIdxLB);
+#if INTRA_BL
+    bAddedSmvp = (tmpCU != NULL) && (!tmpCU->isIntra(idx));
+#else
     bAddedSmvp = (tmpCU != NULL) && (tmpCU->getPredictionMode(idx) != MODE_INTRA);
+#endif
   }
 
@@ -3406,6 +3636,11 @@
   if (scaleFactor > 0)
   {
+#if SVC_MVP
+    m_acCUMvField[0].compress(m_pePredMode, m_puhInterDir, scaleFactor);
+    m_acCUMvField[1].compress(m_pePredMode, m_puhInterDir, scaleFactor);    
+#else
     m_acCUMvField[0].compress(m_pePredMode, scaleFactor);
     m_acCUMvField[1].compress(m_pePredMode, scaleFactor);    
+#endif
   }
 }
@@ -3839,4 +4074,204 @@
 }
 
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED 
+Void TComDataCU::getBaseLumaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride )
+{
+  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
+  UInt uiStrideBase = pcBaseRec->getStride();
+  Pel* piBase = pcBaseRec->getLumaAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  
+  for ( UInt y = 0; y < uiHeight; y ++ )
+  {
+    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
+  }
+}
+
+Void TComDataCU::getBaseChromaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, UInt uiChromaId )
+{
+  TComPicYuv* pcBaseRec = getSlice()->getFullPelBaseRec();
+
+  UInt uiStrideBase = pcBaseRec->getCStride();
+  Pel* piBase;
+  
+  if( uiChromaId == 0 )
+  {
+    piBase = pcBaseRec->getCbAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  }
+  else
+  {
+    piBase = pcBaseRec->getCrAddr( getAddr(), getZorderIdxInCU() + uiAbsPartIdx );
+  }
+  
+  for ( UInt y = 0; y < uiHeight; y ++ )
+  {
+    memcpy( piPred + y * uiStride, piBase + y * uiStrideBase, uiWidth * sizeof( Pel ) );
+  }
+}
+
+#endif
+
+#if SVC_COL_BLK
+TComDataCU*  TComDataCU::getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+#if 1 // it should provide identical resutls
+  UInt uiPelX = getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
+  UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
+
+  return getBaseColCU( uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
+#else
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+
+#if SVC_UPSAMPLING
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth () - cBaseColPic->getPicYuvRec()->getPicCropLeftOffset() - cBaseColPic->getPicYuvRec()->getPicCropRightOffset();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight() - cBaseColPic->getPicYuvRec()->getPicCropTopOffset() - cBaseColPic->getPicYuvRec()->getPicCropBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - m_pcPic->getPicYuvRec()->getPicCropLeftOffset() - m_pcPic->getPicYuvRec()->getPicCropRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - m_pcPic->getPicYuvRec()->getPicCropTopOffset() - m_pcPic->getPicYuvRec()->getPicCropBottomOffset();
+#else
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  if (iBWidth == iEWidth && iEHeight == iBHeight)
+  {
+    uiAbsPartIdxBase = uiCuAbsPartIdx + m_uiAbsIdxInLCU;
+    uiCUAddrBase = m_uiCUAddr;
+  }
+  else
+  {
+    UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
+    UInt uiRasterAddr  = g_auiZscanToRaster[uiCuAbsPartIdx];
+    UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
+
+    Int iEX = m_uiCUPelX + uiMinUnitSize*(uiRasterAddr%uiNumPartInCUWidth);
+    Int iEY = m_uiCUPelY + uiMinUnitSize*(uiRasterAddr/uiNumPartInCUWidth);
+
+    Int iBX = (iEX*iBWidth + iEWidth/2)/iEWidth;
+    Int iBY = (iEY*iBHeight+ iEHeight/2)/iEHeight;
+
+    uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+
+    assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+    
+    UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+                          + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
+
+    uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+  }
+
+  return cBaseColPic->getCU(uiCUAddrBase);
+#endif
+}
+
+TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+
+#if SVC_UPSAMPLING
+  const Window &confBL = cBaseColPic->getPicYuvRec()->getConformanceWindow();
+  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
+
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#else
+  Int iBWidth   = cBaseColPic->getPicYuvRec()->getWidth();
+  Int iBHeight  = cBaseColPic->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  uiPelX = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getWidth() - 1, uiPelX);
+  uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
+
+  UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
+
+  Int iBX = (uiPelX*iBWidth + iEWidth/2)/iEWidth;
+  Int iBY = (uiPelY*iBHeight+ iEHeight/2)/iEHeight;
+
+  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+  {
+    return NULL;
+  }
+
+#if AVC_SYNTAX
+  if( iBX >= iBWidth || iBY >= iBHeight ) //outside of the reference layer cropped picture
+  {
+    return NULL;
+  }
+#endif
+
+  uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
+
+  assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
+
+  UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
+    + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
+
+  uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
+
+  return cBaseColPic->getCU(uiCUAddrBase);
+}
+
+Void TComDataCU::scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
+{
+  TComMvField cMvFieldBase;
+  TComMv cMv;
+
+#if MV_SCALING_FIX
+  const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
+  const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
+
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#else
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
+
+  Int iEWidth   = m_pcPic->getPicYuvRec()->getWidth();
+  Int iEHeight  = m_pcPic->getPicYuvRec()->getHeight();
+#endif
+
+  Int iMvX = (rcMvFieldBase.getHor()*iEWidth + (iBWidth/2 -1) * (rcMvFieldBase.getHor() > 0 ? 1: -1) )/iBWidth;
+  Int iMvY = (rcMvFieldBase.getVer()*iEHeight + (iBHeight/2 -1) * (rcMvFieldBase.getVer() > 0 ? 1: -1) )/iBHeight;
+
+  cMv.set(iMvX, iMvY);
+
+  rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
+}
+#endif
+
+#if SVC_MVP
+Bool TComDataCU::hasEqualMotion( UInt uiAbsPartIdx, UChar uchInterDir, TComMvField* pcMvField  )
+{
+  if ( getInterDir( uiAbsPartIdx ) != uchInterDir )
+  {
+    return false;
+  }
+
+  for ( UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
+  {
+    if ( getInterDir( uiAbsPartIdx ) & ( 1 << uiRefListIdx ) )
+    {
+      if ( getCUMvField( RefPicList( uiRefListIdx ) )->getMv( uiAbsPartIdx )  != pcMvField[uiRefListIdx].getMv() || 
+        getCUMvField( RefPicList( uiRefListIdx ) )->getRefIdx( uiAbsPartIdx ) != pcMvField[uiRefListIdx].getRefIdx() )
+      {
+        return false;
+      }
+    }
+  }
+
+  return true;
+}
+#endif
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComDataCU.h	(revision 54)
@@ -125,4 +125,8 @@
   Int           m_unitSize;           ///< size of a "minimum partition"
   
+#if SVC_EXTENSION
+  UInt          m_layerId;          ///< layer id
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // CU data
@@ -434,4 +438,9 @@
   Void          compressMV            ();
   
+#if SVC_EXTENSION
+  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt          getLayerId ()               { return m_layerId; }
+#endif
+  
   // -------------------------------------------------------------------------------------------------------------------
   // utility functions for neighbouring information
@@ -476,4 +485,7 @@
   Void          deriveLeftBottomIdxGeneral    ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
   
+#if SVC_MVP
+  Bool          hasEqualMotion              ( UInt uiAbsPartIdx, UChar uchInterDir, TComMvField* pcMvField  );
+#endif
   
   // -------------------------------------------------------------------------------------------------------------------
@@ -481,5 +493,14 @@
   // -------------------------------------------------------------------------------------------------------------------
   
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED 
+  Void          getBaseLumaBlk   ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride );
+  Void          getBaseChromaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride, UInt uiChromaId );
+#endif
+#if INTRA_BL
+  Bool          isIntraBL ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA_BL; }
+  Bool          isIntra   ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA || m_pePredMode[ uiPartIdx ] == MODE_INTRA_BL; }
+#else
   Bool          isIntra   ( UInt uiPartIdx )  { return m_pePredMode[ uiPartIdx ] == MODE_INTRA; }
+#endif 
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
@@ -507,4 +528,14 @@
   UInt          getSliceSegmentStartCU  ( UInt pos )                  { return m_sliceSegmentStartCU[pos-m_uiAbsIdxInLCU];                                                                                   }
   UInt&         getTotalBins            ()                            { return m_uiTotalBins;                                                                                                  }
+
+#if INTRA_BL
+  UInt          getCtxIntraBLFlag               ( UInt   uiAbsPartIdx                                 );
+#endif  
+
+#if REF_IDX_ME_ZEROMV
+  Bool xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+  Bool xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx);
+#endif
+
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for RD cost storage
@@ -518,4 +549,9 @@
   UInt          getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra);
 
+#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 );
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 54)
@@ -328,5 +328,9 @@
  * \param scale      Factor by which to subsample motion information
  */
+#if SVC_MVP
+Void TComCUMvField::compress(Char* pePredMode, UChar* peInterDir, Int scale)
+#else
 Void TComCUMvField::compress(Char* pePredMode, Int scale)
+#endif
 {
   Int N = scale * scale;
@@ -347,4 +351,7 @@
       pePredMode[ uiPartIdx + i ] = predMode;
       m_piRefIdx[ uiPartIdx + i ] = iRefIdx;
+#if SVC_MVP
+      peInterDir[ uiPartIdx + i ] = peInterDir[ uiPartIdx ];
+#endif
     }
   }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComMotionInfo.h	(revision 54)
@@ -141,4 +141,9 @@
   Void    setAllMvField( TComMvField const & mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0 );
 
+#if AVC_SYNTAX
+  Void           setMv    (TComMv cMv,  Int iIdx )         { m_pcMv    [iIdx] = cMv; }
+  Void           setRefIdx(Int iRefIdx, Int iIdx   )       { m_piRefIdx[iIdx] =  iRefIdx; }
+#endif
+
   Void setNumPartition( Int iNumPart )
   {
@@ -153,5 +158,25 @@
   }
   
+#if SVC_MVP
+  Void compress(Char* pePredMode, UChar* peInterDir, Int scale);
+#else
   Void compress(Char* pePredMode, Int scale); 
+#endif
+
+#if REF_IDX_MFM
+  Void setMvField( TComMvField const& mvField, Int iIdx )
+  {
+    m_pcMv[iIdx]      = mvField.getMv();
+    m_piRefIdx[iIdx]  = mvField.getRefIdx();
+    return;
+  }
+
+  Void setMvField( TComMv cMv, Int iRefIdx, Int iIdx )
+  {
+    m_pcMv[iIdx]      = cMv;
+    m_piRefIdx[iIdx]  = iRefIdx;
+    return;
+  }
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.cpp	(revision 54)
@@ -64,4 +64,12 @@
 , m_pNDBFilterYuvTmp                      (NULL)
 , m_bCheckLTMSB                           (false)
+#if SVC_EXTENSION
+, m_layerId( 0 )
+, m_bSpatialEnhLayer( false )
+, m_pcFullPelBaseRec( NULL )
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+, m_bIsILR                                (false)
+#endif
+#endif
 {
   m_apcPicYuv[0]      = NULL;
@@ -72,5 +80,65 @@
 {
 }
-
+#if SVC_UPSAMPLING
+Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
+                      Int *numReorderPics, TComSPS* pcSps, Bool bIsVirtual)
+
+{
+  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
+  if (!bIsVirtual)
+  {
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+  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 );
+  }
+
+  m_layerId = pcSps->getLayerId();  
+
+  // there are no SEI messages associated with this picture initially
+  if (m_SEIs.size() > 0)
+  {
+    deleteSEIs (m_SEIs);
+  }
+  m_bUsedByCurr = false;
+
+  /* store conformance window parameters with picture */
+  m_conformanceWindow = conformanceWindow;
+  
+  /* store display window parameters with picture */
+  m_defaultDisplayWindow = defaultDisplayWindow;
+
+  /* store number of reorder pics with picture */
+  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
+
+  return;
+}
+#if REF_IDX_FRAMEWORK
+Void TComPic::createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps,  Bool bIsVirtual)
+{
+  m_apcPicSym     = new TComPicSym;  m_apcPicSym   ->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth );
+  if (!bIsVirtual)
+  {
+    m_apcPicYuv[0]  = new TComPicYuv;  m_apcPicYuv[0]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+  m_apcPicYuv[1]  = NULL;
+ 
+#if SVC_UPSAMPLING
+  if (m_bSpatialEnhLayer)
+  {
+    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  }
+#endif
+
+  /* there are no SEI messages associated with this picture initially */
+  m_SEIs = NULL;
+  m_bUsedByCurr = false;
+  return;
+}
+#endif
+#else
 Void TComPic::create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow,
                       Int *numReorderPics, Bool bIsVirtual)
@@ -102,4 +170,5 @@
   return;
 }
+#endif
 
 Void TComPic::destroy()
@@ -127,4 +196,12 @@
   
   deleteSEIs(m_SEIs);
+#if SVC_EXTENSION && SVC_UPSAMPLING
+  if (m_bSpatialEnhLayer)
+  {
+    m_pcFullPelBaseRec->destroy();
+    delete m_pcFullPelBaseRec;
+    m_pcFullPelBaseRec  = NULL;
+  }
+#endif 
 }
 
@@ -465,4 +542,354 @@
 }
 
+#if REF_IDX_FRAMEWORK
+Void copyOnetoOnePicture(    // SVC_NONCOLL
+                  Pel *in,        
+                  Pel *out,      
+                  Int nCols,
+                  Int nRows, 
+                  Int fullRowWidth)
+{
+  Int rX;
+
+  for (rX = 0; rX < nRows; rX++)       
+  {
+    memcpy( out, in, sizeof(Pel) * nCols );
+    in = in + fullRowWidth;
+    out = out + fullRowWidth;
+  }
+}
+
+Void TComPic:: copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut)
+{
+  Int upsampledRowWidthLuma = pcPicYuvOut->getStride(); // 2 * pcPicYuvOut->getLumaMargin() + pcPicYuvOut->getWidth(); 
+  Int upsampledRowWidthCroma = pcPicYuvOut->getCStride(); //2 * pcPicYuvOut->getChromaMargin() + (pcPicYuvOut->getWidth()>>1);
+
+  copyOnetoOnePicture(
+    pcPicYuvIn->getLumaAddr(),        
+    pcPicYuvOut->getLumaAddr(),      
+    pcPicYuvOut->getWidth(), 
+    pcPicYuvOut->getHeight(),
+    upsampledRowWidthLuma);
+  copyOnetoOnePicture(
+    pcPicYuvIn->getCrAddr(),        
+    pcPicYuvOut->getCrAddr(),      
+    pcPicYuvOut->getWidth()>>1, 
+    pcPicYuvOut->getHeight()>>1,
+    upsampledRowWidthCroma);
+  copyOnetoOnePicture(
+    pcPicYuvIn->getCbAddr(),        
+    pcPicYuvOut->getCbAddr(),      
+    pcPicYuvOut->getWidth()>>1, 
+    pcPicYuvOut->getHeight()>>1,
+    upsampledRowWidthCroma);
+}
+
+#if REF_IDX_MFM
+#if !REUSE_BLKMAPPING
+Void TComPic::deriveUnitIdxBase( UInt uiUpsamplePelX, UInt uiUpsamplePelY, UInt ratio, UInt& uiBaseCUAddr, UInt& uiBaseAbsPartIdx )
+{
+  //pixel in the base layer
+
+  UInt uiPelX       = (uiUpsamplePelX<<1)/ratio;
+  UInt uiPelY       = (uiUpsamplePelY<<1)/ratio;
+  UInt uiBaseWidth  = getPicYuvRec()->getWidth();
+  UInt uiBaseHeight = getPicYuvRec()->getHeight();
+  
+  UInt uiWidthInCU       = ( uiBaseWidth % g_uiMaxCUWidth  ) ? uiBaseWidth /g_uiMaxCUWidth  + 1 : uiBaseWidth /g_uiMaxCUWidth;
+
+#if MFM_CLIPPING_FIX
+  uiPelX     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getWidth() - 1, uiPelX);
+  uiPelY     = (UInt)Clip3<UInt>(0, getPicYuvRec()->getHeight() - 1, uiPelY);
+#else
+  UInt uiHeightInCU      = ( uiBaseHeight% g_uiMaxCUHeight ) ? uiBaseHeight/ g_uiMaxCUHeight + 1 : uiBaseHeight/ g_uiMaxCUHeight;
+
+  uiPelX     = (UInt)Clip3<UInt>(0, uiWidthInCU * g_uiMaxCUWidth - 1, uiPelX);
+  uiPelY     = (UInt)Clip3<UInt>(0, uiHeightInCU * g_uiMaxCUHeight - 1, uiPelY);
+#endif
+  
+  uiBaseCUAddr = uiPelY / g_uiMaxCUHeight * uiWidthInCU + uiPelX / g_uiMaxCUWidth;
+
+  UInt uiWidthMinPU = g_uiMaxCUWidth / (1<<g_uiMaxCUDepth);
+  UInt uiHeightMinPU = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
+  
+  UInt uiAbsPelX = uiPelX - (uiPelX / g_uiMaxCUWidth) * g_uiMaxCUWidth;
+  UInt uiAbsPelY = uiPelY - (uiPelY / g_uiMaxCUHeight) * g_uiMaxCUHeight;
+
+  UInt RasterIdx = uiAbsPelY / uiHeightMinPU * (g_uiMaxCUWidth/uiWidthMinPU) + uiAbsPelX / uiWidthMinPU;
+  uiBaseAbsPartIdx = g_auiRasterToZscan[RasterIdx];
+
+  return;
+}
+#endif
+
+Void TComPic::copyUpsampledMvField(TComPic* pcPicBase)
+{
+#if !REUSE_MVSCALE || !REUSE_BLKMAPPING || AVC_SYNTAX
+  Int iBWidth   = pcPicBase->getPicYuvRec()->getWidth () - pcPicBase->getPicYuvRec()->getPicCropLeftOffset() - pcPicBase->getPicYuvRec()->getPicCropRightOffset();
+  Int iBHeight  = pcPicBase->getPicYuvRec()->getHeight() - pcPicBase->getPicYuvRec()->getPicCropTopOffset() - pcPicBase->getPicYuvRec()->getPicCropBottomOffset();
+
+  Int iEWidth   = getPicYuvRec()->getWidth() -  getPicYuvRec()->getPicCropLeftOffset() - getPicYuvRec()->getPicCropRightOffset();
+  Int iEHeight  = getPicYuvRec()->getHeight() - getPicYuvRec()->getPicCropTopOffset() -  getPicYuvRec()->getPicCropBottomOffset();
+#endif
+  
+#if !REUSE_MVSCALE  || !REUSE_BLKMAPPING
+  UInt upSampleRatio = 0;
+  if(iEWidth == iBWidth && iEHeight == iBHeight)
+  {
+    upSampleRatio = 2;
+  }
+  else if(2*iEWidth == 3*iBWidth && 2*iEHeight == 3*iBHeight)
+  {
+    upSampleRatio = 3;
+  }
+  else if(iEWidth == 2*iBWidth && iEHeight == 2*iBHeight)
+  {
+    upSampleRatio = 4;
+  }
+  else
+  {
+    assert(0);
+  }
+#endif
+
+  UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
+  UInt uiWidthMinPU      = g_uiMaxCUWidth/(1<<g_uiMaxCUDepth);
+  UInt uiHeightMinPU     = g_uiMaxCUHeight/(1<<g_uiMaxCUDepth);
+  Int  unitNum           = max (1, (Int)((16/uiWidthMinPU)*(16/uiHeightMinPU)) ); 
+
+  for(UInt cuIdx = 0; cuIdx < getPicSym()->getNumberOfCUsInFrame(); cuIdx++)  //each LCU
+  {
+    TComDataCU*             pcCUDes = getCU(cuIdx);
+
+    for(UInt uiAbsPartIdx = 0; uiAbsPartIdx < uiNumPartitions; uiAbsPartIdx+=unitNum )  //each 16x16 unit
+    {
+      //pixel position of each unit in up-sampled layer
+      UInt  uiPelX = pcCUDes->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ];
+      UInt  uiPelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
+      UInt uiBaseCUAddr, uiBaseAbsPartIdx;
+
+#if REUSE_BLKMAPPING
+      TComDataCU *pcColCU = 0;
+      pcColCU = pcCUDes->getBaseColCU(uiPelX + 8, uiPelY + 8, uiBaseCUAddr, uiBaseAbsPartIdx);
+#else 
+      pcPicBase->deriveUnitIdxBase(uiPelX + 8, uiPelY + 8, upSampleRatio, uiBaseCUAddr, uiBaseAbsPartIdx);
+#endif
+
+#if AVC_SYNTAX
+      Int iBX = ( (uiPelX + 8) * iBWidth + iEWidth/2 ) / iEWidth;
+      Int iBY = ( (uiPelY + 8) * iBHeight+ iEHeight/2 ) / iEHeight;
+
+#if REUSE_BLKMAPPING
+      if( ( iBX < iBWidth && iBY < iBHeight ) && pcColCU && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#else
+      if( ( iBX < iBWidth && iBY < iBHeight ) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#endif
+#else
+#if REUSE_BLKMAPPING
+      if( pcColCU && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcColCU->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#else
+      if( (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_NONE) && (pcPicBase->getCU(uiBaseCUAddr)->getPredictionMode(uiBaseAbsPartIdx) != MODE_INTRA) )  //base layer unit not skip and invalid mode
+#endif
+#endif
+      {
+        for(UInt refPicList = 0; refPicList < 2; refPicList++)  //for each reference list
+        {
+#if REUSE_MVSCALE
+          TComMvField sMvFieldBase, sMvField;
+#if REUSE_BLKMAPPING
+          pcColCU->getMvField( pcColCU, uiBaseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
+#else
+          pcPicBase->getCU(uiBaseCUAddr)->getMvField( pcPicBase->getCU(uiBaseCUAddr), uiBaseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
+#endif
+          pcCUDes->scaleBaseMV( sMvField, sMvFieldBase );
+#else
+          TComMv cMv = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)refPicList)->getMv(uiBaseAbsPartIdx);
+          Int refIdx = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)refPicList)->getRefIdx(uiBaseAbsPartIdx);
+
+          Int Hor =  ((Int)upSampleRatio * cMv.getHor())/2 ;
+          Int Ver =  ((Int)upSampleRatio * cMv.getVer())/2 ;
+
+          TComMv cScaledMv(Hor, Ver);
+          TComMvField sMvField;
+          sMvField.setMvField(cScaledMv, refIdx);
+#endif
+
+          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, uiAbsPartIdx);
+          pcCUDes->setPredictionMode(uiAbsPartIdx, MODE_INTER);
+        }
+      }
+      else
+      {
+        TComMvField zeroMvField;  //zero MV and invalid reference index
+        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(zeroMvField, uiAbsPartIdx);
+        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(zeroMvField, uiAbsPartIdx);
+        pcCUDes->setPredictionMode(uiAbsPartIdx, MODE_INTRA);
+      }
+
+      for(UInt i = 1; i < unitNum; i++ )  
+      {
+        pcCUDes->getCUMvField(REF_PIC_LIST_0)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_0)->getMv(uiAbsPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_0)->getRefIdx(uiAbsPartIdx), uiAbsPartIdx + i);
+        pcCUDes->getCUMvField(REF_PIC_LIST_1)->setMvField(pcCUDes->getCUMvField(REF_PIC_LIST_1)->getMv(uiAbsPartIdx), pcCUDes->getCUMvField(REF_PIC_LIST_1)->getRefIdx(uiAbsPartIdx), uiAbsPartIdx + i);
+        pcCUDes->setPredictionMode(uiAbsPartIdx+i, pcCUDes->getPredictionMode(uiAbsPartIdx))  ;
+      }
+    }
+      memset( pcCUDes->getPartitionSize(), SIZE_2Nx2N, sizeof(char)*uiNumPartitions);
+  }
+}
+#endif
+
+#endif
+
+#if AVC_SYNTAX
+Void TComPic::readBLSyntax( fstream* filestream, UInt numBytes )
+{
+  if( !filestream->good() )
+  {
+    return;
+  }
+
+  UInt   uiWidth      = this->getPicYuvRec()->getWidth() - this->getPicYuvRec()->getPicCropLeftOffset() - this->getPicYuvRec()->getPicCropRightOffset();
+  UInt   uiHeight     = this->getPicYuvRec()->getHeight() - this->getPicYuvRec()->getPicCropTopOffset() - this->getPicYuvRec()->getPicCropBottomOffset();
+  UInt64 uiPOC        = (UInt64)this->getPOC();
+  UInt   uiPartWidth  = uiWidth / 4;
+  UInt   uiPartHeight = uiHeight / 4;
+
+  UInt uiNumPartInWidth    = this->getNumPartInWidth();
+  UInt uiNumPartInHeight   = this->getNumPartInHeight();
+  UInt uiNumPartLCUInWidth = this->getFrameWidthInCU();
+
+  UInt64 uiPos = (UInt64)uiPOC * uiWidth * uiHeight * numBytes / 16;
+   
+  filestream->seekg( uiPos, ios_base::beg );
+
+  for( Int i = 0; i < uiPartHeight; i++ )
+  {
+    for( Int j = 0; j < uiPartWidth; j++ )
+    {
+      UInt uiX = ( j / uiNumPartInWidth );
+      UInt uiY = ( i / uiNumPartInHeight );
+
+      UInt uiLCUAddr = uiY * uiNumPartLCUInWidth + uiX;
+      UInt uiPartAddr = ( i - uiY * uiNumPartInHeight ) * uiNumPartInWidth + ( j - uiX * uiNumPartInWidth );
+      uiPartAddr = g_auiRasterToZscan[uiPartAddr];
+      
+      TComDataCU* pcCU = this->getCU( uiLCUAddr );
+      
+      TComMv mv;
+      Short temp;
+
+      // RefIdxL0
+      Char refIdxL0 = -1;
+      filestream->read( &refIdxL0, 1 );
+      assert( refIdxL0 >= -1 );
+      pcCU->getCUMvField( REF_PIC_LIST_0 )->setRefIdx( (Int)refIdxL0, uiPartAddr );
+
+      // RefIdxL1
+      Char refIdxL1 = -1;
+      filestream->read( &refIdxL1, 1 );
+      assert( refIdxL1 >= -1 );
+      pcCU->getCUMvField( REF_PIC_LIST_1 )->setRefIdx( (Int)refIdxL1, uiPartAddr );
+
+      // MV L0
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setHor( (Short)temp );
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setVer( (Short)temp );
+      pcCU->getCUMvField( REF_PIC_LIST_0 )->setMv( mv, uiPartAddr );
+
+      // MV L1
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setHor( (Short)temp );
+      temp = 0;
+      filestream->read( reinterpret_cast<char*>(&temp), 2 );
+      mv.setVer( (Short)temp );
+      pcCU->getCUMvField( REF_PIC_LIST_1 )->setMv( mv, uiPartAddr );
+
+      // set dependent information
+      pcCU->setPredictionMode( uiPartAddr, ( refIdxL0 == NOT_VALID && refIdxL1 == NOT_VALID ) ? MODE_INTRA : MODE_INTER );
+      UInt uiInterDir = ( refIdxL0 != NOT_VALID ) + ( refIdxL1 != NOT_VALID && this->getSlice(0)->isInterB() ) * 2;
+      assert( uiInterDir >= 0 && uiInterDir <= 3 );
+      pcCU->setInterDir( uiPartAddr, uiInterDir );      
+    }
+  }
+}
+#endif
+
+#if SYNTAX_OUTPUT
+Void TComPic::wrireBLSyntax( fstream* filestream, UInt numBytes )
+{
+  if( !filestream->good() )
+  {
+    return;
+  }
+
+  UInt   uiWidth      = this->getPicYuvRec()->getWidth() - getSlice(0)->getSPS()->getPicCropLeftOffset() - getSlice(0)->getSPS()->getPicCropRightOffset();
+  UInt   uiHeight     = this->getPicYuvRec()->getHeight() - getSlice(0)->getSPS()->getPicCropTopOffset() - getSlice(0)->getSPS()->getPicCropBottomOffset();
+  UInt64 uiPOC        = (UInt64)this->getPOC();
+  UInt   uiPartWidth  = uiWidth / 4;
+  UInt   uiPartHeight = uiHeight / 4;
+
+  UInt uiNumPartInWidth    = this->getNumPartInWidth();
+  UInt uiNumPartInHeight   = this->getNumPartInHeight();
+  UInt uiNumPartLCUInWidth = this->getFrameWidthInCU();
+
+  filestream->seekg( uiPOC * uiWidth * uiHeight * numBytes / 16 );
+    
+  for( Int i = 0; i < uiPartHeight; i++ )
+  {
+    for( Int j = 0; j < uiPartWidth; j++ )
+    {
+      UInt uiX = ( j / uiNumPartInWidth );
+      UInt uiY = ( i / uiNumPartInHeight );
+
+      UInt uiLCUAddr = uiY * uiNumPartLCUInWidth + uiX;
+      UInt uiPartAddr = ( i - uiY * uiNumPartInHeight ) * uiNumPartInWidth + ( j - uiX * uiNumPartInWidth );
+      uiPartAddr = g_auiRasterToZscan[uiPartAddr];
+      
+      TComDataCU* pcCU = this->getCU( uiLCUAddr );
+      
+      TComMv mv;
+      Short temp;
+      Char refIdxL0 = NOT_VALID, refIdxL1 = NOT_VALID;
+
+      // RefIdx
+      if( !pcCU->isIntra( uiPartAddr ) )
+      {
+        refIdxL0 = (Char)pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
+        refIdxL1 = (Char)pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
+      }
+      assert( refIdxL0 >= - 1 && refIdxL1 >= - 1 );
+      filestream->put( refIdxL0 );
+      filestream->put( refIdxL1 );
+
+      // MV L0
+      mv.setZero();
+      if( refIdxL0 >= 0 )
+      {
+        mv = pcCU->getCUMvField( REF_PIC_LIST_0 )->getMv( uiPartAddr );
+      }
+      temp = (Short)mv.getHor();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+      temp = (Short)mv.getVer();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+
+      // MV L1
+      mv.setZero();
+      if( refIdxL1 >= 0 )
+      {
+        mv = pcCU->getCUMvField( REF_PIC_LIST_1 )->getMv( uiPartAddr );
+      }
+      temp = (Short)mv.getHor();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+      temp = (Short)mv.getVer();
+      filestream->write( reinterpret_cast<char*>(&temp), 2 );
+    }
+  }
+}
+#endif
+
 
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPic.h	(revision 54)
@@ -45,4 +45,7 @@
 #include "TComBitStream.h"
 #include "SEI.h"
+#if AVC_BASE || SYNTAX_OUTPUT
+#include <fstream>
+#endif
 
 //! \ingroup TLibCommon
@@ -58,4 +61,7 @@
 private:
   UInt                  m_uiTLayer;               //  Temporal layer
+#if SVC_EXTENSION
+  UInt                  m_layerId;              //  Layer ID
+#endif
   Bool                  m_bUsedByCurr;            //  Used by current picture
   Bool                  m_bIsLongTerm;            //  IS long term picture
@@ -85,4 +91,11 @@
 
   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
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+  Bool                  m_bIsILR;                 //  Is ILR picture
+#endif
+#endif
 
 public:
@@ -90,11 +103,38 @@
   virtual ~TComPic();
   
+#if SVC_UPSAMPLING
   Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
-                        Int *numReorderPics, Bool bIsVirtual = false );
-                        
+                        Int *numReorderPics, TComSPS* pcSps = NULL, Bool bIsVirtual = false );
+#if REF_IDX_FRAMEWORK
+  Void          createWithOutYuv( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, TComSPS* pcSps = NULL, Bool bIsVirtual = false );  
+  Void          setPicYuvRec(TComPicYuv *pPicYuv) { m_apcPicYuv[1]=pPicYuv; }
+#endif
+#else
+  Void          create( Int iWidth, Int iHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth, Window &conformanceWindow, Window &defaultDisplayWindow, 
+                        Int *numReorderPics, Bool bIsVirtual = false );                        
+#endif
   virtual Void  destroy();
   
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
+#if SVC_EXTENSION
+  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;  }
+#endif
+#if REF_IDX_ME_AROUND_ZEROMV || REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+  Void          setIsILR( Bool bIsILR)      {m_bIsILR = bIsILR;}
+  Bool          getIsILR()                  {return m_bIsILR;}
+#endif
+
+#if REF_IDX_MFM
+  Void          copyUpsampledMvField  (  TComPic* pcPicBase );
+#if !REUSE_BLKMAPPING
+  Void          deriveUnitIdxBase     (  UInt uiUpsamplePelX, UInt uiUpsamplePelY, UInt ratio, UInt& uiBaseCUAddr, UInt& uiBaseAbsPartIdx );
+#endif
+#endif
 
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
@@ -177,4 +217,14 @@
   const SEIMessages& getSEIs() const { return m_SEIs; }
 
+#if REF_IDX_FRAMEWORK
+  Void  copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut); 
+#endif
+#if AVC_SYNTAX
+  Void readBLSyntax( fstream* filestream, UInt numBytes );
+#endif
+#if SYNTAX_OUTPUT
+  Void wrireBLSyntax( fstream* filestream, UInt numBytes );
+#endif
+
 };// END CLASS DEFINITION TComPic
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.cpp	(revision 54)
@@ -147,4 +147,8 @@
   m_apcTComDataCU = NULL;
 
+#if AVC_BASE || REF_IDX_FRAMEWORK
+  if( m_apcTComTile )
+  {
+#endif
   for(Int i = 0; i < (m_iNumColumnsMinus1+1)*(m_iNumRowsMinus1+1); i++ )
   {
@@ -152,4 +156,7 @@
   }
   delete [] m_apcTComTile;
+#if AVC_BASE || REF_IDX_FRAMEWORK
+  }
+#endif
 
   m_apcTComTile = NULL;
@@ -178,5 +185,9 @@
   {
     m_apcTComSlice[m_uiNumAllocatedSlice-1]->copySliceInfo( m_apcTComSlice[m_uiNumAllocatedSlice-2] );
+#if SET_SLICE_LAYER_ID
+    m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice( m_apcTComSlice[m_uiNumAllocatedSlice-1]->getLayerId() );
+#else
     m_apcTComSlice[m_uiNumAllocatedSlice-1]->initSlice();
+#endif
   }
 }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicSym.h	(revision 54)
@@ -122,4 +122,10 @@
   TComDataCU*&  getCU( UInt uiCUAddr )  { return m_apcTComDataCU[uiCUAddr];     }
   
+#if AVC_SYNTAX
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+  UInt        getMaxDepth()             { return m_uhTotalDepth;               }
+#endif
+  
   Void        setSlice(TComSlice* p, UInt i) { m_apcTComSlice[i] = p;           }
   UInt        getNumAllocatedSlice()    { return m_uiNumAllocatedSlice;         }
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 54)
@@ -60,5 +60,4 @@
   m_piPicOrgU       = NULL;
   m_piPicOrgV       = NULL;
-  
   m_bIsBorderExtended = false;
 }
@@ -67,10 +66,20 @@
 {
 }
-
+#if SVC_UPSAMPLING
+Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps )
+#else
 Void TComPicYuv::create( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth )
+#endif
 {
   m_iPicWidth       = iPicWidth;
   m_iPicHeight      = iPicHeight;
   
+#if SVC_UPSAMPLING
+  if(pcSps != NULL)
+  {
+    m_conformanceWindow = pcSps->getConformanceWindow();
+  }
+#endif
+
   // --> After config finished!
   m_iCuWidth        = uiMaxCUWidth;
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPicYuv.h	(revision 54)
@@ -42,5 +42,7 @@
 #include "CommonDef.h"
 #include "TComRom.h"
-
+#if SVC_UPSAMPLING
+#include "TComSlice.h"
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -86,4 +88,8 @@
   Int   m_iChromaMarginY;
   
+#if SVC_UPSAMPLING
+  Window  m_conformanceWindow;
+#endif
+
   Bool  m_bIsBorderExtended;
   
@@ -98,6 +104,10 @@
   //  Memory management
   // ------------------------------------------------------------------------------------------------
+#if SVC_UPSAMPLING
+  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth, TComSPS* pcSps = NULL);
+#else
+  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
+#endif  
   
-  Void  create      ( Int iPicWidth, Int iPicHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxCUDepth );
   Void  destroy     ();
   
@@ -112,4 +122,11 @@
   Int   getHeight   ()     { return  m_iPicHeight;   }
   
+#if SVC_EXTENSION
+  Void   setHeight   ( Int iPicHeight )     { m_iPicHeight = iPicHeight; }
+#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); }
@@ -140,4 +157,9 @@
   Pel*  getCrAddr   ( Int iCuAddr, Int uiAbsZorderIdx ) { return m_piPicOrgV + m_cuOffsetC[iCuAddr] + m_buOffsetC[g_auiZscanToRaster[uiAbsZorderIdx]]; }
   
+#if SVC_UPSAMPLING
+  Window& getConformanceWindow()                           { return  m_conformanceWindow;             }
+  Void    setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
+#endif
+
   // ------------------------------------------------------------------------------------------------
   //  Miscellaneous
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.cpp	(revision 54)
@@ -407,4 +407,12 @@
 }
 
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
+Void TComPrediction::getBaseBlk( TComDataCU* pcCU, TComYuv* pcYuvPred, Int iPartAddr, Int iWidth, Int iHeight )
+{
+  pcCU->getBaseLumaBlk( iWidth, iHeight, iPartAddr, pcYuvPred->getLumaAddr( iPartAddr ), pcYuvPred->getStride() );
+  pcCU->getBaseChromaBlk( iWidth >> 1, iHeight >> 1, iPartAddr, pcYuvPred->getCbAddr( iPartAddr ), pcYuvPred->getCStride(), 0 );
+  pcCU->getBaseChromaBlk( iWidth >> 1, iHeight >> 1, iPartAddr, pcYuvPred->getCrAddr( iPartAddr ), pcYuvPred->getCStride(), 1 );
+}
+#endif
 
 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
@@ -758,3 +766,10 @@
   return;
 }
+
+#if SVC_UPSAMPLING
+Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
+{
+  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
+}
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComPrediction.h	(revision 54)
@@ -48,4 +48,8 @@
 #include "TComWeightPrediction.h"
 
+#if SVC_UPSAMPLING
+#include "TComDataCU.h"
+#include "TComUpsampleFilter.h"
+#endif
 //! \ingroup TLibCommon
 //! \{
@@ -70,4 +74,8 @@
   TComInterpolationFilter m_if;
   
+#if SVC_UPSAMPLING
+  TComUpsampleFilter      m_cUsf;
+#endif
+
   Pel*   m_pLumaRecBuffer;       ///< array for downsampled reconstructed luma sample 
   Int    m_iLumaRecStride;       ///< stride of #m_pLumaRecBuffer array
@@ -94,4 +102,7 @@
   Void    initTempBuff();
   
+#if INTRA_BL
+  Void getBaseBlk ( TComDataCU* pcCU, TComYuv* pcYuvPred, Int iPartAddr, Int iWidth, Int iHeight );
+#endif
   // inter
   Void motionCompensation         ( TComDataCU*  pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList = REF_PIC_LIST_X, Int iPartIdx = -1 );
@@ -110,4 +121,7 @@
   Int  getPredicBufHeight()       { return m_iYuvExtHeight; }
 
+#if SVC_UPSAMPLING
+  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+#endif
 };
 
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.cpp	(revision 54)
@@ -81,4 +81,8 @@
 , m_bNoBackPredFlag               ( false )
 , m_uiTLayer                      ( 0 )
+#if SVC_EXTENSION
+, m_layerId                     ( 0 )
+, m_pcBaseColPic                  ( NULL )
+#endif
 , m_bTLayerSwitchingFlag          ( false )
 , m_sliceMode                   ( 0 )
@@ -136,6 +140,13 @@
 
 
+#if SET_SLICE_LAYER_ID
+Void TComSlice::initSlice( UInt layerId )
+#else
 Void TComSlice::initSlice()
-{
+#endif
+{
+#if SET_SLICE_LAYER_ID
+  m_layerId = layerId;
+#endif
   m_aiNumRefIdx[0]      = 0;
   m_aiNumRefIdx[1]      = 0;
@@ -344,5 +355,11 @@
 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
 {
+#if REF_IDX_FRAMEWORK
+  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
+      (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
+      (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
+#else
   if (m_eSliceType == I_SLICE)
+#endif
   {
     ::memset( m_apcRefPicList, 0, sizeof (m_apcRefPicList));
@@ -1261,4 +1278,7 @@
 , m_vuiParametersPresentFlag  (false)
 , m_vuiParameters             ()
+#if SVC_EXTENSION
+, m_layerId(0)
+#endif
 {
   for ( Int i = 0; i < MAX_TLAYER; i++ )
@@ -1926,5 +1946,9 @@
 //! activate a PPS and depending on isIDR parameter also SPS and VPS
 //! \returns true, if activation is successful
+#if SVC_EXTENSION
+Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR, UInt layerId)
+#else
 Bool ParameterSetManager::activatePPS(Int ppsId, Bool isIDR)
+#endif
 {
   TComPPS *pps = m_ppsMap.getPS(ppsId);
@@ -1932,5 +1956,9 @@
   {
     Int spsId = pps->getSPSId();
+#if SVC_EXTENSION
+    if (!isIDR && (spsId != layerId ))
+#else
     if (!isIDR && (spsId != m_activeSPSId))
+#endif
     {
       printf("Warning: tried to activate PPS referring to a inactive SPS at non-IDR.");
@@ -2001,3 +2029,151 @@
 }
 #endif
+
+#if SVC_EXTENSION
+#if AVC_SYNTAX
+Void TComSlice::initBaseLayerRPL( TComSlice *pcSlice )
+{
+// Assumed that RPL of the base layer is same to the EL, otherwise this information should be also dumped and read from the metadata file
+  setPOC( pcSlice->getPOC() );
+  if( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )
+  {
+    setSliceType( I_SLICE );
+  }
+  else
+  {
+    setSliceType( pcSlice->getSliceType() );
+  }
+
+  if( this->isIntra() )
+  {
+    return;
+  }
+
+  //initialize reference POC of BL
+  for( Int iRefPicList = 0; iRefPicList < 2; iRefPicList++ )
+  {
+    RefPicList eRefPicList = RefPicList( iRefPicList );
+
+    assert( pcSlice->getNumRefIdx( eRefPicList) > 0 );
+    setNumRefIdx( eRefPicList, pcSlice->getNumRefIdx( eRefPicList ) - 1 );
+    assert( getNumRefIdx( eRefPicList) <= MAX_NUM_REF);
+
+    for(Int refIdx = 0; refIdx < getNumRefIdx( eRefPicList ); refIdx++) 
+    {
+      setRefPOC( pcSlice->getRefPic( eRefPicList, refIdx )->getPOC(), eRefPicList, refIdx );
+      setRefPic( pcSlice->getRefPic( eRefPicList, refIdx ), eRefPicList, refIdx );
+      /*
+      // should be set if the base layer has its own instance of the reference picture lists, currently EL RPL is reused.
+      getRefPic( eRefPicList, refIdx )->setLayerId( 0 );
+      getRefPic( eRefPicList, refIdx )->setIsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsLongTerm() );
+      getRefPic( eRefPicList, refIdx )->setIsUsedAsLongTerm( pcSlice->getRefPic( eRefPicList, refIdx )->getIsUsedAsLongTerm() );
+      */
+
+    }
+  }  
+  return;
+}
+#endif
+
+Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt layerID )
+{  
+  if (layerID == 0)
+  {
+    m_pcBaseColPic = NULL;
+    return;
+  }        
+  setBaseColPic(xGetRefPic(rcListPic, getPOC())); 
+}
+#endif 
+
+#if REF_IDX_FRAMEWORK
+Void TComSlice::addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset )
+{
+  if(getSPS()->getLayerId() && m_eSliceType != I_SLICE)
+  {
+#if REF_IDX_MFM
+    assert(iRefPicNum == 1);
+    if( getPOC() != 0 )
+    { 
+      pIlpPicList[0]->copyUpsampledMvField(getBaseColPic());
+    }
+#endif
+    //add to list 0;
+    Int iOffset;
+    m_aiNumRefIdx[REF_PIC_LIST_0] += iInsertOffset;
+    iOffset = m_aiNumRefIdx[REF_PIC_LIST_0];
+    for (Int i=0; i<iRefPicNum; i++)
+    {
+      pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
+      pIlpPicList[i]->setIsUsedAsLongTerm(1);  //mark ilp as long-term reference
+      m_apcRefPicList[REF_PIC_LIST_0][iOffset + i] = pIlpPicList[i]; 
+      m_aiNumRefIdx[REF_PIC_LIST_0]++;
+      //m_aiNumRefIdx[REF_PIC_LIST_C]++;
+    }
+    if(m_eSliceType == B_SLICE)
+    {
+      m_aiNumRefIdx[REF_PIC_LIST_1] += iInsertOffset;
+      iOffset = m_aiNumRefIdx[REF_PIC_LIST_1];
+      for (Int i=0; i<iRefPicNum; i++)
+      {
+        pIlpPicList[i]->setIsLongTerm(1);  //mark ilp as long-term reference
+        pIlpPicList[i]->setIsUsedAsLongTerm(1);  //mark ilp as long-term reference
+        m_apcRefPicList[REF_PIC_LIST_1][iOffset + i] = pIlpPicList[i]; 
+        m_aiNumRefIdx[REF_PIC_LIST_1]++;
+        //m_aiNumRefIdx[REF_PIC_LIST_C]++;
+      }
+    }
+  }
+}
+
+#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());
+
+#if REUSE_MVSCALE || REUSE_BLKMAPPING
+  ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
+#endif
+
+  //initialize reference POC of ILP 
+  for(Int refIdx = 0; refIdx < MAX_NUM_REF; refIdx++) 
+  { 
+    ilpPic[0]->getSlice(0)->setRefPOC(0, REF_PIC_LIST_0, refIdx); 
+    ilpPic[0]->getSlice(0)->setRefPOC(0, REF_PIC_LIST_1, refIdx); 
+
+    ilpPic[0]->getSlice(0)->setRefPic(NULL, REF_PIC_LIST_0, refIdx); 
+    ilpPic[0]->getSlice(0)->setRefPic(NULL, REF_PIC_LIST_1, refIdx); 
+  }
+
+  //set reference POC of ILP 
+  ilpPic[0]->getSlice(0)->setNumRefIdx(REF_PIC_LIST_0, pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0));
+  assert(ilpPic[0]->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0) <= MAX_NUM_REF); 
+  ilpPic[0]->getSlice(0)->setNumRefIdx(REF_PIC_LIST_1, pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1));
+  assert(ilpPic[0]->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1) <= MAX_NUM_REF);
+
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(REF_PIC_LIST_0, refIdx), REF_PIC_LIST_0, refIdx); 
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(REF_PIC_LIST_1, refIdx), REF_PIC_LIST_1, refIdx);
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_0); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(REF_PIC_LIST_0, refIdx), REF_PIC_LIST_0, refIdx); 
+  }
+  for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(REF_PIC_LIST_1); refIdx++) 
+  {
+    ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(REF_PIC_LIST_1, refIdx), REF_PIC_LIST_1, refIdx); 
+  }
+  return;
+}
+#endif
+
+
+#endif
 //! \}
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComSlice.h	(revision 54)
@@ -51,4 +51,8 @@
 class TComPic;
 class TComTrQuant;
+
+#if SVC_EXTENSION
+class TComPicYuv;
+#endif
 // ====================================================================================================================
 // Constants
@@ -850,4 +854,11 @@
   static const Int   m_winUnitY[MAX_CHROMA_FORMAT_IDC+1];
   TComPTL     m_pcPTL;
+
+#if SVC_EXTENSION
+  UInt m_layerId;
+#endif
+#if REF_IDX_MFM
+  Bool m_bMFMEnabledFlag;
+#endif
 public:
   TComSPS();
@@ -976,4 +987,13 @@
 
   TComPTL* getPTL()     { return &m_pcPTL; }
+
+#if SVC_EXTENSION
+  Void     setLayerId(UInt layerId) { m_layerId = layerId; }
+  UInt     getLayerId() { return m_layerId; }
+#endif
+#if REF_IDX_MFM
+  Void     setMFMEnabledFlag(Bool flag) {m_bMFMEnabledFlag = flag;}
+  Bool     getMFMEnabledFlag()          {return m_bMFMEnabledFlag;}
+#endif
 };
 
@@ -1283,4 +1303,9 @@
   Bool        m_bNoBackPredFlag;
   UInt        m_uiTLayer;
+#if SVC_EXTENSION
+  UInt        m_layerId;
+  TComPic*    m_pcBaseColPic;
+  TComPicYuv* m_pcFullPelBaseRec;
+#endif 
   Bool        m_bTLayerSwitchingFlag;
 
@@ -1319,5 +1344,9 @@
   TComSlice();
   virtual ~TComSlice(); 
+#if SET_SLICE_LAYER_ID
+  Void      initSlice       ( UInt layerId );
+#else
   Void      initSlice       ();
+#endif
 
   Void      setVPS          ( TComVPS* pcVPS ) { m_pcVPS = pcVPS; }
@@ -1417,4 +1446,24 @@
   Void      setDepth            ( Int iDepth )                  { m_iDepth            = iDepth; }
   
+#if SVC_EXTENSION  
+  Void      setBaseColPic       ( TComPic* p)                   { m_pcBaseColPic = p; }
+  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
+  TComPic*  getBaseColPic       ()  { return m_pcBaseColPic; }
+
+  Void      setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt      getLayerId ()               { return m_layerId; }
+
+  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
+  TComPicYuv* getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+
+#if AVC_SYNTAX
+  Void      initBaseLayerRPL( TComSlice *pcSlice );
+#endif
+#endif
+
+#if REF_IDX_MFM
+  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
+#endif
+
   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
   Void      setRefPOCList       ();
@@ -1536,5 +1585,7 @@
   Void      setEnableTMVPFlag     ( Bool   b )    { m_enableTMVPFlag = b; }
   Bool      getEnableTMVPFlag     ()              { return m_enableTMVPFlag;}
-
+#if REF_IDX_FRAMEWORK
+  Void      addRefPicList( TComPic **pIlpPicList, Int iRefPicNum, Int iInsertOffset=0 );
+#endif
 protected:
   TComPic*  xGetRefPic  (TComList<TComPic*>& rcListPic,
@@ -1625,5 +1676,9 @@
   //! activate a PPS and depending on isIDR parameter also SPS and VPS
   //! \returns true, if activation is successful
+#if SVC_EXTENSION
+  Bool activatePPS(Int ppsId, Bool isIDR, UInt layerId);
+#else
   Bool activatePPS(Int ppsId, Bool isIDR);
+#endif
 
   TComVPS* getActiveVPS(){ return m_vpsMap.getPS(m_activeVPSId); };
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 54)
@@ -1236,4 +1236,10 @@
     uiMode = pcCU->getLumaIntraDir( uiAbsPartIdx );
   }
+#if INTRA_BL_DST4x4
+  else if(eTType == TEXT_LUMA && pcCU->isIntraBL(uiAbsPartIdx) )
+  {
+    uiMode = DC_IDX; //Using DST
+  }
+#endif
   else
   {
@@ -1309,5 +1315,16 @@
     Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTxt];
     assert(scalingListType < 6);
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+    if(pcCU->isIntraBL(uiAbsPartIdx) && eTxt == TEXT_LUMA)
+    {
+      invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, DC_IDX, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+    }
+    else
+    {
+      invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+    }
+#else
     invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
+#endif
   }
   else
@@ -1803,5 +1820,9 @@
   Int     ui16CtxCbf          = 0;
   Int     iBestLastIdxP1      = 0;
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  if( (!pcCU->isIntra( uiAbsPartIdx ) || pcCU->isIntraBL( uiAbsPartIdx )) && eTType == TEXT_LUMA && pcCU->getTransformIdx( uiAbsPartIdx ) == 0 )
+#else
   if( !pcCU->isIntra( uiAbsPartIdx ) && eTType == TEXT_LUMA && pcCU->getTransformIdx( uiAbsPartIdx ) == 0 )
+#endif
   {
     ui16CtxCbf   = 0;
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 54)
@@ -0,0 +1,604 @@
+
+#include "TComUpsampleFilter.h"
+#include "TypeDef.h"
+
+#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] =
+{
+  {  0,  0,  0, 64,  0,  0,  0,  0}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  { -1, 4, -11, 52, 26,  -8, 3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5      
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //       
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  { -1, 4, -11, 40, 40, -11, 4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  // 
+};
+
+const Int TComUpsampleFilter::m_chromaFixedFilter[16][NTAPS_US_CHROMA] =
+{
+#if CHROMA_UPSAMPLING
+  {  0, 64,  0,  0},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
+  { -4, 30, 42, -4},// <-> actual phase shift 7/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  {  0,  4, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+#else
+  {  0, 64,  0,  0},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  { -5, 50, 22, -3},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  {CNU,CNU,CNU,CNU},// 
+  { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
+  { -4, 30, 43, -5},// <-> actual phase shift 7/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+  {CNU,CNU,CNU,CNU},// 
+  { -3, 22, 50, -5},// <-> actual phase shift 2/3, used for spatial scalability x1.5
+  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},// 
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  { -1,  5, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
+#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)
+{
+}
+
+TComUpsampleFilter::~TComUpsampleFilter(void)
+{
+}
+
+Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+{
+  assert ( NTAPS_US_LUMA == 8 );
+  assert ( NTAPS_US_CHROMA == 4 );
+
+  Int i, j;
+
+  //========== Y component upsampling ===========
+  const Window &confBL = pcBasePic->getConformanceWindow();
+  const Window &confEL = pcUsPic->getConformanceWindow();
+
+  Int iBWidth   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int iBHeight  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+  Int iBStride  = pcBasePic->getStride();
+
+  Int iEWidth   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int iEHeight  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+  Int iEStride  = pcUsPic->getStride();
+  
+  Pel* piTempBufY = pcTempPic->getLumaAddr();
+  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 ( pcBasePic->getPicCropRightOffset() )
+  {
+    tempBufSizeRight = pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+  }
+  
+  if( pcBasePic->getPicCropBottomOffset() )
+  {
+    tempBufSizeBottom = pcBasePic->getPicCropBottomOffset() * 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 PHASE_DERIVATION_IN_INTEGER
+  Int iRefPos16 = 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 (iEWidth == 2*iBWidth) // 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 ( iEWidth == 2*iBWidth || 2*iEWidth == 3*iBWidth );
+  assert ( iEHeight == 2*iBHeight || 2*iEHeight == 3*iBHeight );
+
+#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 + iBWidth;
+    piDstY = tempBufRight;
+    for( i = 0; i < pcBasePic->getHeight(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getPicCropRightOffset());
+      piSrcY += iBStride;
+      piDstY += pcBasePic->getPicCropRightOffset();
+    }
+    
+    if(pcBasePic->getPicCropRightOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = piSrcBufU + (iBWidth>>1);
+      piDstU = tempBufRight + pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+      piSrcV = piSrcBufV + (iBWidth>>1);
+      piDstV = piDstU + (pcBasePic->getPicCropRightOffset()>>1) * (pcBasePic->getHeight()>>1);
+    
+      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcU += iBStrideChroma;
+        piDstU += (pcBasePic->getPicCropRightOffset()>>1);
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcV += iBStrideChroma;
+        piDstV += (pcBasePic->getPicCropRightOffset()>>1);
+      }
+    }
+    
+    pcBasePic->setWidth(iBWidth);
+  }
+  
+  if( tempBufSizeBottom )
+  {
+    piSrcY = piSrcBufY + iBHeight * iBStride;
+    piDstY = tempBufBottom;
+    for( i = 0; i < pcBasePic->getPicCropBottomOffset(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
+      piSrcY += iBStride;
+      piDstY += pcBasePic->getWidth();
+    }
+    
+    if(pcBasePic->getPicCropBottomOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = piSrcBufU + (iBHeight>>1) * iBStrideChroma;
+      piDstU = tempBufBottom + pcBasePic->getPicCropBottomOffset() * pcBasePic->getWidth();
+      piSrcV = piSrcBufV + (iBHeight>>1) * iBStrideChroma;
+      piDstV = piDstU + (pcBasePic->getPicCropBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
+      
+      for( i = 0; i < pcBasePic->getPicCropBottomOffset()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcU += iBStrideChroma;
+        piDstU += (pcBasePic->getWidth()>>1);
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcV += iBStrideChroma;
+        piDstV += (pcBasePic->getWidth()>>1);
+      }
+    }
+
+    pcBasePic->setHeight(iBHeight);
+  }
+#endif
+  
+  pcBasePic->setBorderExtension(false);
+  pcBasePic->extendPicBorder   (); // extend the border.
+
+#if PHASE_DERIVATION_IN_INTEGER
+  Int   iShiftX = 16;
+  Int   iShiftY = 16;
+
+  Int   iPhaseX = 0;
+  Int   iPhaseY = 0;
+
+  Int   iAddX       = ( ( ( iBWidth * iPhaseX ) << ( iShiftX - 2 ) ) + ( iEWidth >> 1 ) ) / iEWidth + ( 1 << ( iShiftX - 5 ) );
+  Int   iAddY       = ( ( ( iBHeight * iPhaseY ) << ( iShiftY - 2 ) ) + ( iEHeight >> 1 ) ) / iEHeight+ ( 1 << ( iShiftY - 5 ) );
+
+  Int   iDeltaX     = 4 * iPhaseX;
+  Int   iDeltaY     = 4 * iPhaseY;  
+
+
+  Int iShiftXM4 = iShiftX - 4;
+  Int iShiftYM4 = iShiftY - 4;
+
+  Int   iScaleX     = ( ( iBWidth << iShiftX ) + ( iEWidth >> 1 ) ) / iEWidth;
+  Int   iScaleY     = ( ( iBHeight << iShiftY ) + ( iEHeight >> 1 ) ) / iEHeight;
+#else
+  const Double sFactor = 1.0 * iBWidth / iEWidth;
+  const Double sFactor12 = sFactor * 12;
+#endif
+
+  //========== horizontal upsampling ===========
+  for( i = 0; i < iEWidth; i++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((i*iScaleX + iAddX) >> iShiftXM4) - iDeltaX;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 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 < iBHeight ; j++ )
+    {
+      *piDstY = sumLumaHor(piSrcY, coeff);
+      piSrcY += iBStride;
+      piDstY += iEStride;
+    }
+  }
+
+
+  //========== vertical upsampling ===========
+  pcTempPic->setBorderExtension(false);
+  pcTempPic->setHeight(iBHeight);
+  pcTempPic->extendPicBorder   (); // extend the border.
+  pcTempPic->setHeight(iEHeight);
+
+  const Int nShift = US_FILTER_PREC*2;
+  Int iOffset = 1 << (nShift - 1); 
+
+  for( j = 0; j < iEHeight; j++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((j*iScaleY + iAddY) >> iShiftYM4) - iDeltaY;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 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))*iEStride;
+    piDstY = piDstBufY + j * iEStride;
+
+    for( i = 0; i < iEWidth; i++ )
+    {
+      *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, iEStride) + iOffset) >> (nShift));
+      piSrcY++;
+      piDstY++;
+    }
+  }
+
+  //========== UV component upsampling ===========
+
+  iEWidth  >>= 1;
+  iEHeight >>= 1;
+
+  iBWidth  >>= 1;
+  iBHeight >>= 1;
+
+  iBStride  = pcBasePic->getCStride();
+  iEStride  = pcUsPic->getCStride();
+
+#if PHASE_DERIVATION_IN_INTEGER
+  iShiftX = 16;
+  iShiftY = 16;
+
+  iPhaseX = 0;
+  iPhaseY = 1;
+
+  iAddX       = ( ( ( iBWidth * iPhaseX ) << ( iShiftX - 2 ) ) + ( iEWidth >> 1 ) ) / iEWidth + ( 1 << ( iShiftX - 5 ) );
+  iAddY       = ( ( ( iBHeight * iPhaseY ) << ( iShiftY - 2 ) ) + ( iEHeight >> 1 ) ) / iEHeight+ ( 1 << ( iShiftY - 5 ) );
+
+  iDeltaX     = 4 * iPhaseX;
+  iDeltaY     = 4 * iPhaseY;
+
+  iShiftXM4 = iShiftX - 4;
+  iShiftYM4 = iShiftY - 4;
+
+  iScaleX     = ( ( iBWidth << iShiftX ) + ( iEWidth >> 1 ) ) / iEWidth;
+  iScaleY     = ( ( iBHeight << iShiftY ) + ( iEHeight >> 1 ) ) / iEHeight;
+#endif
+
+  //========== horizontal upsampling ===========
+  for( i = 0; i < iEWidth; i++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((i*iScaleX + iAddX) >> iShiftXM4) - iDeltaX;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 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 < iBHeight ; j++ )
+    {
+      *piDstU = sumChromaHor(piSrcU, coeff);
+      *piDstV = sumChromaHor(piSrcV, coeff);
+
+      piSrcU += iBStride;
+      piSrcV += iBStride;
+      piDstU += iEStride;
+      piDstV += iEStride;
+    }
+  }
+
+  //========== vertical upsampling ===========
+  pcTempPic->setBorderExtension(false);
+  pcTempPic->setHeight(iBHeight << 1);
+  pcTempPic->extendPicBorder   (); // extend the border.
+  pcTempPic->setHeight(iEHeight << 1);
+
+  for( j = 0; j < iEHeight; j++ )
+  {
+#if PHASE_DERIVATION_IN_INTEGER
+    iRefPos16 = ((j*iScaleY + iAddY) >> iShiftYM4) - iDeltaY;
+    phase    = iRefPos16 & 15;
+    refPos   = iRefPos16 >> 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))*iEStride;
+    piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*iEStride;
+
+    piDstU = piDstBufU + j*iEStride;
+    piDstV = piDstBufV + j*iEStride;
+
+    for( i = 0; i < iEWidth; i++ )
+    {
+      *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, iEStride) + iOffset) >> (nShift));
+      *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, iEStride) + iOffset) >> (nShift));
+
+      piSrcU++;
+      piSrcV++;
+      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()+pcBasePic->getPicCropRightOffset());
+  }
+  if( tempBufSizeBottom )
+  {
+    pcBasePic->setHeight(pcBasePic->getHeight()+pcBasePic->getPicCropBottomOffset());
+  }
+  
+  iBWidth   = pcBasePic->getWidth () - pcBasePic->getPicCropLeftOffset() - pcBasePic->getPicCropRightOffset();
+  iBHeight  = pcBasePic->getHeight() - pcBasePic->getPicCropTopOffset() - pcBasePic->getPicCropBottomOffset();
+  
+  iBStride  = pcBasePic->getStride();
+  
+  if( tempBufSizeRight )
+  {
+    piSrcY = tempBufRight;
+    piDstY = piSrcBufY + iBWidth;
+    
+    for( i = 0; i < pcBasePic->getHeight(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getPicCropRightOffset());
+      piSrcY += pcBasePic->getPicCropRightOffset();
+      piDstY += iBStride;
+    }
+    
+    if(pcBasePic->getPicCropRightOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = tempBufRight + pcBasePic->getPicCropRightOffset() * pcBasePic->getHeight();
+      piDstU = piSrcBufU + (iBWidth>>1);
+      piSrcV = piSrcU + (pcBasePic->getPicCropRightOffset()>>1) * (pcBasePic->getHeight()>>1);
+      piDstV = piSrcBufV + (iBWidth>>1);
+
+      for( i = 0; i < pcBasePic->getHeight()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcU += (pcBasePic->getPicCropRightOffset()>>1);
+        piDstU += iBStrideChroma;
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getPicCropRightOffset()>>1));
+        piSrcV += (pcBasePic->getPicCropRightOffset()>>1);
+        piDstV += iBStrideChroma;
+      }
+    }
+  }
+  
+  if( tempBufSizeBottom )
+  {
+    piDstY = piSrcBufY + iBHeight * iBStride;
+    piSrcY = tempBufBottom;
+    for( i = 0; i < pcBasePic->getPicCropBottomOffset(); i++ )
+    {
+      memcpy(piDstY, piSrcY, sizeof(Pel) * pcBasePic->getWidth());
+      piDstY += iBStride;
+      piSrcY += pcBasePic->getWidth();
+    }
+    
+    if(pcBasePic->getPicCropBottomOffset()>>1)
+    {
+      Int iBStrideChroma = (iBStride>>1);
+      piSrcU = tempBufBottom + pcBasePic->getPicCropBottomOffset() * pcBasePic->getWidth();
+      piDstU = piSrcBufU + (iBHeight>>1) * iBStrideChroma;
+      piSrcV = piSrcU + (pcBasePic->getPicCropBottomOffset()>>1) * (pcBasePic->getWidth()>>1);
+      piDstV = piSrcBufV + (iBHeight>>1) * iBStrideChroma;
+            
+      for( i = 0; i < pcBasePic->getPicCropBottomOffset()>>1; i++ )
+      {
+        memcpy(piDstU, piSrcU, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcU += (pcBasePic->getWidth()>>1);
+        piDstU += iBStrideChroma;
+        
+        memcpy(piDstV, piSrcV, sizeof(Pel) * (pcBasePic->getWidth()>>1));
+        piSrcV += (pcBasePic->getWidth()>>1);
+        piDstV += iBStrideChroma;
+      }
+    }
+  
+  }
+
+  if( tempBufSizeRight )
+  {
+    xFree( tempBufRight );
+  }
+  if( tempBufSizeBottom )
+  {
+    xFree( tempBufBottom );
+  }
+#endif
+}
+#endif //SVC_EXTENSION
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 54)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 54)
@@ -0,0 +1,57 @@
+#ifndef __TCOMUPSAMPLEFILTER__
+#define __TCOMUPSAMPLEFILTER__
+
+#include "TComPic.h"
+#include "TComYuv.h"
+#include "TComDataCU.h"
+
+#define NTAPS_US_LUMA        8 ///< Number of taps for luma upsampling filter
+#define NTAPS_US_CHROMA      4 ///< Number of taps for chroma upsampling filter
+#define US_FILTER_PREC       6 ///< Log2 of sum of filter taps
+
+class TComUpsampleFilter
+{
+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
+
+  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 )
+  {
+    return ( pel[0]*coeff[0] + pel[1]*coeff[1] + pel[2]*coeff[2] + pel[3]*coeff[3] + pel[4]*coeff[4] + pel[5]*coeff[5] + pel[6]*coeff[6] + pel[7]*coeff[7]);
+  }
+
+  static inline Int sumChromaHor( Pel* pel, Int* coeff )
+  {
+    return ( pel[0]*coeff[0] + pel[1]*coeff[1] + pel[2]*coeff[2] + pel[3]*coeff[3] );
+  }
+
+  static inline Int sumLumaVer( Pel* pel, Int* coeff, Int stride )
+  {
+    return ( pel[0]*coeff[0] + pel[stride]*coeff[1] + pel[2*stride]*coeff[2] + pel[3*stride]*coeff[3] + pel[4*stride]*coeff[4] + pel[5*stride]*coeff[5] + pel[6*stride]*coeff[6] + pel[7*stride]*coeff[7]);
+  }
+
+  static inline Int sumChromaVer( Pel* pel, Int* coeff, Int stride )
+  {
+    return ( pel[0]*coeff[0] + pel[stride]*coeff[1] + pel[2*stride]*coeff[2] + pel[3*stride]*coeff[3] );
+  }
+
+public:
+  TComUpsampleFilter(void);
+  ~TComUpsampleFilter(void);
+
+ Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+};
+
+#endif //__TCOMUPSAMPLEFILTER__
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.cpp	(revision 54)
@@ -184,4 +184,57 @@
 }
 
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+Void TComYuv::copyFromPicLuma  ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiWidth, UInt uiHeight )
+{
+  Int  y;
+
+  Pel* pDst     = getLumaAddr(uiAbsZorderIdx);
+  Pel* pSrc     = pcPicYuvSrc->getLumaAddr ( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+  UInt  iDstStride  = getStride();
+  UInt  iSrcStride  = pcPicYuvSrc->getStride();
+  for ( y = uiHeight; y != 0; y-- )
+  {
+    ::memcpy( pDst, pSrc, sizeof(Pel)*uiWidth);
+    pDst += iDstStride;
+    pSrc += iSrcStride;
+  }
+}
+
+Void TComYuv::copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId  )
+{
+  Int  y;
+
+  if (!uiChromaId)
+  {
+    Pel* pDstU      = getCbAddr(uiAbsZorderIdx); 
+    Pel* pSrcU      = pcPicYuvSrc->getCbAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+    UInt  iDstStride = getCStride();
+    UInt  iSrcStride = pcPicYuvSrc->getCStride();
+    for ( y = uiCHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstU, pSrcU, sizeof(Pel)*(uiCWidth) );
+      pSrcU += iSrcStride;
+      pDstU += iDstStride;
+    }
+  }
+  else
+  {
+    Pel* pDstV      = getCrAddr(uiAbsZorderIdx);
+    Pel* pSrcV      = pcPicYuvSrc->getCrAddr( iCuAddr, uiZorderIdxInCU + uiAbsZorderIdx );
+
+    UInt  iDstStride = getCStride();
+    UInt  iSrcStride = pcPicYuvSrc->getCStride();
+    for ( y = uiCHeight; y != 0; y-- )
+    {
+      ::memcpy( pDstV, pSrcV, sizeof(Pel)*(uiCWidth) );
+      pSrcV += iSrcStride;
+      pDstV += iDstStride;
+    }
+  }
+}
+#endif
+
 Void TComYuv::copyToPartYuv( TComYuv* pcYuvDst, UInt uiDstPartIdx )
 {
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TComYuv.h	(revision 54)
@@ -115,4 +115,8 @@
   Void    copyFromPicLuma      ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
   Void    copyFromPicChroma    ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiAbsZorderIdx );
+#if NO_RESIDUAL_FLAG_FOR_BLPRED
+  Void    copyFromPicLuma  ( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiWidth, UInt uiHeight );
+  Void    copyFromPicChroma( TComPicYuv* pcPicYuvSrc, UInt iCuAddr, UInt uiZorderIdxInCU, UInt uiAbsZorderIdx, UInt uiCWidth, UInt uiCHeight, UInt uiChromaId  );
+#endif
   
   //  Copy Small YUV buffer to the part of other Big YUV buffer
Index: branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 51)
+++ branches/HM-10.0-dev-SHM/source/Lib/TLibCommon/TypeDef.h	(revision 54)
@@ -38,4 +38,68 @@
 #ifndef _TYPEDEF__
 #define _TYPEDEF__
+
+#define SVC_EXTENSION                    1
+
+#define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
+
+#if SVC_EXTENSION
+#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+
+#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 SET_SLICE_LAYER_ID               1      ///< set layerId to the slice
+#define BUGFIX_925                       1      ///< bug fix ticket #925
+#define ENCODER_BUGFIX                   1      ///< L0167: encoder bug fix for inter mode
+#define CHROMA_UPSAMPLING                1      ///< L0335: Chroma upsampling with 5 bits coefficients
+
+#define MV_SCALING_FIX                   1      ///< fixing the base layer MV scaling
+#define MV_SCALING_POS_FIX               1      ///< use center pixels to get co-located base layer block
+#define MFM_CLIPPING_FIX                 1      ///< set the right picture size for the clipping
+
+#define AVC_BASE                         0      ///< YUV BL reading for AVC base SVC
+#define REF_IDX_FRAMEWORK                0      ///< inter-layer reference framework
+
+#if AVC_BASE
+#define AVC_SYNTAX                       1      ///< Syntax reading for AVC base
+#endif
+
+#if REF_IDX_FRAMEWORK
+#define REF_IDX_ME_AROUND_ZEROMV         0      ///< added ME around zero MV for inter-layer reference picture
+#define REF_IDX_ME_ZEROMV                1      ///< L0051: use zero motion for inter-layer reference picture (without fractional ME)
+#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.
+#if !AVC_BASE || AVC_SYNTAX
+#define REF_IDX_MFM                      1      ///< L0336: motion vector mapping of inter-layer reference picture
+#endif
+
+#if REF_IDX_MFM
+#define REUSE_MVSCALE                    1      ///< using the base layer MV scaling function
+#define REUSE_BLKMAPPING                 1      ///< using the base layer get co-located block function
+#endif
+
+#else
+#define INTRA_BL                         0      ///< inter-layer texture prediction
+
+#if INTRA_BL
+#define INTRA_BL_DST4x4                  1      ///< L0067/L0204: DST4x4 for Intra BL
+#define NO_RESIDUAL_FLAG_FOR_BLPRED      1      ///< L0437: Root cbf for Intra_BL
+
+// Hooks
+#if !AVC_BASE || AVC_SYNTAX
+#define SVC_MVP                          1      ///< motion hook for merge mode as an example
+#if !AVC_SYNTAX
+#define SVC_BL_CAND_INTRA                0      ///< Intra Base Mode Prediction hook as an example 
+#endif
+#endif
+
+#if SVC_UPSAMPLING
+#define JCTVC_L0178                      1      ///< implementation of JCTVC-L0178 (code only supports right and bottom croppping offsets)
+#endif
+
+#endif
+#endif
+#else
+#define SYNTAX_OUTPUT                    0
+#endif
 
 //! \ingroup TLibCommon
