Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 55)
@@ -56,5 +56,5 @@
 // ====================================================================================================================
 
-#define NV_VERSION        "1.0"                 ///< Current software version
+#define NV_VERSION        "1.1"                 ///< Current software version
 
 // ====================================================================================================================
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 55)
@@ -383,5 +383,4 @@
   m_layerId          = pcPic->getLayerId();
 #endif 
-
   for(int i=0; i<pcPic->getNumPartInCU(); i++) 
   {
@@ -2906,8 +2905,12 @@
   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
@@ -4843,5 +4846,5 @@
 }
 
-#if INTRA_BL 
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED 
 Void TComDataCU::getBaseLumaBlk ( UInt uiWidth, UInt uiHeight, UInt uiAbsPartIdx, Pel* piPred, UInt uiStride )
 {
@@ -4883,4 +4886,10 @@
 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();
 
@@ -4927,23 +4936,82 @@
 
   return cBaseColPic->getCU(uiCUAddrBase);
+#endif
+}
+
+TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+  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
+
+  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;
-
-   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();
-
-   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() );
+  TComMvField cMvFieldBase;
+  TComMv cMv;
+
+#if MV_SCALING_FIX
+  Int iBWidth   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - m_pcSlice->getBaseColPic()->getPicYuvRec()->getPicCropLeftOffset() - m_pcSlice->getBaseColPic()->getPicYuvRec()->getPicCropRightOffset();
+  Int iBHeight  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - m_pcSlice->getBaseColPic()->getPicYuvRec()->getPicCropTopOffset() - m_pcSlice->getBaseColPic()->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   = 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
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 55)
@@ -526,5 +526,5 @@
   // -------------------------------------------------------------------------------------------------------------------
   
-#if INTRA_BL
+#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 );
@@ -593,4 +593,5 @@
 #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: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 55)
@@ -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 )
   {
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 55)
@@ -66,4 +66,5 @@
 , m_SEIs                                  (NULL)
 #if SVC_EXTENSION
+, m_layerId( 0 )
 , m_bSpatialEnhLayer( false )
 , m_pcFullPelBaseRec( NULL )
@@ -96,4 +97,6 @@
     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 */
@@ -557,4 +560,5 @@
 
 #if REF_IDX_MFM
+#if !REUSE_BLKMAPPING
 Void TComPic::deriveUnitIdxBase( UInt uiUpsamplePelX, UInt uiUpsamplePelY, UInt ratio, UInt& uiBaseCUAddr, UInt& uiBaseAbsPartIdx )
 {
@@ -565,10 +569,16 @@
   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;
@@ -585,7 +595,9 @@
   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();
@@ -593,5 +605,7 @@
   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)
@@ -611,14 +625,14 @@
     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
   {
-    UInt uiNumPartitions   = 1<<(g_uiMaxCUDepth<<1);
-
     TComDataCU*             pcCUDes = getCU(cuIdx);
-
-    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 uiAbsPartIdx = 0; uiAbsPartIdx < uiNumPartitions; uiAbsPartIdx+=unitNum )  //each 16x16 unit
@@ -628,11 +642,42 @@
       UInt  uiPelY = pcCUDes->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
       UInt uiBaseCUAddr, uiBaseAbsPartIdx;
-         pcPicBase->deriveUnitIdxBase(uiPelX + 8, uiPelY + 8, upSampleRatio, 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
-      {
-        for(UInt list = 0; list < 2; list++)  //each list
-        { 
-          TComMv cMv = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)list)->getMv(uiBaseAbsPartIdx);
-          Int refIdx = pcPicBase->getCU(uiBaseCUAddr)->getCUMvField((RefPicList)list)->getRefIdx(uiBaseAbsPartIdx);
+#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 ;
@@ -642,6 +687,7 @@
           TComMvField sMvField;
           sMvField.setMvField(cScaledMv, refIdx);
-
-          pcCUDes->getCUMvField((RefPicList)list)->setMvField(sMvField, uiAbsPartIdx);
+#endif
+
+          pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, uiAbsPartIdx);
           pcCUDes->setPredictionMode(uiAbsPartIdx, MODE_INTER);
         }
@@ -669,3 +715,155 @@
 #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: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 55)
@@ -44,4 +44,8 @@
 #include "TComPicYuv.h"
 #include "TComBitStream.h"
+#if AVC_BASE || SYNTAX_OUTPUT
+#include <fstream>
+#endif
+
 
 //! \ingroup TLibCommon
@@ -125,5 +129,7 @@
 #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
 
@@ -209,4 +215,11 @@
   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
 
@@ -214,2 +227,3 @@
 
 #endif // __TCOMPIC__
+
Index: trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 55)
@@ -125,4 +125,10 @@
   UInt        getNumberOfCUsInFrame()   { return m_uiNumCUsInFrame;  }
   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;           }
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 55)
@@ -407,5 +407,5 @@
 }
 
-#if INTRA_BL
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
 Void TComPrediction::getBaseBlk( TComDataCU* pcCU, TComYuv* pcYuvPred, Int iPartAddr, Int iWidth, Int iHeight )
 {
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 55)
@@ -562,4 +562,8 @@
   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++) 
@@ -2191,3 +2195,49 @@
 }
 #endif
+
+#if SVC_EXTENSION && 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
+
 //! \}
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 55)
@@ -1454,4 +1454,8 @@
   Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
   TComPicYuv* getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+
+#if AVC_SYNTAX
+  Void      initBaseLayerRPL( TComSlice *pcSlice );
+#endif
 #endif
 
Index: trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 33)
+++ trunk/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 55)
@@ -227,6 +227,4 @@
 #endif
 
-
-
   assert ( iEWidth == 2*iBWidth || 2*iEWidth == 3*iBWidth );
   assert ( iEHeight == 2*iBHeight || 2*iEHeight == 3*iBHeight );
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 33)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 55)
@@ -40,4 +40,7 @@
 
 #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
@@ -49,10 +52,16 @@
 #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 AVC_BASE                         0      ///< YUV BL reading for AVC base SVC
-
+#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                         1      ///< 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
@@ -60,5 +69,13 @@
 #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                         1      ///< inter-layer texture prediction
@@ -69,6 +86,7 @@
 
 // Hooks
-#if !AVC_BASE
+#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
@@ -80,4 +98,7 @@
 
 #endif
+#endif
+#else
+#define SYNTAX_OUTPUT                    1
 #endif
 
Index: trunk/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 33)
+++ trunk/source/Lib/TLibDecoder/TDecCu.cpp	(revision 55)
@@ -546,5 +546,5 @@
   
   //===== get prediction signal =====
-#if INTRA_BL
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
   if(pcCU->isIntraBL ( uiAbsPartIdx ) )
   {
@@ -651,5 +651,5 @@
   
   //===== get prediction signal =====
-#if INTRA_BL
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
   if(pcCU->isIntraBL ( uiAbsPartIdx ) )
   {
Index: trunk/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 33)
+++ trunk/source/Lib/TLibDecoder/TDecTop.cpp	(revision 55)
@@ -81,4 +81,7 @@
   memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
 #endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  m_pBLSyntaxFile = NULL;
+#endif
 
 }
@@ -335,4 +338,8 @@
 
   m_cGopDecoder.filterPicture(pcPic);
+
+#if SYNTAX_OUTPUT
+  pcPic->wrireBLSyntax( getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
 
   TComSlice::sortPicList( m_cListPic ); // sorting for application output
@@ -554,16 +561,17 @@
   if (m_bFirstSliceInPicture)
   {
-
 #if AVC_BASE
   if( m_layerId == 1 )
   {
     TComPic* pBLPic = (*m_ppcTDecTop[0]->getListPic()->begin());
-    FILE* pFile = m_ppcTDecTop[0]->getBLReconFile();
-    UInt uiWidth = pBLPic->getPicYuvRec()->getWidth();
-    UInt uiHeight = pBLPic->getPicYuvRec()->getHeight();
+    fstream* pFile  = m_ppcTDecTop[0]->getBLReconFile();
+    UInt uiWidth    = pBLPic->getPicYuvRec()->getWidth() - pBLPic->getPicYuvRec()->getPicCropLeftOffset() - pBLPic->getPicYuvRec()->getPicCropRightOffset();;
+    UInt uiHeight   = pBLPic->getPicYuvRec()->getHeight() - pBLPic->getPicYuvRec()->getPicCropTopOffset() - pBLPic->getPicYuvRec()->getPicCropBottomOffset();
         
-    if( pFile )
-    {
-      fseek( pFile, m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2, SEEK_SET );
+    if( pFile->good() )
+    {
+      UInt64 uiPos = (UInt64) m_apcSlicePilot->getPOC() * uiWidth * uiHeight * 3 / 2;
+
+      pFile->seekg((UInt)uiPos, ios::beg );
 
       Pel* pPel = pBLPic->getPicYuvRec()->getLumaAddr();
@@ -573,5 +581,5 @@
         for( Int j = 0; j < uiWidth; j++ )
         {
-          pPel[j] = fgetc( pFile );
+          pPel[j] = pFile->get();
         }
         pPel += uiStride;
@@ -584,5 +592,5 @@
         for( Int j = 0; j < uiWidth/2; j++ )
         {
-          pPel[j] = fgetc( pFile );
+          pPel[j] = pFile->get();
         }
         pPel += uiStride;
@@ -595,5 +603,5 @@
         for( Int j = 0; j < uiWidth/2; j++ )
         {
-          pPel[j] = fgetc( pFile );
+          pPel[j] = pFile->get();
         }
         pPel += uiStride;
@@ -737,5 +745,5 @@
   {
     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic);
-#if !REF_IDX_FRAMEWORK
+#if !REF_IDX_FRAMEWORK || AVC_SYNTAX
     // Set reference list
     pcSlice->setRefPicList( m_cListPic );
@@ -747,4 +755,17 @@
 #if AVC_BASE
       pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
+#if AVC_SYNTAX
+      TComPic* pBLPic = pcSlice->getBaseColPic();
+      if( pcSlice->getPOC() == 0 )
+      {
+        // initialize partition order.
+        UInt* piTmp = &g_auiZscanToRaster[0];
+        initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
+        initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
+      }      
+      pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
+      pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+
 #else
       TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
@@ -767,6 +788,8 @@
 
 #if REF_IDX_FRAMEWORK
+#if !AVC_SYNTAX
     // Set reference list
     pcSlice->setRefPicList( m_cListPic );
+#endif
     if(m_layerId > 0)
     {
@@ -979,5 +1002,10 @@
         {
 #if SVC_UPSAMPLING
+#if AVC_SYNTAX
+          TComSPS* sps = new TComSPS();
+          pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, sps, true);
+#else
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, NULL, true);
+#endif
 #else
           pBLPic->create( m_ppcTDecTop[0]->getBLWidth(), m_ppcTDecTop[0]->getBLHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, true);
Index: trunk/source/Lib/TLibDecoder/TDecTop.h
===================================================================
--- trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 33)
+++ trunk/source/Lib/TLibDecoder/TDecTop.h	(revision 55)
@@ -127,9 +127,12 @@
   TDecTop**               m_ppcTDecTop;
 #if AVC_BASE
-  FILE*                   m_pBLReconFile;
+  fstream*                m_pBLReconFile;
   Int                     m_iBLSourceWidth;
   Int                     m_iBLSourceHeight;
 #endif
 #endif 
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  fstream*               m_pBLSyntaxFile;
+#endif
 #if REF_IDX_FRAMEWORK
   TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture 
@@ -165,10 +168,14 @@
   TDecTop*            getLayerDec(UInt layer)   { return m_ppcTDecTop[layer]; }
 #if AVC_BASE
-  Void      setBLReconFile( FILE* pFile ) { m_pBLReconFile = pFile; }
-  FILE*     getBLReconFile() { return m_pBLReconFile; }
+  Void      setBLReconFile( fstream* pFile ) { m_pBLReconFile = pFile; }
+  fstream*  getBLReconFile() { return m_pBLReconFile; }
   Void      setBLsize( Int iWidth, Int iHeight ) { m_iBLSourceWidth = iWidth; m_iBLSourceHeight = iHeight; }
   Int       getBLWidth() { return  m_iBLSourceWidth; }
   Int       getBLHeight() { return  m_iBLSourceHeight; }
 #endif
+#endif
+#if AVC_SYNTAX || SYNTAX_OUTPUT
+  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
+  fstream* getBLSyntaxFile() { return m_pBLSyntaxFile; }
 #endif
 #if REF_IDX_FRAMEWORK
Index: trunk/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 33)
+++ trunk/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 55)
@@ -337,12 +337,16 @@
     pcSlice->setNalUnitType(getNalUnitType(uiPOCCurr));
 #if REF_IDX_FRAMEWORK
-    if (m_layerId > 0 && (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0))
+    if( m_layerId > 0 && (uiPOCCurr % m_pcCfg->getIntraPeriod() == 0) )
+    {
       pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
+    }
     if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
     {
       if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA) &&
           (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
-           pcSlice->getSliceType() == B_SLICE ) 
+           pcSlice->getSliceType() == B_SLICE )
+      {
         pcSlice->setSliceType(P_SLICE);
+      }
     }
 #endif
@@ -466,6 +470,8 @@
 
 #if REF_IDX_FRAMEWORK
-    if (pcSlice->getSliceType() == B_SLICE) 
+    if( pcSlice->getSliceType() == B_SLICE )
+    {
       pcSlice->setColFromL0Flag(1-uiColDir);
+    }
 #endif
 
@@ -774,4 +780,7 @@
     {
       pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() );
+#if AVC_SYNTAX
+      pcPic->readBLSyntax( m_ppcTEncTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
       return;
     }
Index: trunk/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 33)
+++ trunk/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 55)
@@ -1057,5 +1057,5 @@
     pcCU->getPattern()->initAdiPattern( pcCU, uiAbsPartIdx, uiTrDepth, m_piYuvExt, m_iYuvExtStride, m_iYuvExtHeight, bAboveAvail, bLeftAvail );
     //===== get prediction signal =====
-#if INTRA_BL
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
     if(pcCU->isIntraBL ( uiAbsPartIdx ) )
     {
@@ -1259,5 +1259,5 @@
 
     //===== get prediction signal =====
-#if INTRA_BL
+#if INTRA_BL && !NO_RESIDUAL_FLAG_FOR_BLPRED
   if(pcCU->isIntraBL ( uiAbsPartIdx ) )
   {
Index: trunk/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 33)
+++ trunk/source/Lib/TLibEncoder/TEncTop.h	(revision 55)
@@ -77,4 +77,7 @@
   static Int              m_iSPSIdCnt;                    ///< next Id number for SPS    
   static Int              m_iPPSIdCnt;                    ///< next Id number for PPS    
+#if AVC_SYNTAX
+  fstream*                m_pBLSyntaxFile;
+#endif
 #endif
   
@@ -223,4 +226,8 @@
 
   Void encodePrep( bool bEos, TComPicYuv* pcPicYuvOrg );
+#if AVC_SYNTAX
+  Void      setBLSyntaxFile( fstream* pFile ) { m_pBLSyntaxFile = pFile; }
+  fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
+#endif
 #else
   Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
