Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/CommonDef.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/CommonDef.h	(revision 466)
@@ -130,5 +130,14 @@
 extern Int g_bitDepthY;
 extern Int g_bitDepthC;
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+extern Int  g_bitDepthYLayer[MAX_LAYERS];
+extern Int  g_bitDepthCLayer[MAX_LAYERS];
+
+extern UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+extern UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+extern void* g_refWeightACDCParam; //type:wpACDCParam
+#endif
 /** clip x, such that 0 <= x <= #g_maxLumaVal */
 template <typename T> inline T ClipY(T x) { return std::min<T>(T((1 << g_bitDepthY)-1), std::max<T>( T(0), x)); }
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 466)
@@ -4004,12 +4004,15 @@
   uiPelY = (UInt)Clip3<UInt>(0, m_pcPic->getPicYuvRec()->getHeight() - 1, uiPelY);
 
-#if !LAYER_CTB
   UInt uiMinUnitSize = m_pcPic->getMinCUWidth();
-#endif
-
+
+#if SCALED_REF_LAYER_OFFSETS
   Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowLeftOffset();
   Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow(refLayerIdc).getWindowTopOffset();
   Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
   Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
+#else
+  Int iBX = (uiPelX*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
+  Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
+#endif
 
 #if N0139_POSITION_ROUNDING_OFFSET
@@ -4021,32 +4024,22 @@
 #endif
 
+#if SCALED_REF_LAYER_OFFSETS
   if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight() ||
        iBX < 0                                        || iBY < 0                                           )
+#else
+  if ( iBX >= cBaseColPic->getPicYuvRec()->getWidth() || iBY >= cBaseColPic->getPicYuvRec()->getHeight())
+#endif
   {
     return NULL;
   }
 
-#if LAYER_CTB
-  UInt baseMaxCUHeight = cBaseColPic->getPicSym()->getMaxCUHeight();
-  UInt baseMaxCUWidth  = cBaseColPic->getPicSym()->getMaxCUWidth();
-  UInt baseMinUnitSize = cBaseColPic->getMinCUWidth();
-  
-  uiCUAddrBase = ( iBY / cBaseColPic->getPicSym()->getMaxCUHeight() ) * cBaseColPic->getFrameWidthInCU() + ( iBX / cBaseColPic->getPicSym()->getMaxCUWidth() );
-#else
   uiCUAddrBase = (iBY/g_uiMaxCUHeight)*cBaseColPic->getFrameWidthInCU() + (iBX/g_uiMaxCUWidth);
-#endif
 
   assert(uiCUAddrBase < cBaseColPic->getNumCUsInFrame());
 
-#if LAYER_CTB
-  UInt uiRasterAddrBase = ( iBY - (iBY/baseMaxCUHeight)*baseMaxCUHeight ) / baseMinUnitSize * cBaseColPic->getNumPartInWidth() + ( iBX - (iBX/baseMaxCUWidth)*baseMaxCUWidth ) / baseMinUnitSize;
-  
-  uiAbsPartIdxBase = g_auiLayerRasterToZscan[cBaseColPic->getLayerId()][uiRasterAddrBase];
-#else
   UInt uiRasterAddrBase = (iBY - (iBY/g_uiMaxCUHeight)*g_uiMaxCUHeight)/uiMinUnitSize*cBaseColPic->getNumPartInWidth()
     + (iBX - (iBX/g_uiMaxCUWidth)*g_uiMaxCUWidth)/uiMinUnitSize;
 
   uiAbsPartIdxBase = g_auiRasterToZscan[uiRasterAddrBase];
-#endif
 
   return cBaseColPic->getCU(uiCUAddrBase);
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicSym.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicSym.h	(revision 466)
@@ -126,9 +126,4 @@
   TComDataCU*&  getCU( UInt uiCUAddr )  { return m_apcTComDataCU[uiCUAddr];     }
   
-#if LAYER_CTB
-  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
-  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
-#endif
-
 #if AVC_SYNTAX
   UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 466)
@@ -90,11 +90,6 @@
   Int numCuInHeight = m_iPicHeight / m_iCuHeight + (m_iPicHeight % m_iCuHeight != 0);
   
-#if LAYER_CTB
-  m_iLumaMarginX    = uiMaxCUWidth  + 16; // for 16-byte alignment
-  m_iLumaMarginY    = uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
-#else
   m_iLumaMarginX    = g_uiMaxCUWidth  + 16; // for 16-byte alignment
   m_iLumaMarginY    = g_uiMaxCUHeight + 16;  // margin for 8-tap filter and infinite padding
-#endif
   
   m_iChromaMarginX  = m_iLumaMarginX>>1;
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRdCost.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRdCost.cpp	(revision 466)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -61,5 +61,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -80,5 +80,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -107,5 +107,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -115,5 +115,5 @@
   Double dRdCost = 0.0;
   Double dLambda = 0.0;
-  
+
   switch ( eDFunc )
   {
@@ -134,5 +134,5 @@
       break;
   }
-  
+
   if (bFlag)
   {
@@ -161,5 +161,5 @@
     }
   }
-  
+
   return dRdCost;
 }
@@ -178,5 +178,5 @@
 {
   m_afpDistortFunc[0]  = NULL;                  // for DF_DEFAULT
-  
+
   m_afpDistortFunc[1]  = TComRdCost::xGetSSE;
   m_afpDistortFunc[2]  = TComRdCost::xGetSSE4;
@@ -186,5 +186,5 @@
   m_afpDistortFunc[6]  = TComRdCost::xGetSSE64;
   m_afpDistortFunc[7]  = TComRdCost::xGetSSE16N;
-  
+
   m_afpDistortFunc[8]  = TComRdCost::xGetSAD;
   m_afpDistortFunc[9]  = TComRdCost::xGetSAD4;
@@ -194,5 +194,5 @@
   m_afpDistortFunc[13] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[14] = TComRdCost::xGetSAD16N;
-  
+
   m_afpDistortFunc[15] = TComRdCost::xGetSAD;
   m_afpDistortFunc[16] = TComRdCost::xGetSAD4;
@@ -202,5 +202,5 @@
   m_afpDistortFunc[20] = TComRdCost::xGetSAD64;
   m_afpDistortFunc[21] = TComRdCost::xGetSAD16N;
-  
+
 #if AMP_SAD
   m_afpDistortFunc[43] = TComRdCost::xGetSAD12;
@@ -219,5 +219,5 @@
   m_afpDistortFunc[27] = TComRdCost::xGetHADs;
   m_afpDistortFunc[28] = TComRdCost::xGetHADs;
-  
+
 #if !FIX203
   m_puiComponentCostOriginP = NULL;
@@ -239,16 +239,16 @@
   iSubPelSearchLimit += 4;
   iSubPelSearchLimit *= 8;
-  
+
   if( m_iSearchLimit != iSubPelSearchLimit )
   {
     xUninit();
-    
+
     m_iSearchLimit = iSubPelSearchLimit;
-    
+
     m_puiComponentCostOriginP = new UInt[ 4 * iSubPelSearchLimit ];
     iSubPelSearchLimit *= 2;
-    
+
     m_puiComponentCost = m_puiComponentCostOriginP + iSubPelSearchLimit;
-    
+
     for( Int n = -iSubPelSearchLimit; n < iSubPelSearchLimit; n++)
     {
@@ -272,7 +272,7 @@
   UInt uiLength = 1;
   UInt uiTemp   = ( iVal <= 0) ? (-iVal<<1)+1: (iVal<<1);
-  
+
   assert ( uiTemp );
-  
+
   while ( 1 != uiTemp )
   {
@@ -280,5 +280,5 @@
     uiLength += 2;
   }
-  
+
   return uiLength;
 }
@@ -290,5 +290,5 @@
   rcDistParam.iRows    = uiBlkHeight;
   rcDistParam.DistFunc = m_afpDistortFunc[eDFunc + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -301,13 +301,13 @@
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
   rcDistParam.iRows    = pcPatternKey->getROIYHeight();
   rcDistParam.DistFunc = m_afpDistortFunc[DF_SAD + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
-  
+
 #if AMP_SAD
   if (rcDistParam.iCols == 12)
@@ -336,14 +336,18 @@
 #endif
 {
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Bug fix: The correct bit depth has not been used for weighted cost calculation
+  rcDistParam.bitDepth = g_bitDepthY;
+#endif
   // set Original & Curr Pointer / Stride
   rcDistParam.pOrg = pcPatternKey->getROIY();
   rcDistParam.pCur = piRefY;
-  
+
   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride();
   rcDistParam.iStrideCur = iRefStride * iStep;
-  
+
   // set Step for interpolated buffer
   rcDistParam.iStep = iStep;
-  
+
   // set Block Width / Height
   rcDistParam.iCols    = pcPatternKey->getROIYWidth();
@@ -352,5 +356,5 @@
   rcDistParam.bUseNSHAD = bUseNSHAD;
 #endif
-  
+
   // set distortion function
   if ( !bHADME )
@@ -376,5 +380,5 @@
     rcDistParam.DistFunc = m_afpDistortFunc[DF_HADS + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ];
   }
-  
+
   // initialize
   rcDistParam.iSubShift  = 0;
@@ -407,5 +411,5 @@
   UInt uiSum = 0;
   Int x, y;
-  
+
   if ( ( (iWidth % 8) == 0 ) && ( (iHeight % 8) == 0 ) )
   {
@@ -444,5 +448,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
 
@@ -523,7 +527,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur;
   Int  iStrideOrg = pcDtParam->iStrideOrg;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-- )
   {
@@ -535,5 +539,5 @@
     piCur += iStrideCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -541,5 +545,5 @@
 UInt TComRdCost::xGetSAD4( DistParam* pcDtParam )
 {
-  if ( pcDtParam->bApplyWeight ) 
+  if ( pcDtParam->bApplyWeight )
   {
     return xGetSADw( pcDtParam );
@@ -552,7 +556,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -561,9 +565,9 @@
     uiSum += abs( piOrg[2] - piCur[2] );
     uiSum += abs( piOrg[3] - piCur[3] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -583,7 +587,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -596,9 +600,9 @@
     uiSum += abs( piOrg[6] - piCur[6] );
     uiSum += abs( piOrg[7] - piCur[7] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -618,7 +622,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -639,9 +643,9 @@
     uiSum += abs( piOrg[14] - piCur[14] );
     uiSum += abs( piOrg[15] - piCur[15] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -662,7 +666,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -679,9 +683,9 @@
     uiSum += abs( piOrg[10] - piCur[10] );
     uiSum += abs( piOrg[11] - piCur[11] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -699,7 +703,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -726,5 +730,5 @@
     piCur += iStrideCur;
   }
-  
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -744,7 +748,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -781,9 +785,9 @@
     uiSum += abs( piOrg[30] - piCur[30] );
     uiSum += abs( piOrg[31] - piCur[31] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -804,7 +808,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -833,9 +837,9 @@
     uiSum += abs( piOrg[22] - piCur[22] );
     uiSum += abs( piOrg[23] - piCur[23] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -857,7 +861,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -926,9 +930,9 @@
     uiSum += abs( piOrg[62] - piCur[62] );
     uiSum += abs( piOrg[63] - piCur[63] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -949,7 +953,7 @@
   Int  iStrideCur = pcDtParam->iStrideCur*iSubStep;
   Int  iStrideOrg = pcDtParam->iStrideOrg*iSubStep;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for( ; iRows != 0; iRows-=iSubStep )
   {
@@ -1002,9 +1006,9 @@
     uiSum += abs( piOrg[46] - piCur[46] );
     uiSum += abs( piOrg[47] - piCur[47] );
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   uiSum <<= iSubShift;
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
@@ -1028,10 +1032,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1044,5 +1048,5 @@
     piCur += iStrideCur;
   }
-  
+
   return ( uiSum );
 }
@@ -1060,22 +1064,22 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[0] - piCur[0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[1] - piCur[1]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[2] - piCur[2]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[3] - piCur[3]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1093,10 +1097,10 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1109,9 +1113,9 @@
     iTemp = piOrg[6] - piCur[6]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[7] - piCur[7]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1129,13 +1133,13 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
-  
+
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1154,9 +1158,9 @@
     iTemp = piOrg[14] - piCur[14]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[15] - piCur[15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1174,14 +1178,14 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
     for (Int n = 0; n < iCols; n+=16 )
     {
-      
+
       iTemp = piOrg[n+ 0] - piCur[n+ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+ 1] - piCur[n+ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1200,10 +1204,10 @@
       iTemp = piOrg[n+14] - piCur[n+14]; uiSum += ( iTemp * iTemp ) >> uiShift;
       iTemp = piOrg[n+15] - piCur[n+15]; uiSum += ( iTemp * iTemp ) >> uiShift;
-      
-    }
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    }
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1221,12 +1225,12 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
-    
+
     iTemp = piOrg[ 0] - piCur[ 0]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[ 1] - piCur[ 1]; uiSum += ( iTemp * iTemp ) >> uiShift;
@@ -1261,9 +1265,9 @@
     iTemp = piOrg[30] - piCur[30]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[31] - piCur[31]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1281,9 +1285,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStrideCur = pcDtParam->iStrideCur;
-  
+
   UInt uiSum = 0;
   UInt uiShift = DISTORTION_PRECISION_ADJUSTMENT((pcDtParam->bitDepth-8) << 1);
   Int  iTemp;
-  
+
   for( ; iRows != 0; iRows-- )
   {
@@ -1352,9 +1356,9 @@
     iTemp = piOrg[62] - piCur[62]; uiSum += ( iTemp * iTemp ) >> uiShift;
     iTemp = piOrg[63] - piCur[63]; uiSum += ( iTemp * iTemp ) >> uiShift;
-    
-    piOrg += iStrideOrg;
-    piCur += iStrideCur;
-  }
-  
+
+    piOrg += iStrideOrg;
+    piCur += iStrideCur;
+  }
+
   return ( uiSum );
 }
@@ -1376,10 +1380,10 @@
   m[2] = diff[0] - diff[2];
   m[3] = diff[1] - diff[3];
-  
+
   satd += abs(m[0] + m[1]);
   satd += abs(m[0] - m[1]);
   satd += abs(m[2] + m[3]);
   satd += abs(m[2] - m[3]);
-  
+
   return satd;
 }
@@ -1388,5 +1392,5 @@
 {
   Int k, satd = 0, diff[16], m[16], d[16];
-  
+
   assert( iStep == 1 );
   for( k = 0; k < 16; k+=4 )
@@ -1396,9 +1400,9 @@
     diff[k+2] = piOrg[2] - piCur[2];
     diff[k+3] = piOrg[3] - piCur[3];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   /*===== hadamard transform =====*/
   m[ 0] = diff[ 0] + diff[12];
@@ -1418,5 +1422,5 @@
   m[14] = diff[ 2] - diff[14];
   m[15] = diff[ 3] - diff[15];
-  
+
   d[ 0] = m[ 0] + m[ 4];
   d[ 1] = m[ 1] + m[ 5];
@@ -1435,5 +1439,5 @@
   d[14] = m[14] - m[10];
   d[15] = m[15] - m[11];
-  
+
   m[ 0] = d[ 0] + d[ 3];
   m[ 1] = d[ 1] + d[ 2];
@@ -1452,5 +1456,5 @@
   m[14] = d[13] - d[14];
   m[15] = d[12] - d[15];
-  
+
   d[ 0] = m[ 0] + m[ 1];
   d[ 1] = m[ 0] - m[ 1];
@@ -1469,5 +1473,5 @@
   d[14] = m[14] + m[15];
   d[15] = m[15] - m[14];
-  
+
   for (k=0; k<16; ++k)
   {
@@ -1475,5 +1479,5 @@
   }
   satd = ((satd+1)>>1);
-  
+
   return satd;
 }
@@ -1494,9 +1498,9 @@
     diff[k+6] = piOrg[6] - piCur[6];
     diff[k+7] = piOrg[7] - piCur[7];
-    
-    piCur += iStrideCur;
-    piOrg += iStrideOrg;
-  }
-  
+
+    piCur += iStrideCur;
+    piOrg += iStrideOrg;
+  }
+
   //horizontal
   for (j=0; j < 8; j++)
@@ -1511,5 +1515,5 @@
     m2[j][6] = diff[jj+2] - diff[jj+6];
     m2[j][7] = diff[jj+3] - diff[jj+7];
-    
+
     m1[j][0] = m2[j][0] + m2[j][2];
     m1[j][1] = m2[j][1] + m2[j][3];
@@ -1520,5 +1524,5 @@
     m1[j][6] = m2[j][4] - m2[j][6];
     m1[j][7] = m2[j][5] - m2[j][7];
-    
+
     m2[j][0] = m1[j][0] + m1[j][1];
     m2[j][1] = m1[j][0] - m1[j][1];
@@ -1530,5 +1534,5 @@
     m2[j][7] = m1[j][6] - m1[j][7];
   }
-  
+
   //vertical
   for (i=0; i < 8; i++)
@@ -1542,5 +1546,5 @@
     m3[6][i] = m2[2][i] - m2[6][i];
     m3[7][i] = m2[3][i] - m2[7][i];
-    
+
     m1[0][i] = m3[0][i] + m3[2][i];
     m1[1][i] = m3[1][i] + m3[3][i];
@@ -1551,5 +1555,5 @@
     m1[6][i] = m3[4][i] - m3[6][i];
     m1[7][i] = m3[5][i] - m3[7][i];
-    
+
     m2[0][i] = m1[0][i] + m1[1][i];
     m2[1][i] = m1[0][i] - m1[1][i];
@@ -1561,5 +1565,5 @@
     m2[7][i] = m1[6][i] - m1[7][i];
   }
-  
+
   for (i = 0; i < 8; i++)
   {
@@ -1569,7 +1573,7 @@
     }
   }
-  
+
   sad=((sad+2)>>2);
-  
+
   return sad;
 }
@@ -1681,5 +1685,5 @@
   //vertical
   for (i=0; i < 16; i++)
-  {    
+  {
     m2[0][i] = m1[0][i] + m1[2][i];
     m2[1][i] = m1[1][i] + m1[3][i];
@@ -1838,7 +1842,7 @@
   Int  iOffsetOrg = iStrideOrg<<2;
   Int  iOffsetCur = iStrideCur<<2;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   for ( y=0; y<iRows; y+= 4 )
   {
@@ -1847,5 +1851,5 @@
     piCur += iOffsetCur;
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1864,7 +1868,7 @@
   Int  iStep  = pcDtParam->iStep;
   Int  y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
   if ( iRows == 4 )
   {
@@ -1883,5 +1887,5 @@
     }
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
@@ -1900,9 +1904,9 @@
   Int  iStrideOrg = pcDtParam->iStrideOrg;
   Int  iStep  = pcDtParam->iStep;
-  
+
   Int  x, y;
-  
-  UInt uiSum = 0;
-  
+
+  UInt uiSum = 0;
+
 #if NS_HAD
   if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )
@@ -1924,5 +1928,5 @@
   }
 #if NS_HAD
-  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<2;
@@ -1938,5 +1942,5 @@
     }
   }
-  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD ) 
+  else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )
   {
     Int  iOffsetOrg = iStrideOrg<<4;
@@ -1957,5 +1961,5 @@
     Int  iOffsetOrg = iStrideOrg<<2;
     Int  iOffsetCur = iStrideCur<<2;
-    
+
     for ( y=0; y<iRows; y+= 4 )
     {
@@ -1986,5 +1990,5 @@
     assert(false);
   }
-  
+
   return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(pcDtParam->bitDepth-8);
 }
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.cpp	(revision 466)
@@ -86,14 +86,5 @@
 // Data structure related table & variable
 // ====================================================================================================================
-#if LAYER_CTB
-UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
-UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
-UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
-UInt g_auiLayerAddCUDepth[MAX_LAYERS];
-UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-#endif
+
 UInt g_uiMaxCUWidth  = MAX_CU_SIZE;
 UInt g_uiMaxCUHeight = MAX_CU_SIZE;
@@ -321,5 +312,14 @@
 UInt g_uiPCMBitDepthLuma     = 8;    // PCM bit-depth
 UInt g_uiPCMBitDepthChroma   = 8;    // PCM bit-depth
-
+#if O0194_DIFFERENT_BITDEPTH_EL_BL
+Int  g_bitDepthYLayer[MAX_LAYERS];
+Int  g_bitDepthCLayer[MAX_LAYERS];
+
+UInt g_uiPCMBitDepthLumaDec[MAX_LAYERS];    // PCM bit-depth
+UInt g_uiPCMBitDepthChromaDec[MAX_LAYERS];    // PCM bit-depth
+#endif
+#if O0194_WEIGHTED_PREDICTION_CGS
+void * g_refWeightACDCParam; // type=wpACDCParam
+#endif
 // ====================================================================================================================
 // Misc.
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComRom.h	(revision 466)
@@ -81,14 +81,4 @@
 
 // global variable (LCU width/height, max. CU depth)
-#if LAYER_CTB
-extern       UInt g_auiLayerMaxCUWidth[MAX_LAYERS];
-extern       UInt g_auiLayerMaxCUHeight[MAX_LAYERS];
-extern       UInt g_auiLayerMaxCUDepth[MAX_LAYERS];
-extern       UInt g_auiLayerAddCUDepth[MAX_LAYERS];
-extern       UInt g_auiLayerZscanToRaster[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-extern       UInt g_auiLayerRasterToZscan[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-extern       UInt g_auiLayerRasterToPelX[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-extern       UInt g_auiLayerRasterToPelY[MAX_LAYERS][ MAX_NUM_SPU_W*MAX_NUM_SPU_W ];
-#endif
 extern       UInt g_uiMaxCUWidth;
 extern       UInt g_uiMaxCUHeight;
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComSlice.h	(revision 466)
@@ -1602,4 +1602,7 @@
   Int64 iAC;
   Int64 iDC;
+#if O0194_WEIGHTED_PREDICTION_CGS
+  Int iSamples;
+#endif
 } wpACDCParam;
 
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 466)
@@ -17,14 +17,14 @@
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
   {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
-#endif
-  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5      
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+#endif
+  { -1, 4, -11, 52, 26,  -8,  3, -1}, // <-> actual phase shift 1/3, used for spatial scalability x1.5
 #if ARBITRARY_SPATIAL_RATIO
   { -1, 3,  -9, 47, 31, -10,  4, -1},
   { -1, 4, -11, 45, 34, -10,  4, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //       
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 4, -11, 40, 40, -11,  4, -1}, // <-> actual phase shift 1/2, equal to HEVC MC, used for spatial scalability x2
@@ -33,6 +33,6 @@
   { -1,  4, -10, 31, 47,  -9,  3, -1},
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
 #endif
   { -1, 3,  -8, 26, 52, -11, 4, -1}, // <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -43,8 +43,8 @@
   { 0,  1,  -2,  4, 63,  -3,  1,  0}
 #else
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, // 
-  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  // 
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}, //
+  {CNU,CNU,CNU,CNU,CNU,CNU,CNU,CNU}  //
 #endif
 };
@@ -60,13 +60,13 @@
   {CNU,CNU,CNU,CNU},//
   {CNU,CNU,CNU,CNU},//
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 54, 16, -2},// <-> actual phase shift 1/4,equal to HEVC MC, used for spatial scalability x1.5 (only for accurate Chroma alignement)
-  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5   
-  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)      
+  { -6, 52, 20, -2},// <-> actual phase shift 1/3, used for spatial scalability x1.5
+  { -6, 46, 28, -4},// <-> actual phase shift 3/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
 #if ARBITRARY_SPATIAL_RATIO
   { -4, 42, 30, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -4, 36, 36, -4},// <-> actual phase shift 1/2,equal to HEVC MC, used for spatial scalability x2
@@ -75,5 +75,5 @@
   { -4, 28, 46, -6},
 #else
-  {CNU,CNU,CNU,CNU},// 
+  {CNU,CNU,CNU,CNU},//
 #endif
   { -2, 20, 52, -6},// <-> actual phase shift 2/3, used for spatial scalability x1.5
@@ -82,8 +82,8 @@
   {-2, 14, 56, -4},
 #else
-  {CNU,CNU,CNU,CNU},// 
-  {CNU,CNU,CNU,CNU},// 
-#endif
-  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)  
+  {CNU,CNU,CNU,CNU},//
+  {CNU,CNU,CNU,CNU},//
+#endif
+  { -2, 10, 58, -2},// <-> actual phase shift 7/8,equal to HEVC MC, used for spatial scalability x2 (only for accurate Chroma alignement)
   {  0,  4, 62, -2} // <-> actual phase shift 11/12, used for spatial scalability x1.5 (only for accurate Chroma alignement)
 };
@@ -109,4 +109,5 @@
 
   //========== Y component upsampling ===========
+#if SCALED_REF_LAYER_OFFSETS
   const Window &scalEL = window;
 
@@ -118,5 +119,16 @@
   Int heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
   Int strideEL  = pcUsPic->getStride();
-
+#else
+  const Window &confBL = pcBasePic->getConformanceWindow();
+  const Window &confEL = pcUsPic->getConformanceWindow();
+
+  Int widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+  Int strideBL  = pcBasePic->getStride();
+
+  Int widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+  Int heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+  Int strideEL  = pcUsPic->getStride();
+#endif
   Pel* piTempBufY = pcTempPic->getLumaAddr();
   Pel* piSrcBufY  = pcBasePic->getLumaAddr();
@@ -182,5 +194,5 @@
     Int refPos16 = 0;
     Int phase    = 0;
-    Int refPos   = 0; 
+    Int refPos   = 0;
     Int* coeff = m_chromaFilter[phase];
     for ( i = 0; i < 16; i++)
@@ -190,5 +202,5 @@
     }
 
-#if ARBITRARY_SPATIAL_RATIO 
+#if ARBITRARY_SPATIAL_RATIO
     assert ( widthEL >= widthBL );
     assert ( heightEL >= heightBL );
@@ -205,6 +217,6 @@
 
 #if O0215_PHASE_ALIGNMENT //for Luma, if Phase 0, then both PhaseX  and PhaseY should be 0. If symmetric: both PhaseX and PhaseY should be 2
-    Int   phaseX = 2*phaseAlignFlag; 
-    Int   phaseY = 2*phaseAlignFlag;  
+    Int   phaseX = 2*phaseAlignFlag;
+    Int   phaseY = 2*phaseAlignFlag;
 #else
     Int   phaseX = 0;
@@ -221,5 +233,5 @@
 
     Int   deltaX     = 4 * phaseX;
-    Int   deltaY     = 4 * phaseY;  
+    Int   deltaY     = 4 * phaseY;
 
     Int shiftXM4 = shiftX - 4;
@@ -231,13 +243,21 @@
     widthBL   = pcBasePic->getWidth ();
     heightBL  = min<Int>( pcBasePic->getHeight(), heightEL );
-
+#if SCALED_REF_LAYER_OFFSETS
     Int leftStartL = scalEL.getWindowLeftOffset();
     Int rightEndL  = pcUsPic->getWidth() - scalEL.getWindowRightOffset();
     Int topStartL  = scalEL.getWindowTopOffset();
     Int bottomEndL = pcUsPic->getHeight() - scalEL.getWindowBottomOffset();
+#if BUGFIX_RESAMPLE
     Int leftOffset = leftStartL > 0 ? leftStartL : 0;
+#endif
+#endif
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    // g_bitDepthY was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
+    Int shift1 = g_bitDepthYLayer[0] - 8;
+#else
     Int shift1 = g_bitDepthY - 8;
+#endif
 #endif
 
@@ -245,6 +265,10 @@
     for( i = 0; i < widthEL; i++ )
     {
+#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3( leftStartL, rightEndL - 1, i );
       refPos16 = (((x - leftStartL)*scaleX + addX) >> shiftXM4) - deltaX;
+#else
+      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -273,14 +297,26 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+  Int nShift = 20 - g_bitDepthYLayer[1];
+#else
     Int nShift = US_FILTER_PREC*2 - shift1;
+#endif
 #else
     const Int nShift = US_FILTER_PREC*2;
 #endif
-    Int iOffset = 1 << (nShift - 1); 
-
+    Int iOffset = 1 << (nShift - 1);
+
+#if SCALED_REF_LAYER_OFFSETS
     for( j = 0; j < pcTempPic->getHeight(); j++ )
+#else
+    for( j = 0; j < heightEL; j++ )
+#endif
     {
+#if SCALED_REF_LAYER_OFFSETS
       Int y = Clip3(topStartL, bottomEndL - 1, j);
       refPos16 = ((( y - topStartL )*scaleY + addY) >> shiftYM4) - deltaY;
+#else
+      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -288,5 +324,7 @@
 
       piSrcY = piTempBufY + (refPos -((NTAPS_US_LUMA>>1) - 1))*strideEL;
-      Pel* piDstY0 = piDstBufY + j * strideEL;            
+#if SCALED_REF_LAYER_OFFSETS
+#if BUGFIX_RESAMPLE
+      Pel* piDstY0 = piDstBufY + j * strideEL;
       piDstY = piDstY0 + leftOffset;
       piSrcY += leftOffset;
@@ -311,7 +349,58 @@
         piDstY++;
       }
-
+#else
+#if 1 // it should provide identical result
+      Pel* piDstY0 = piDstBufY + j * strideEL;
+      piDstY = piDstY0 + ( leftStartL > 0 ? leftStartL : 0 );
+
+      for( i = min<Int>(rightEndL, pcTempPic->getWidth()) - max<Int>(0, leftStartL); i > 0; i-- )
+      {
+        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcY++;
+        piDstY++;
+      }
+
+      for( i = rightEndL; i < pcTempPic->getWidth(); i++ )
+      {
+        *piDstY = piDstY0[rightEndL-1];
+        piDstY++;
+      }
+
+      piDstY = piDstY0;
+      for( i = 0; i < leftStartL; i++ )
+      {
+        *piDstY = piDstY0[leftStartL];
+        piDstY++;
+      }
+#else
+      piDstY = piDstBufY + j * strideEL;
+
+      for( i = 0; i < pcTempPic->getWidth(); i++ )
+      {
+        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+
+        // Only increase the x position of reference upsample picture when within the window
+        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndL-1
+        if( (i >= leftStartL) && (i <= rightEndL-2) )
+        {
+          piSrcY++;
+        }
+        piDstY++;
+      }
+#endif
+#endif
+#else
+      piDstY = piDstBufY + j * strideEL;
+
+      for( i = 0; i < widthEL; i++ )
+      {
+        *piDstY = ClipY( (sumLumaVer(piSrcY, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcY++;
+        piDstY++;
+      }
+#endif
     }
 
+#if SCALED_REF_LAYER_OFFSETS
     widthBL   = pcBasePic->getWidth ();
     heightBL  = pcBasePic->getHeight();
@@ -319,4 +408,11 @@
     widthEL   = pcUsPic->getWidth () - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
     heightEL  = pcUsPic->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+#else
+    widthBL   = pcBasePic->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+    heightBL  = pcBasePic->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+    widthEL   = pcUsPic->getWidth () - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+    heightEL  = pcUsPic->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
 
     //========== UV component upsampling ===========
@@ -330,17 +426,20 @@
     strideBL  = pcBasePic->getCStride();
     strideEL  = pcUsPic->getCStride();
-
+#if SCALED_REF_LAYER_OFFSETS
     Int leftStartC = scalEL.getWindowLeftOffset() >> 1;
     Int rightEndC  = (pcUsPic->getWidth() >> 1) - (scalEL.getWindowRightOffset() >> 1);
     Int topStartC  = scalEL.getWindowTopOffset() >> 1;
     Int bottomEndC = (pcUsPic->getHeight() >> 1) - (scalEL.getWindowBottomOffset() >> 1);
+#if BUGFIX_RESAMPLE
     leftOffset = leftStartC > 0 ? leftStartC : 0;
+#endif
+#endif
 
     shiftX = 16;
     shiftY = 16;
 
-#if O0215_PHASE_ALIGNMENT  
-    Int phaseXC = 0; 
-    Int phaseYC = 1; 
+#if O0215_PHASE_ALIGNMENT
+    Int phaseXC = 0;
+    Int phaseYC = 1;
 
 #if ROUNDING_OFFSET
@@ -380,5 +479,10 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    // g_bitDepthC was set to EL bit-depth, but shift1 should be calculated using BL bit-depth
+    shift1 = g_bitDepthCLayer[0] - 8;
+#else
     shift1 = g_bitDepthC - 8;
+#endif
 #endif
 
@@ -386,6 +490,10 @@
     for( i = 0; i < widthEL; i++ )
     {
+#if SCALED_REF_LAYER_OFFSETS
       Int x = Clip3(leftStartC, rightEndC - 1, i);
       refPos16 = (((x - leftStartC)*scaleX + addX) >> shiftXM4) - deltaX;
+#else
+      refPos16 = ((i*scaleX + addX) >> shiftXM4) - deltaX;
+#endif
       phase    = refPos16 & 15;
       refPos   = refPos16 >> 4;
@@ -421,19 +529,32 @@
 
 #if  N0214_INTERMEDIATE_BUFFER_16BITS
+#if O0194_JOINT_US_BITSHIFT
+    nShift = 20 - g_bitDepthCLayer[1];
+#else
     nShift = US_FILTER_PREC*2 - shift1;
-    iOffset = 1 << (nShift - 1); 
-#endif
-
+#endif
+    iOffset = 1 << (nShift - 1);
+#endif
+
+#if SCALED_REF_LAYER_OFFSETS
     for( j = 0; j < pcTempPic->getHeight() >> 1; j++ )
+#else
+    for( j = 0; j < heightEL; j++ )
+#endif
     {
+#if SCALED_REF_LAYER_OFFSETS
       Int y = Clip3(topStartC, bottomEndC - 1, j);
       refPos16 = (((y - topStartC)*scaleY + addY) >> shiftYM4) - deltaY;
+#else
+      refPos16 = ((j*scaleY + addY) >> shiftYM4) - deltaY;
+#endif
       phase    = refPos16 & 15;
-      refPos   = refPos16 >> 4; 
+      refPos   = refPos16 >> 4;
       coeff = m_chromaFilter[phase];
 
       piSrcU = piTempBufU  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
       piSrcV = piTempBufV  + (refPos -((NTAPS_US_CHROMA>>1) - 1))*strideEL;
-
+#if SCALED_REF_LAYER_OFFSETS
+#if BUGFIX_RESAMPLE
       Pel* piDstU0 = piDstBufU + j*strideEL;
       Pel* piDstV0 = piDstBufV + j*strideEL;
@@ -447,4 +568,5 @@
         *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
         *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
+
         piSrcU++;
         piSrcV++;
@@ -470,14 +592,83 @@
         piDstV++;
       }
-
+#else
+#if 1 // it should provide identical result
+      Pel* piDstU0 = piDstBufU + j*strideEL;
+      Pel* piDstV0 = piDstBufV + j*strideEL;
+      piDstU = piDstU0 + ( leftStartC > 0 ? leftStartC : 0 );
+      piDstV = piDstV0 + ( leftStartC > 0 ? leftStartC : 0 );
+
+      for( i = min<Int>(rightEndC, pcTempPic->getWidth() >> 1) - max<Int>(0, leftStartC); i > 0; i-- )
+      {
+        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
+        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcU++;
+        piSrcV++;
+        piDstU++;
+        piDstV++;
+      }
+
+      for( i = rightEndC; i < pcTempPic->getWidth() >> 1; i++ )
+      {
+        *piDstU = piDstU0[rightEndC-1];
+        *piDstV = piDstV0[rightEndC-1];
+        piDstU++;
+        piDstV++;
+      }
+
+      piDstU = piDstU0;
+      piDstV = piDstV0;
+      for( i = 0; i < leftStartC; i++ )
+      {
+        *piDstU = piDstU0[leftStartC];
+        *piDstV = piDstV0[leftStartC];
+        piDstU++;
+        piDstV++;
+      }
+#else
+      piDstU = piDstBufU + j*strideEL;
+      piDstV = piDstBufV + j*strideEL;
+
+      for( i = 0; i < pcTempPic->getWidth() >> 1; i++ )
+      {
+        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
+        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
+
+        // Only increase the x position of reference upsample picture when within the window
+        // "-2" to ensure that pointer doesn't go beyond the boundary rightEndC-1
+        if( (i >= leftStartC) && (i <= rightEndC-2) )
+        {
+          piSrcU++;
+          piSrcV++;
+        }
+
+        piDstU++;
+        piDstV++;
+      }
+#endif
+#endif
+#else
+      piDstU = piDstBufU + j*strideEL;
+      piDstV = piDstBufV + j*strideEL;
+
+      for( i = 0; i < widthEL; i++ )
+      {
+        *piDstU = ClipC( (sumChromaVer(piSrcU, coeff, strideEL) + iOffset) >> (nShift));
+        *piDstV = ClipC( (sumChromaVer(piSrcV, coeff, strideEL) + iOffset) >> (nShift));
+        piSrcU++;
+        piSrcV++;
+        piDstU++;
+        piDstV++;
+      }
+#endif
     }
   }
-  pcUsPic->setBorderExtension(false);
-  pcUsPic->extendPicBorder   (); // extend the border.
-
-  //Reset the Border extension flag
-  pcUsPic->setBorderExtension(false);
-  pcTempPic->setBorderExtension(false);
-  pcBasePic->setBorderExtension(false);
+    pcUsPic->setBorderExtension(false);
+    pcUsPic->extendPicBorder   (); // extend the border.
+
+    //Reset the Border extension flag
+    pcUsPic->setBorderExtension(false);
+    pcTempPic->setBorderExtension(false);
+    pcBasePic->setBorderExtension(false);
 }
 #endif //SVC_EXTENSION
Index: branches/SHM-4.0-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibCommon/TypeDef.h	(revision 466)
@@ -46,4 +46,10 @@
 #if SVC_EXTENSION
 #define MFM_ENCCONSTRAINT                1      ///< JCTVC-O0216: Encoder constraint for motion field mapping
+
+#define O0194_DIFFERENT_BITDEPTH_EL_BL   1      ///< JCTVC-O0194: Support for different bitdepth values for BL and EL, add required configuration parameters
+#define O0194_JOINT_US_BITSHIFT          1      ///< JCTVC-O0194: Joint Upsampling and bit-shift
+#define O0194_WEIGHTED_PREDICTION_CGS    1      ///< JCTVC-O0194: Weighted prediciton for color gamut scalability
+#define O0194_REPN_FORMAT_IN_VPS_BUGFIX  1      ///< JCTVC-O0194: Some bugfixes when REPN_FORMAT_IN_VPS (JCTVC-N0092) is enabled
+
 #define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
 #define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
@@ -59,9 +65,10 @@
 #endif
 #define IL_SL_SIGNALLING_N0371           0      ///< JCTVC-N0371: inter-layer scaling list
+#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< JCTVC-M0464: VUI flag to indicate tile boundary alignment
 #define M0463_VUI_EXT_ILP_REF            0      ///< JCTVC-M0463: VUI extension inter-layer dependency offset signalling
 #define SPS_EXTENSION                    1      ///< Define sps_extension() syntax structure
+#define SCALED_REF_LAYER_OFFSETS         1      ///< JCTVC-M0309: Signal scaled reference layer offsets in SPS
 #define VERT_MV_CONSTRAINT               1      ///< Vertical MV component constraint flag
 #define SCALABILITY_MASK_E0104           1      ///< JCT3V-E0104: scalability mask for depth
-#define LAYER_CTB                        0      ///< enable layer-specific CTB structure
 
 #define ILP_SSH_SIG                      1      ///< JCTVC-N0195 proposal 2, JCTVC-N0118: add presence flag in VPS ext to condition inter-layer prediction signaling in slice segment header
@@ -79,4 +86,9 @@
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
 #define VPS_EXTN_DIRECT_REF_LAYERS       1      ///< Include indication of direct dependency of layers in VPS extension
+#define VPS_OUTPUT_LAYER_SET_IDX         1      ///< JCTVC-M0268: Signal output_layer_set_idx[i] as output_layer_set_idx_minus1[i]
+#define VPS_MOVE_DIR_DEPENDENCY_FLAG     1      ///< JCTVC-M0268: Move the syntax element direct_dependency_flag to follow the syntax element dimension_id
+#define VPS_PROFILE_OUTPUT_LAYERS        1      ///< JCTVC-M0268: Signal profile information and output layer information as in Sec. 3 of M0268v2
+#define SPS_SUB_LAYER_INFO               1      ///< JCTVC-M0268: Do not signal sps_max_sub_layers_minus1 and sps_temporal_id_nesting_flag for nuh_layer_id greater than 0
+#define VPS_SPLIT_FLAG                   1      ///< JCTVC-M0163: Do not signal dimension_id and the last dimension_id_len_minus1, when splitting_flag is equal to 1. 
 #define M0457_PREDICTION_INDICATIONS     1
 #define M0040_ADAPTIVE_RESOLUTION_CHANGE 1
@@ -87,4 +99,6 @@
 #define N0160_VUI_EXT_ILP_REF            1      ///< VUI extension inter-layer dependency offset signalling
 #define VPS_VUI_BITRATE_PICRATE          1      ///< JCTVC-N0085: Signal bit rate and picture in VPS VUI
+#else
+#define M0464_TILE_BOUNDARY_ALIGNED_FLAG 0      ///< VUI flag to indicate tile boundary alignment
 #endif //VPS_VUI
 
@@ -94,4 +108,5 @@
 #define VPS_EXTN_OFFSET_CALC             1      ///< Calculation of VPS extension offset
 #define SPS_PTL_FIX                      1      ///< remove profile_tier_level from enhancement layer SPS
+#define SH_DISCARDABLE_FLAG              1      ///< JCTVC-M0152: Use one reserved flag in the slice header for discardable flag
 
 #define DERIVE_LAYER_ID_LIST_VARIABLES   1      ///< Derived variables based on the variables in VPS - for use in syntax table parsing
@@ -101,4 +116,5 @@
 #define N0214_INTERMEDIATE_BUFFER_16BITS 1      ///< JCTVC-N0214: support base layer input more than 8 bits
 #define ARBITRARY_SPATIAL_RATIO          1      ///< JCTVC-N0219, JCTVC-N0273: Support arbitrary spatial ratio
+#define BUGFIX_RESAMPLE                  1      ///< JCTVC-N0055: resampling bug fix for positive left scalled offset
 
 #define JCTVC_M0259_LAMBDAREFINEMENT     1      ///< JCTVC-M0259: lambda refinement (encoder only optimization)
@@ -121,4 +137,6 @@
 #define JCTVC_M0203_INTERLAYER_PRED_IDC  1      ///< JCTVC-M0203: implementation of Inter-layer Prediction Indication
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
+#define ILR_RESTR                        1      ///< JCTVC-M0209: Inter-layer RPS and RPL
+#define ILR_RESTR_FIX                    1      ///< Fix encoder crash when temporal layers are used with scalable coding
 #define EARLY_REF_PIC_MARKING            1      ///< Decoded picture marking of sub-layer non-reference pictures
 #define N0120_MAX_TID_REF_PRESENT_FLAG   1      ///< JCTVC-N0120: max_tid_ref_pics_plus1_present_flag
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 466)
@@ -187,9 +187,9 @@
   assert(uiCode <= 63);
   pcPPS->setPPSId (uiCode);
-  
+
   READ_UVLC( uiCode, "pps_seq_parameter_set_id");
   assert(uiCode <= 15);
   pcPPS->setSPSId (uiCode);
-  
+
   READ_FLAG( uiCode, "dependent_slice_segments_enabled_flag"    );    pcPPS->setDependentSliceSegmentsEnabledFlag   ( uiCode == 1 );
   READ_FLAG( uiCode, "output_flag_present_flag" );                    pcPPS->setOutputFlagPresentFlag( uiCode==1 );
@@ -293,5 +293,5 @@
 
 #if IL_SL_SIGNALLING_N0371
-  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );  
+  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS );
 #endif
 
@@ -301,9 +301,9 @@
     pcPPS->getScalingList()->setLayerId( pcPPS->getLayerId() );
 
-    if( pcPPS->getLayerId() > 0 ) 
+    if( pcPPS->getLayerId() > 0 )
     {
       READ_FLAG( uiCode, "pps_pred_scaling_list_flag" );           pcPPS->setPredScalingListFlag( uiCode ? true : false );
       pcPPS->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
-      
+
       if( pcPPS->getPredScalingListFlag() )
       {
@@ -319,9 +319,9 @@
         }
 
-        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
         // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
         assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
 
-        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
         // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
         assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
@@ -450,4 +450,10 @@
   {
     READ_FLAG(   uiCode, "tiles_fixed_structure_flag");               pcVUI->setTilesFixedStructureFlag(uiCode);
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+    if ( pcSPS->getLayerId() > 0 )
+    {
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag" ); pcVUI->setTileBoundariesAlignedFlag( uiCode == 1 );
+    }
+#endif
     READ_FLAG(   uiCode, "motion_vectors_over_pic_boundaries_flag");  pcVUI->setMotionVectorsOverPicBoundariesFlag(uiCode);
     READ_FLAG(   uiCode, "restricted_ref_pic_lists_flag");            pcVUI->setRestrictedRefPicListsFlag(uiCode);
@@ -536,5 +542,5 @@
 }
 
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
 Void TDecCavlc::parseSPS(TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager)
 #else
@@ -548,5 +554,5 @@
   UInt  uiCode;
   READ_CODE( 4,  uiCode, "sps_video_parameter_set_id");          pcSPS->setVPSId        ( uiCode );
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   if(pcSPS->getLayerId() == 0)
   {
@@ -554,7 +560,7 @@
     READ_CODE( 3,  uiCode, "sps_max_sub_layers_minus1" );          pcSPS->setMaxTLayers   ( uiCode+1 );
     assert(uiCode <= 6);
-  
+
     READ_FLAG( uiCode, "sps_temporal_id_nesting_flag" );               pcSPS->setTemporalIdNestingFlag ( uiCode > 0 ? true : false );
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   }
   else
@@ -563,13 +569,13 @@
     pcSPS->setTemporalIdNestingFlag( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId())->getTemporalNestingFlag() );
   }
+#endif
 #if IL_SL_SIGNALLING_N0371
   pcSPS->setVPS( parameterSetManager->getPrefetchedVPS(pcSPS->getVPSId()) );
   pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
 #endif
-#endif
   if ( pcSPS->getMaxTLayers() == 1 )
   {
     // sps_temporal_id_nesting_flag must be 1 when sps_max_sub_layers_minus1 is 0
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
     assert( pcSPS->getTemporalIdNestingFlag() == true );
 #else
@@ -592,5 +598,5 @@
   if( pcSPS->getLayerId() > 0 )
   {
-    READ_FLAG( uiCode, "update_rep_format_flag" );                 
+    READ_FLAG( uiCode, "update_rep_format_flag" );
     pcSPS->setUpdateRepFormatFlag( uiCode ? true : false );
   }
@@ -599,5 +605,5 @@
     pcSPS->setUpdateRepFormatFlag( true );
   }
-  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
   {
 #endif
@@ -633,5 +639,5 @@
   }
 #if REPN_FORMAT_IN_VPS
-  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() ) 
+  if(  pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
   {
 #endif
@@ -653,5 +659,5 @@
   UInt subLayerOrderingInfoPresentFlag;
   READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
-  
+
   for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
   {
@@ -722,9 +728,9 @@
           }
 
-          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and 
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
           // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
           assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
 
-          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB, 
+          // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
           // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
           assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
@@ -835,7 +841,8 @@
   assert( uiCode == 0 );
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   if( pcSPS->getLayerId() > 0 )
   {
-    Int iCode; 
+    Int iCode;
     READ_UVLC( uiCode,      "num_scaled_ref_layer_offsets" ); pcSPS->setNumScaledRefLayerOffsets(uiCode);
     for(Int i = 0; i < pcSPS->getNumScaledRefLayerOffsets(); i++)
@@ -848,22 +855,23 @@
     }
   }
+#endif
 #if M0463_VUI_EXT_ILP_REF
   ////   sps_extension_vui_parameters( )
   if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
-  {  
-    READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode ); 
-    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ ) 
-    {  
-      READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode ); 
-      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 ) 
-      {  
-        READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 ); 
-        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )  
-        {
-          READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode ); 
-        }
-      }  
-    }  
-  }  
+  {
+    READ_UVLC( uiCode, "num_ilp_restricted_ref_layers" ); pcSPS->setNumIlpRestrictedRefLayers( uiCode );
+    for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
+    {
+      READ_UVLC( uiCode, "min_spatial_segment_offset_plus1" ); pcSPS->setMinSpatialSegmentOffsetPlus1( i, uiCode );
+      if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
+      {
+        READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[ i ]"); pcSPS->setCtuBasedOffsetEnabledFlag(i, uiCode == 1 );
+        if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) )
+        {
+          READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[ i ]"); pcSPS->setMinHorizontalCtuOffsetPlus1( i, uiCode );
+        }
+      }
+    }
+  }
   ////   sps_extension_vui_parameters( ) END
 #endif
@@ -992,5 +1000,4 @@
 }
 
-#if SVC_EXTENSION
 #if VPS_EXTNS
 Void TDecCavlc::parseVPSExtension(TComVPS *vps)
@@ -1011,9 +1018,13 @@
   vps->setNumScalabilityTypes(numScalabilityTypes);
 
+#if VPS_SPLIT_FLAG
   for(j = 0; j < numScalabilityTypes - vps->getSplittingFlag(); j++)
+#else
+  for(j = 0; j < numScalabilityTypes; j++)
+#endif
   {
     READ_CODE( 3, uiCode, "dimension_id_len_minus1[j]" ); vps->setDimensionIdLen(j, uiCode + 1);
   }
-
+#if VPS_SPLIT_FLAG
   if(vps->getSplittingFlag())
   {
@@ -1027,4 +1038,15 @@
     numBits = 6;
   }
+#else
+  if(vps->getSplittingFlag())
+  {
+    UInt numBits = 0;
+    for(j = 0; j < numScalabilityTypes; j++)
+    {
+      numBits += vps->getDimensionIdLen(j);
+    }
+    assert( numBits <= 6 );
+  }
+#endif
 
   READ_FLAG( uiCode, "vps_nuh_layer_id_present_flag" ); vps->setNuhLayerIdPresentFlag(uiCode ? true : false);
@@ -1044,17 +1066,17 @@
     vps->setLayerIdInVps(vps->getLayerIdInNuh(i), i);
 
-    if( !vps->getSplittingFlag() )
-    {
-      for(j = 0; j < numScalabilityTypes; j++)
-      {
-        READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
-        assert( uiCode <= vps->getMaxLayerId() );
-      }
-    }
-  }
-#endif
-#if VIEW_ID_RELATED_SIGNALING 
-  // if ( pcVPS->getNumViews() > 1 )  
-  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val. 
+#if VPS_SPLIT_FLAG
+    if(!vps->getSplittingFlag())
+#endif
+    for(j = 0; j < numScalabilityTypes; j++)
+    {
+      READ_CODE( vps->getDimensionIdLen(j), uiCode, "dimension_id[i][j]" ); vps->setDimensionId(i, j, uiCode);
+      assert( uiCode <= vps->getMaxLayerId() );
+    }
+  }
+#endif
+#if VIEW_ID_RELATED_SIGNALING
+  // if ( pcVPS->getNumViews() > 1 )
+  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
   {
     READ_CODE( 4, uiCode, "view_id_len_minus1" ); vps->setViewIdLenMinus1( uiCode );
@@ -1066,4 +1088,5 @@
   }
 #endif
+#if VPS_MOVE_DIR_DEPENDENCY_FLAG
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // For layer 0
@@ -1085,4 +1108,5 @@
   }
 #endif
+#endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
 #if N0120_MAX_TID_REF_PRESENT_FLAG
@@ -1095,10 +1119,10 @@
 #if N0120_MAX_TID_REF_CFG
       assert( uiCode <= vps->getMaxTLayers());
-#else 
+#else
       assert( uiCode <= vps->getMaxTLayers()+ 1 );
-#endif 
-    }
-  }
-  else 
+#endif
+    }
+  }
+  else
   {
     for(i = 0; i < vps->getMaxLayers() - 1; i++)
@@ -1120,15 +1144,23 @@
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
+#if VPS_PROFILE_OUTPUT_LAYERS
   READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1" );     assert( uiCode == (vps->getNumLayerSets() - 1) );
   READ_CODE(  6, uiCode, "vps_num_profile_tier_level_minus1"); vps->setNumProfileTierLevel( uiCode + 1 );
   vps->getPTLForExtnPtr()->resize(vps->getNumProfileTierLevel());
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+#else
+  vps->getPTLForExtnPtr()->resize(vps->getNumLayerSets());
+  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
+#endif
   {
     READ_FLAG( uiCode, "vps_profile_present_flag[i]" ); vps->setProfilePresentFlag(idx, uiCode ? true : false);
     if( !vps->getProfilePresentFlag(idx) )
     {
+#if VPS_PROFILE_OUTPUT_LAYERS
       READ_CODE( 6, uiCode, "profile_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
+#else
+      READ_UVLC( uiCode, "vps_profile_layer_set_ref_minus1[i]" ); vps->setProfileLayerSetRef(idx, uiCode + 1);
+#endif
       assert( vps->getProfileLayerSetRef(idx) < idx );
-
       // Copy profile information as indicated
       vps->getPTLForExtn(idx)->copyProfileInfo( vps->getPTLForExtn( vps->getProfileLayerSetRef(idx) ) );
@@ -1138,4 +1170,5 @@
 #endif
 
+#if VPS_PROFILE_OUTPUT_LAYERS
   READ_FLAG( uiCode, "more_output_layer_sets_than_default_flag" ); vps->setMoreOutputLayerSetsThanDefaultFlag( uiCode ? true : false );
   Int numOutputLayerSets = 0;
@@ -1198,7 +1231,28 @@
     READ_CODE( numBits, uiCode, "profile_level_tier_idx[i]" );     vps->setProfileLevelTierIdx(i, uiCode);
   }
-
+#else
+#if VPS_EXTN_OP_LAYER_SETS
+  // Target output layer signalling
+  READ_UVLC( uiCode,            "vps_num_output_layer_sets"); vps->setNumOutputLayerSets(uiCode);
+  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
+  {
+#if VPS_OUTPUT_LAYER_SET_IDX
+    READ_UVLC( uiCode,           "vps_output_layer_set_idx_minus1[i]"); vps->setOutputLayerSetIdx(i, uiCode + 1);
+#else
+    READ_UVLC( uiCode,           "vps_output_layer_set_idx[i]"); vps->setOutputLayerSetIdx(i, uiCode);
+#endif
+    Int lsIdx = vps->getOutputLayerSetIdx(i);
+    for(j = 0; j <= vps->getMaxLayerId(); j++)
+    {
+      if(vps->getLayerIdIncludedFlag(lsIdx, j))
+      {
+        READ_FLAG( uiCode, "vps_output_layer_flag[lsIdx][j]"); vps->setOutputLayerFlag(lsIdx, j, uiCode);
+      }
+    }
+  }
+#endif
+#endif
 #if REPN_FORMAT_IN_VPS
-  READ_FLAG( uiCode, "rep_format_idx_present_flag"); 
+  READ_FLAG( uiCode, "rep_format_idx_present_flag");
   vps->setRepFormatIdxPresentFlag( uiCode ? true : false );
 
@@ -1219,5 +1273,5 @@
     parseRepFormat( vps->getVpsRepFormat(i) );
   }
-  
+
   // Default assignment for layer 0
   vps->setVpsRepFormatIdx( 0, 0 );
@@ -1258,6 +1312,27 @@
   READ_FLAG(uiCode, "cross_layer_irap_aligned_flag" );
   vps->setCrossLayerIrapAlignFlag(uiCode);
-#endif 
-
+#endif
+
+#if !VPS_MOVE_DIR_DEPENDENCY_FLAG
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // For layer 0
+  vps->setNumDirectRefLayers(0, 0);
+  // For other layers
+  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    UInt numDirectRefLayers = 0;
+    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      READ_FLAG(uiCode, "direct_dependency_flag[i][j]" ); vps->setDirectDependencyFlag(layerCtr, refLayerCtr, uiCode? true : false);
+      if(uiCode)
+      {
+        vps->setRefLayerId(layerCtr, numDirectRefLayers, refLayerCtr);
+        numDirectRefLayers++;
+      }
+    }
+    vps->setNumDirectRefLayers(layerCtr, numDirectRefLayers);
+  }
+#endif
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   READ_UVLC( uiCode,           "direct_dep_type_len_minus2"); vps->setDirectDepTypeLen(uiCode+2);
@@ -1279,5 +1354,5 @@
     {
       for(j = 0; j < i; j++)
-        {      
+        {
           vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
         }
@@ -1298,5 +1373,5 @@
     }
     parseVPSVUI(vps);
-#endif 
+#endif
   }
 }
@@ -1307,5 +1382,5 @@
   UInt uiCode;
   READ_CODE( 2, uiCode, "chroma_format_idc" );               repFormat->setChromaFormatVpsIdc( uiCode );
-  
+
   if( repFormat->getChromaFormatVpsIdc() == 3 )
   {
@@ -1315,5 +1390,5 @@
   READ_CODE ( 16, uiCode, "pic_width_in_luma_samples" );     repFormat->setPicWidthVpsInLumaSamples ( uiCode );
   READ_CODE ( 16, uiCode, "pic_height_in_luma_samples" );    repFormat->setPicHeightVpsInLumaSamples( uiCode );
-  
+
   READ_CODE( 4, uiCode, "bit_depth_luma_minus8" );           repFormat->setBitDepthVpsLuma  ( uiCode + 8 );
   READ_CODE( 4, uiCode, "bit_depth_chroma_minus8" );         repFormat->setBitDepthVpsChroma( uiCode + 8 );
@@ -1381,10 +1456,10 @@
     for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     {
-      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));      
-    }
-  }  
-#endif 
+      READ_FLAG( uiCode, "tile_boundaries_aligned_flag[i][j]" ); vps->setTileBoundariesAlignedFlag(i,j,(uiCode == 1));
+    }
+  }
+#endif
 #if N0160_VUI_EXT_ILP_REF
-    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 ); 
+    READ_FLAG( uiCode, "num_ilp_restricted_ref_layers" ); vps->setNumIlpRestrictedRefLayers( uiCode == 1 );
   if( vps->getNumIlpRestrictedRefLayers())
   {
@@ -1393,21 +1468,19 @@
       for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
       {
-        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode ); 
-        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 ) 
-        {  
-          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 ); 
-          if(vps->getCtuBasedOffsetEnabledFlag(i,j))  
+        READ_UVLC( uiCode, "min_spatial_segment_offset_plus1[i][j]" ); vps->setMinSpatialSegmentOffsetPlus1( i, j, uiCode );
+        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
+        {
+          READ_FLAG( uiCode, "ctu_based_offset_enabled_flag[i][j]"); vps->setCtuBasedOffsetEnabledFlag(i, j, uiCode == 1 );
+          if(vps->getCtuBasedOffsetEnabledFlag(i,j))
           {
-            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode ); 
+            READ_UVLC( uiCode, "min_horizontal_ctu_offset_plus1[i][j]"); vps->setMinHorizontalCtuOffsetPlus1( i,j, uiCode );
           }
-        }  
-      }  
-    }
-  }
-#endif 
-}
-#endif
-#endif //SVC_EXTENSION
-
+        }
+      }
+    }
+  }
+#endif
+}
+#endif
 Void TDecCavlc::parseSliceHeader (TComSlice*& rpcSlice, ParameterSetManagerDecoder *parameterSetManager)
 {
@@ -1482,7 +1555,6 @@
   if(!rpcSlice->getDependentSliceSegmentFlag())
   {
-#if SVC_EXTENSION
 #if POC_RESET_FLAG
-    Int iBits = 0; 
+    Int iBits = 0;
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits)
     {
@@ -1500,4 +1572,5 @@
     }
 #else
+#if SH_DISCARDABLE_FLAG
     if(rpcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     {
@@ -1508,11 +1581,11 @@
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
-#endif
-#else //SVC_EXTENSION
+#else
     for (Int i = 0; i < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     {
       READ_FLAG(uiCode, "slice_reserved_undetermined_flag[]"); // ignored
     }
-#endif //SVC_EXTENSION
+#endif
+#endif
 
     READ_UVLC (    uiCode, "slice_type" );            rpcSlice->setSliceType((SliceType)uiCode);
@@ -1676,5 +1749,5 @@
             rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
             rps->setCheckLTMSBPresent(j,false);
-            
+
             // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
             if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
@@ -1779,5 +1852,5 @@
 #else
     else if( rpcSlice->getVPS()->getIlpSshSignalingEnabledFlag() == false )
-#endif 
+#endif
     {
       rpcSlice->setInterLayerPredEnabledFlag(true);
@@ -2007,4 +2080,8 @@
 
 #if REPN_FORMAT_IN_VPS
+#if O0194_REPN_FORMAT_IN_VPS_BUGFIX
+    g_bitDepthYLayer[rpcSlice->getLayerId()]     = rpcSlice->getBitDepthY();
+    g_bitDepthCLayer[rpcSlice->getLayerId()]     = rpcSlice->getBitDepthC();
+#endif
     assert( rpcSlice->getSliceQp() >= -rpcSlice->getQpBDOffsetY() );
 #else
@@ -2117,5 +2194,5 @@
   {
     Int endOfSliceHeaderLocation = m_pcBitstream->getByteLocation();
-    
+
     // Adjust endOfSliceHeaderLocation to account for emulation prevention bytes in the slice segment header
     for ( UInt curByteIdx  = 0; curByteIdx<m_pcBitstream->numEmulationPreventionBytesRead(); curByteIdx++ )
@@ -2523,5 +2600,5 @@
 #if IL_SL_SIGNALLING_N0371
       if ( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
-      { 
+      {
         READ_FLAG( code, "scaling_list_pred_mode_flag");
         scalingListPredModeFlag = (code) ? true : false;
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCAVLC.h	(revision 466)
@@ -72,5 +72,4 @@
   Void  parseQtRootCbf      ( UInt uiAbsPartIdx, UInt& uiQtRootCbf );
   Void  parseVPS            ( TComVPS* pcVPS );
-#if SPS_EXTENSION
 #if VPS_EXTNS
   Void  parseVPSExtension   ( TComVPS* pcVPS );
@@ -83,9 +82,12 @@
   Void  parseRepFormat      ( RepFormat *repFormat );
 #endif
+#if SPS_SUB_LAYER_INFO
   Void  parseSPS            ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager );
-  Void  parseSPSExtension    ( TComSPS* pcSPS );
-#else //SVC_EXTENSION
+#else
   Void  parseSPS            ( TComSPS* pcSPS );
-#endif //SVC_EXTENSION
+#endif
+#if SPS_EXTENSION
+  Void parseSPSExtension    ( TComSPS* pcSPS );
+#endif
   Void  parsePPS            ( TComPPS* pcPPS);
   Void  parseVUI            ( TComVUI* pcVUI, TComSPS* pcSPS );
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecCu.cpp	(revision 466)
@@ -616,5 +616,13 @@
     curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
   }
+#if O0194_REPN_FORMAT_IN_VPS_BUGFIX
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), eText, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
@@ -768,5 +776,13 @@
   // Cb and Cr
   Int curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCbQpOffset() + pcCU->getSlice()->getSliceQpDeltaCb();
+#if O0194_REPN_FORMAT_IN_VPS_BUGFIX
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   uiWidth  >>= 1;
@@ -776,5 +792,13 @@
 
   curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
+#if O0194_REPN_FORMAT_IN_VPS_BUGFIX
+#if REPN_FORMAT_IN_VPS
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getQpBDOffsetC(), curChromaQpOffset );
+#else
   m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
+#else
+  m_pcTrQuant->setQPforQuant( pcCU->getQP( uiAbsPartIdx ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
+#endif
 
   piCoeff = pcCU->getCoeffCr(); pResi = m_ppcYuvResi[uiDepth]->getCrAddr();
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecEntropy.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecEntropy.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecEntropy.h	(revision 466)
@@ -66,5 +66,5 @@
 
   virtual Void  parseVPS                  ( TComVPS* pcVPS )                       = 0;
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   virtual Void  parseSPS                  ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )           = 0;
 #else
@@ -134,5 +134,5 @@
   Void    resetEntropy                ( TComSlice* p)           { m_pcEntropyDecoderIf->resetEntropy(p);                    }
   Void    decodeVPS                   ( TComVPS* pcVPS ) { m_pcEntropyDecoderIf->parseVPS(pcVPS); }
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   Void    decodeSPS                   ( TComSPS* pcSPS, ParameterSetManagerDecoder *parameterSetManager )    { m_pcEntropyDecoderIf->parseSPS(pcSPS, parameterSetManager);                    }
 #else
Index: branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibDecoder/TDecSbac.h	(revision 466)
@@ -76,5 +76,5 @@
   Void  setBitstream              ( TComInputBitstream* p  ) { m_pcBitstream = p; m_pcTDecBinIf->init( p ); }
   Void  parseVPS                  ( TComVPS* /*pcVPS*/ ) {}
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   Void  parseSPS                  ( TComSPS* /*pcSPS*/, ParameterSetManagerDecoder * /*parameterSetManager*/ ) {}
 #else
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 466)
@@ -359,4 +359,10 @@
   {
     WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
+#if M0464_TILE_BOUNDARY_ALIGNED_FLAG
+    if ( pcSPS->getLayerId() > 0 )
+    {
+      WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
+    }
+#endif
     WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
     WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
@@ -448,5 +454,5 @@
 #endif
   WRITE_CODE( pcSPS->getVPSId (),          4,       "sps_video_parameter_set_id" );
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   if(pcSPS->getLayerId() == 0)
   {
@@ -454,5 +460,5 @@
     WRITE_CODE( pcSPS->getMaxTLayers() - 1,  3,       "sps_max_sub_layers_minus1" );
     WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "sps_temporal_id_nesting_flag" );
-#if SVC_EXTENSION
+#if SPS_SUB_LAYER_INFO
   }
 #endif
@@ -664,4 +670,5 @@
   WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   if( pcSPS->getLayerId() > 0 )
   {
@@ -676,4 +683,5 @@
     }
   }
+#endif
 #if M0463_VUI_EXT_ILP_REF
   ////   sps_extension_vui_parameters( )
@@ -820,5 +828,4 @@
 }
 
-#if SVC_EXTENSION
 #if VPS_EXTNS
 Void TEncCavlc::codeVPSExtension (TComVPS *vps)
@@ -836,5 +843,9 @@
   }
 
+#if VPS_SPLIT_FLAG
   for(j = 0; j < vps->getNumScalabilityTypes() - vps->getSplittingFlag(); j++)
+#else
+  for(j = 0; j < vps->getNumScalabilityTypes(); j++)
+#endif
   {
     WRITE_CODE( vps->getDimensionIdLen(j) - 1, 3,      "dimension_id_len_minus1[j]" );
@@ -860,12 +871,11 @@
       WRITE_CODE( vps->getLayerIdInNuh(i),     6,      "layer_id_in_nuh[i]" );
     }
-
-    if( !vps->getSplittingFlag() )
-    {
-      for(j = 0; j < vps->getNumScalabilityTypes(); j++)
-      {
-        UInt bits = vps->getDimensionIdLen(j);
-        WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
-      }
+#if VPS_SPLIT_FLAG
+    if(!vps->getSplittingFlag())
+#endif
+    for(j = 0; j < vps->getNumScalabilityTypes(); j++)
+    {
+      UInt bits = vps->getDimensionIdLen(j);
+      WRITE_CODE( vps->getDimensionId(i, j),   bits,   "dimension_id[i][j]" );
     }
   }
@@ -883,4 +893,5 @@
   }
 #endif
+#if VPS_MOVE_DIR_DEPENDENCY_FLAG
 #if VPS_EXTN_DIRECT_REF_LAYERS
   for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
@@ -891,4 +902,5 @@
     }
   }
+#endif
 #endif
 #if JCTVC_M0203_INTERLAYER_PRED_IDC
@@ -914,12 +926,20 @@
 #if VPS_EXTN_PROFILE_INFO
   // Profile-tier-level signalling
+#if VPS_PROFILE_OUTPUT_LAYERS
   WRITE_CODE( vps->getNumLayerSets() - 1   , 10, "vps_number_layer_sets_minus1" );     
   WRITE_CODE( vps->getNumProfileTierLevel() - 1,  6, "vps_num_profile_tier_level_minus1"); 
   for(Int idx = 1; idx <= vps->getNumProfileTierLevel() - 1; idx++)
+#else
+  for(Int idx = 1; idx <= vps->getNumLayerSets() - 1; idx++)
+#endif
   {
     WRITE_FLAG( vps->getProfilePresentFlag(idx),       "vps_profile_present_flag[i]" );
     if( !vps->getProfilePresentFlag(idx) )
     {
+#if VPS_PROFILE_OUTPUT_LAYERS
       WRITE_CODE( vps->getProfileLayerSetRef(idx) - 1, 6, "profile_ref_minus1[i]" );
+#else
+      WRITE_UVLC( vps->getProfileLayerSetRef(idx) - 1, "vps_profile_layer_set_ref_minus1[i]" );
+#endif
     }
     codePTL( vps->getPTLForExtn(idx), vps->getProfilePresentFlag(idx), vps->getMaxTLayers() - 1 );
@@ -927,4 +947,5 @@
 #endif
 
+#if VPS_PROFILE_OUTPUT_LAYERS
   Int numOutputLayerSets = vps->getNumOutputLayerSets() ;
   WRITE_FLAG(  (numOutputLayerSets > vps->getNumLayerSets()), "more_output_layer_sets_than_default_flag" ); 
@@ -961,5 +982,28 @@
     WRITE_CODE( vps->getProfileLevelTierIdx(i), numBits, "profile_level_tier_idx[i]" );     
   }
-  
+#else
+#if VPS_EXTN_OP_LAYER_SETS
+  // Target output layer signalling
+  WRITE_UVLC( vps->getNumOutputLayerSets(),            "vps_num_output_layer_sets");
+  for(i = 0; i < vps->getNumOutputLayerSets(); i++)
+  {
+#if VPS_OUTPUT_LAYER_SET_IDX
+    assert(vps->getOutputLayerSetIdx(i) > 0);
+    WRITE_UVLC( vps->getOutputLayerSetIdx(i) - 1,           "vps_output_layer_set_idx_minus1[i]");
+#else
+    WRITE_UVLC( vps->getOutputLayerSetIdx(i),           "vps_output_layer_set_idx[i]");
+#endif
+    Int lsIdx = vps->getOutputLayerSetIdx(i);
+    for(j = 0; j <= vps->getMaxLayerId(); j++)
+    {
+      if(vps->getLayerIdIncludedFlag(lsIdx, j))
+      {
+        WRITE_FLAG( vps->getOutputLayerFlag(lsIdx, j), "vps_output_layer_flag[lsIdx][j]");
+      }
+    }
+  }
+#endif
+#endif
+
 #if REPN_FORMAT_IN_VPS
   WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag"); 
@@ -988,5 +1032,5 @@
 
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
-  WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
+      WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
 #endif 
 #if O0215_PHASE_ALIGNMENT
@@ -994,6 +1038,17 @@
 #endif
 #if N0147_IRAP_ALIGN_FLAG
-  WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
+      WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
 #endif 
+#if !VPS_MOVE_DIR_DEPENDENCY_FLAG
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  for( Int layerCtr = 1; layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    for( Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      WRITE_FLAG(vps->getDirectDependencyFlag(layerCtr, refLayerCtr), "direct_dependency_flag[i][j]" );
+    }
+  }
+#endif
+#endif
 #if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
   WRITE_UVLC( vps->getDirectDepTypeLen()-2,                           "direct_dep_type_len_minus2");
@@ -1129,5 +1184,4 @@
 }
 #endif
-#endif //SVC_EXTENSION
 
 Void TEncCavlc::codeSliceHeader         ( TComSlice* pcSlice )
@@ -1175,5 +1229,5 @@
   if ( !pcSlice->getDependentSliceSegmentFlag() )
   {
-#if SVC_EXTENSION
+
 #if POC_RESET_FLAG
     Int iBits = 0;
@@ -1195,4 +1249,5 @@
     }
 #else
+#if SH_DISCARDABLE_FLAG
     if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     {
@@ -1205,6 +1260,5 @@
       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     }
-#endif
-#else //SVC_EXTENSION
+#else
     for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     {
@@ -1212,5 +1266,6 @@
       WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     }
-#endif //SVC_EXTENSION
+#endif
+#endif
 
     WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 466)
@@ -753,9 +753,10 @@
     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
 #if SVC_EXTENSION
+#if ILR_RESTR && ILR_RESTR_FIX
+    Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
+    Int activeNumILRRefIdxTmp = 0;
+#endif
     if (m_layerId > 0)
     {
-      Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
-      Int activeNumILRRefIdxTmp = 0;
-
       for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
       {
@@ -768,4 +769,5 @@
         pcSlice->setBaseColPic( *cListPic, refLayerIdc );
 
+#if ILR_RESTR && ILR_RESTR_FIX
         // Apply temporal layer restriction to inter-layer prediction
         Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId());
@@ -778,5 +780,7 @@
           continue; // ILP is not valid due to temporal layer restriction
         }
-
+#endif
+
+#if SCALED_REF_LAYER_OFFSETS
         const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
 
@@ -786,5 +790,14 @@
         Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
         Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-
+#else
+        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getConformanceWindow();
+        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
         g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
         g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
@@ -810,4 +823,5 @@
       }
 
+#if ILR_RESTR && ILR_RESTR_FIX
       // Update the list of active inter-layer pictures
       for ( Int i = 0; i < activeNumILRRefIdxTmp; i++)
@@ -821,4 +835,5 @@
         pcSlice->setInterLayerPredEnabledFlag(false);
       }
+#endif
       
       if( pocCurr % m_pcCfg->getIntraPeriod() == 0 )
@@ -1601,8 +1616,4 @@
           pcSlice->setSliceSegmentCurStartCUAddr  ( startCUAddrSlice      );
           pcSlice->setSliceBits(0);
-#if SVC_EXTENSION
-          // copy reference list modification info from the first slice, assuming that this information is the same across all slices in the picture
-          memcpy( pcSlice->getRefPicListModification(), pcPic->getSlice(0)->getRefPicListModification(), sizeof(TComRefPicListModification) );
-#endif
           uiNumSlices ++;
         }
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 466)
@@ -4119,5 +4119,10 @@
 
   // prediction pattern
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Bug Fix (It did not check WP for BSlices)
+  if ( pcCU->getSlice()->getPPS()->getUseWP())
+#else
   if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE )
+#endif
   {
     xPredInterLumaBlk( pcCU, pcPicYuvRef, uiPartAddr, &cMvCand, iSizeX, iSizeY, pcTemplateCand, true );
@@ -4128,5 +4133,10 @@
   }
 
+#if O0194_WEIGHTED_PREDICTION_CGS
+  if ( pcCU->getSlice()->getPPS()->getUseWP())
+  ///< Bug Fix (It did not check WP for BSlices)
+#else
   if ( pcCU->getSlice()->getPPS()->getUseWP() && pcCU->getSlice()->getSliceType()==P_SLICE )
+#endif
   {
     xWeightedPredictionUni( pcCU, pcTemplateCand, uiPartAddr, iSizeX, iSizeY, eRefPicList, pcTemplateCand, iRefIdx );
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 466)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -51,5 +51,5 @@
   m_apcPicYuvPred = NULL;
   m_apcPicYuvResi = NULL;
-  
+
   m_pdRdPicLambda = NULL;
   m_pdRdPicQp     = NULL;
@@ -69,12 +69,12 @@
 }
 
-Void TEncSlice::initCtxMem(  UInt i )                
-{   
+Void TEncSlice::initCtxMem(  UInt i )
+{
   for (std::vector<TEncSbac*>::iterator j = CTXMem.begin(); j != CTXMem.end(); j++)
   {
     delete (*j);
   }
-  CTXMem.clear(); 
-  CTXMem.resize(i); 
+  CTXMem.clear();
+  CTXMem.resize(i);
 }
 
@@ -87,5 +87,5 @@
     m_apcPicYuvPred->create( iWidth, iHeight, iMaxCUWidth, iMaxCUHeight, uhTotalDepth );
   }
-  
+
   // create residual picture
   if( m_apcPicYuvResi == NULL )
@@ -105,5 +105,5 @@
     m_apcPicYuvPred  = NULL;
   }
-  
+
   // destroy residual picture
   if ( m_apcPicYuvResi )
@@ -113,5 +113,5 @@
     m_apcPicYuvResi  = NULL;
   }
-  
+
   // free lambda and QP arrays
   if ( m_pdRdPicLambda ) { xFree( m_pdRdPicLambda ); m_pdRdPicLambda = NULL; }
@@ -139,9 +139,9 @@
 #if SVC_EXTENSION
   m_ppcTEncTop        = pcEncTop->getLayerEnc();
-#endif  
+#endif
   m_pcGOPEncoder      = pcEncTop->getGOPEncoder();
   m_pcCuEncoder       = pcEncTop->getCuEncoder();
   m_pcPredSearch      = pcEncTop->getPredSearch();
-  
+
   m_pcEntropyCoder    = pcEncTop->getEntropyCoder();
   m_pcCavlcCoder      = pcEncTop->getCavlcCoder();
@@ -149,10 +149,10 @@
   m_pcBinCABAC        = pcEncTop->getBinCABAC();
   m_pcTrQuant         = pcEncTop->getTrQuant();
-  
+
   m_pcBitCounter      = pcEncTop->getBitCounter();
   m_pcRdCost          = pcEncTop->getRdCost();
   m_pppcRDSbacCoder   = pcEncTop->getRDSbacCoder();
   m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
-  
+
   // create lambda and QP arrays
   m_pdRdPicLambda     = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
@@ -187,5 +187,5 @@
   Double dQP;
   Double dLambda;
-  
+
   rpcSlice = pcPic->getSlice(0);
   rpcSlice->setSPS( pSPS );
@@ -202,5 +202,5 @@
   rpcSlice->setPicOutputFlag( true );
   rpcSlice->setPOC( pocCurr );
-  
+
   // depth computation based on GOP size
   Int depth;
@@ -230,17 +230,17 @@
     }
   }
-  
+
   // slice type
   SliceType eSliceType;
-  
+
   eSliceType=B_SLICE;
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
-  
+
   rpcSlice->setSliceType    ( eSliceType );
-  
+
   // ------------------------------------------------------------------------------------------------------------------
   // Non-referenced frame marking
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   if(pocLast == 0)
   {
@@ -252,16 +252,16 @@
   }
   rpcSlice->setReferenced(true);
-  
+
   // ------------------------------------------------------------------------------------------------------------------
   // QP setting
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   dQP = m_pcCfg->getQP();
   if(eSliceType!=I_SLICE)
   {
 #if REPN_FORMAT_IN_VPS
-    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
-#else
-    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless()))) 
+    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
+#else
+    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
 #endif
     {
@@ -269,5 +269,5 @@
     }
   }
-  
+
   // modify QP
   Int* pdQPs = m_pcCfg->getdQPs();
@@ -285,5 +285,5 @@
   // Lambda computation
   // ------------------------------------------------------------------------------------------------------------------
-  
+
   Int iQP;
   Double dOrigQP = dQP;
@@ -294,5 +294,5 @@
     // compute QP value
     dQP = dOrigQP + ((iDQpIdx+1)>>1)*(iDQpIdx%2 ? -1 : 1);
-    
+
     // compute lambda value
     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
@@ -326,5 +326,5 @@
 #endif
     }
-    
+
     // if hadamard is used in ME process
     if ( !m_pcCfg->getUseHADME() && rpcSlice->getSliceType( ) != I_SLICE )
@@ -332,5 +332,5 @@
       dLambda *= 0.95;
     }
-    
+
 #if REPN_FORMAT_IN_VPS
     iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
@@ -343,10 +343,10 @@
     m_piRdPicQp    [iDQpIdx] = iQP;
   }
-  
+
   // obtain dQP = 0 case
   dLambda = m_pdRdPicLambda[0];
   dQP     = m_pdRdPicQp    [0];
   iQP     = m_piRdPicQp    [0];
-  
+
   if( rpcSlice->getSliceType( ) != I_SLICE )
   {
@@ -359,5 +359,5 @@
     Int nCurLayer = rpcSlice->getLayerId();
     Double gamma = xCalEnhLambdaFactor( m_ppcTEncTop[nCurLayer-1]->getQP() - m_ppcTEncTop[nCurLayer]->getQP() ,
-      1.0 * m_ppcTEncTop[nCurLayer]->getSourceWidth() * m_ppcTEncTop[nCurLayer]->getSourceHeight() 
+      1.0 * m_ppcTEncTop[nCurLayer]->getSourceWidth() * m_ppcTEncTop[nCurLayer]->getSourceHeight()
       / m_ppcTEncTop[nCurLayer-1]->getSourceWidth() / m_ppcTEncTop[nCurLayer-1]->getSourceHeight() );
     dLambda *= gamma;
@@ -392,7 +392,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
 // for RDOQ
-  m_pcTrQuant->setLambda( dLambda, dLambda / weight );    
+  m_pcTrQuant->setLambda( dLambda, dLambda / weight );
 #else
   m_pcTrQuant->setLambda( dLambda );
@@ -401,13 +401,13 @@
 #if SAO_CHROMA_LAMBDA
 // For SAO
-  rpcSlice   ->setLambda( dLambda, dLambda / weight );  
+  rpcSlice   ->setLambda( dLambda, dLambda / weight );
 #else
   rpcSlice   ->setLambda( dLambda );
 #endif
-  
+
 #if HB_LAMBDA_FOR_LDC
   // restore original slice type
   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
-  
+
 #if SVC_EXTENSION
   if(m_pcCfg->getLayerId() > 0)
@@ -418,12 +418,12 @@
   rpcSlice->setSliceType        ( eSliceType );
 #endif
-  
+
   if (m_pcCfg->getUseRecalculateQPAccordingToLambda())
   {
     dQP = xGetQPValueAccordingToLambda( dLambda );
 #if REPN_FORMAT_IN_VPS
-    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
-#else
-    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );    
+    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
+#else
+    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
 #endif
   }
@@ -438,5 +438,5 @@
   rpcSlice->setNumRefIdx(REF_PIC_LIST_0,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
   rpcSlice->setNumRefIdx(REF_PIC_LIST_1,m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive);
-  
+
   if ( m_pcCfg->getDeblockingFilterMetric() )
   {
@@ -479,5 +479,5 @@
 
   rpcSlice->setDepth            ( depth );
-  
+
   pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
 #if TEMP_SCALABILITY_FIX
@@ -493,5 +493,5 @@
   assert( m_apcPicYuvPred );
   assert( m_apcPicYuvResi );
-  
+
   pcPic->setPicYuvPred( m_apcPicYuvPred );
   pcPic->setPicYuvResi( m_apcPicYuvResi );
@@ -557,5 +557,5 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
   // for RDOQ
   m_pcTrQuant->setLambda( lambda, lambda / weight );
@@ -665,7 +665,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
   // for RDOQ
-  m_pcTrQuant->setLambda( lambda, lambda / weight );    
+  m_pcTrQuant->setLambda( lambda, lambda / weight );
 #else
   m_pcTrQuant->setLambda( lambda );
@@ -674,5 +674,5 @@
 #if SAO_CHROMA_LAMBDA
   // For SAO
-  pcSlice   ->setLambda( lambda, lambda / weight );  
+  pcSlice   ->setLambda( lambda, lambda / weight );
 #else
   pcSlice   ->setLambda( lambda );
@@ -692,5 +692,5 @@
   Int iMaxSR = m_pcCfg->getSearchRange();
   Int iNumPredDir = pcSlice->isInterP() ? 1 : 2;
- 
+
   for (Int iDir = 0; iDir <= iNumPredDir; iDir++)
   {
@@ -726,9 +726,9 @@
   }
 #endif
-  
+
   TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
   Double     dPicRdCostBest = MAX_DOUBLE;
   UInt       uiQpIdxBest = 0;
-  
+
   Double dFrameLambda;
 #if FULL_NBIT
@@ -737,5 +737,5 @@
   Int    SHIFT_QP = 12;
 #endif
-  
+
   // set frame lambda
   if (m_pcCfg->getGOPSize() > 1)
@@ -748,5 +748,5 @@
   }
   m_pcRdCost      ->setFrameLambda(dFrameLambda);
-  
+
   // for each QP candidate
   for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
@@ -776,5 +776,5 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
+#if RDOQ_CHROMA_LAMBDA
     // for RDOQ
     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
@@ -784,21 +784,21 @@
 #if SAO_CHROMA_LAMBDA
     // For SAO
-    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 
+    pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
 #else
     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
 #endif
-    
+
     // try compress
     compressSlice   ( rpcPic );
-    
+
     Double dPicRdCost;
     UInt64 uiPicDist        = m_uiPicDist;
     UInt64 uiALFBits        = 0;
-    
+
     m_pcGOPEncoder->preLoopFilterPicAll( rpcPic, uiPicDist, uiALFBits );
-    
+
     // compute RD cost and choose the best
     dPicRdCost = m_pcRdCost->calcRdCost64( m_uiPicTotalBits + uiALFBits, uiPicDist, true, DF_SSE_FRAME);
-    
+
     if ( dPicRdCost < dPicRdCostBest )
     {
@@ -807,5 +807,5 @@
     }
   }
-  
+
   // set best values
   pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdxBest] );
@@ -832,7 +832,7 @@
 #endif
 
-#if RDOQ_CHROMA_LAMBDA 
-  // for RDOQ 
-  m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 
+#if RDOQ_CHROMA_LAMBDA
+  // for RDOQ
+  m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
 #else
   m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
@@ -840,5 +840,5 @@
 #if SAO_CHROMA_LAMBDA
   // For SAO
-  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 
+  pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
 #else
   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
@@ -862,5 +862,5 @@
 
   UInt uiEncCUOrder;
-  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); 
+  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
   for( uiEncCUOrder = uiStartCUAddr/rpcPic->getNumPartInCU();
        uiEncCUOrder < (uiBoundingCUAddr+(rpcPic->getNumPartInCU()-1))/rpcPic->getNumPartInCU();
@@ -898,10 +898,10 @@
   TComSlice* pcSlice            = rpcPic->getSlice(getSliceIdx());
   xDetermineStartAndBoundingCUAddr ( uiStartCUAddr, uiBoundingCUAddr, rpcPic, false );
-  
+
   // initialize cost values
   m_uiPicTotalBits  = 0;
   m_dPicRdCost      = 0;
   m_uiPicDist       = 0;
-  
+
   // set entropy coder
   if( m_pcCfg->getUseSBACRD() )
@@ -921,5 +921,5 @@
     m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
   }
-  
+
   //------------------------------------------------------------------------------
   //  Weighted Prediction parameters estimation.
@@ -930,4 +930,14 @@
     xCalcACDCParamSlice(pcSlice);
   }
+#if O0194_WEIGHTED_PREDICTION_CGS
+  else{
+    // Calculate for the base layer to be used in EL as Inter layer reference
+    xCalcACDCParamSlice(pcSlice);
+    wpACDCParam * temp_weightACDCParam;
+
+    pcSlice->getWpAcDcParam(temp_weightACDCParam);
+    g_refWeightACDCParam = (void *) temp_weightACDCParam;
+  }
+#endif
 
   Bool bWp_explicit = (pcSlice->getSliceType()==P_SLICE && pcSlice->getPPS()->getUseWP()) || (pcSlice->getSliceType()==B_SLICE && pcSlice->getPPS()->getWPBiPred());
@@ -1021,5 +1031,5 @@
         m_pcBufferSbacCoders[uiTileCol].loadContexts( CTXMem[1] );
         Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
-        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); 
+        uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
         uiLin     = uiCUAddr / uiWidthInLCUs;
         uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(rpcPic->getPicSym()->getCUOrderMap(uiCUAddr))*iNumSubstreamsPerTile
@@ -1098,5 +1108,5 @@
           pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
         }
-        if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || 
+        if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
@@ -1137,5 +1147,5 @@
       m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
       m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
-      
+
       ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
 
@@ -1242,5 +1252,5 @@
         m_pcRdCost->setLambda(oldLambda);
 #if RATE_CONTROL_INTRA
-        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
 #else
@@ -1250,5 +1260,5 @@
 #endif
 #endif
-      
+
       // restore entropy coder to an initial stage
       m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
@@ -1275,5 +1285,5 @@
       {
          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
-       
+
          //Store probabilties of second LCU in line into buffer
          if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
@@ -1325,5 +1335,5 @@
 
 #if RATE_CONTROL_INTRA
-        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 
+        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
 #else
@@ -1350,5 +1360,5 @@
       }
     }
-    
+
     m_uiPicTotalBits += pcCU->getTotalBits();
     m_dPicRdCost     += pcCU->getTotalCost();
@@ -1401,5 +1411,5 @@
     m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
   }
-  
+
   m_pcCuEncoder->setBitCounter( NULL );
   m_pcBitCounter = NULL;
@@ -1427,5 +1437,5 @@
       m_pcBufferSbacCoders[ui].load(m_pcSbacCoder); //init. state
     }
-    
+
     for (Int iSubstrmIdx=0; iSubstrmIdx < iNumSubstreams; iSubstrmIdx++)
     {
@@ -1524,5 +1534,5 @@
         }
         if ( (true/*bEnforceSliceRestriction*/ &&
-             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) || 
+             ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
@@ -1579,5 +1589,5 @@
     }
 
-    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );    
+    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
     {
@@ -1613,5 +1623,5 @@
         if (allowMergeLeft)
         {
-          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft); 
+          m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
         }
         else
@@ -1676,9 +1686,9 @@
 #if ENC_DEC_TRACE
     g_bJustDoIt = g_bEncDecTraceDisable;
-#endif    
+#endif
     if( m_pcCfg->getUseSBACRD() )
     {
        pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
-       
+
 
        //Store probabilties of second LCU in line into buffer
@@ -1733,5 +1743,5 @@
   UInt uiNumberOfCUsInFrame = rpcPic->getNumCUsInFrame();
   uiBoundingCUAddrSlice     = uiNumberOfCUsInFrame;
-  if (bEncodeSlice) 
+  if (bEncodeSlice)
   {
     UInt uiCUAddrIncrement;
@@ -1769,5 +1779,5 @@
       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1809,5 +1819,5 @@
       uiBoundingCUAddrSlice    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (uiStartCUAddrSlice % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1819,5 +1829,5 @@
 
   Bool tileBoundary = false;
-  if ((m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_BYTES) && 
+  if ((m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceMode() == FIXED_NUMBER_OF_BYTES) &&
       (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
   {
@@ -1832,5 +1842,5 @@
     }
     tileBoundingCUAddrSlice = lcuEncAddr*rpcPic->getNumPartInCU();
-    
+
     if (tileBoundingCUAddrSlice < uiBoundingCUAddrSlice)
     {
@@ -1845,5 +1855,5 @@
   startCUAddrSliceSegment    = pcSlice->getSliceSegmentCurStartCUAddr();
   boundingCUAddrSliceSegment = uiNumberOfCUsInFrame;
-  if (bEncodeSlice) 
+  if (bEncodeSlice)
   {
     UInt uiCUAddrIncrement;
@@ -1880,5 +1890,5 @@
       boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1919,5 +1929,5 @@
       boundingCUAddrSliceSegment    = uiNumberOfCUsInFrame*rpcPic->getNumPartInCU();
       break;
-    } 
+    }
     // WPP: if a slice segment does not start at the beginning of a CTB row, it must end within the same CTB row
     if (pcSlice->getPPS()->getNumSubstreams() > 1 && (startCUAddrSliceSegment % (rpcPic->getFrameWidthInCU()*rpcPic->getNumPartInCU()) != 0))
@@ -1927,5 +1937,5 @@
     pcSlice->setSliceSegmentCurEndCUAddr( boundingCUAddrSliceSegment );
   }
-  if ((m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES) && 
+  if ((m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_LCU || m_pcCfg->getSliceSegmentMode() == FIXED_NUMBER_OF_BYTES) &&
     (m_pcCfg->getNumRowsMinus1() > 0 || m_pcCfg->getNumColumnsMinus1() > 0))
   {
@@ -1979,8 +1989,8 @@
   }
   UInt uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
-  
+
   pcSlice->setSliceSegmentCurStartCUAddr(uiRealStartAddress);
   startCUAddrSliceSegment=uiRealStartAddress;
-  
+
   //calculate real slice start address
   uiInternalAddress = rpcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceCurStartCUAddr()) % rpcPic->getNumPartInCU();
@@ -2007,8 +2017,8 @@
   }
   uiRealStartAddress = rpcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*rpcPic->getNumPartInCU()+uiInternalAddress);
-  
+
   pcSlice->setSliceCurStartCUAddr(uiRealStartAddress);
   uiStartCUAddrSlice=uiRealStartAddress;
-  
+
   // Make a joint decision based on reconstruction and dependent slice bounds
   startCUAddr    = max(uiStartCUAddrSlice   , startCUAddrSliceSegment   );
@@ -2022,7 +2032,7 @@
     if ( (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
       || (m_pcCfg->getSliceMode()==0 && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
-      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0) 
+      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU && m_pcCfg->getSliceSegmentMode()==0)
       || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)
-      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0) 
+      || (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceSegmentMode()==0)
       || (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_TILES && m_pcCfg->getSliceMode()==0)
       || tileBoundary
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 466)
@@ -88,9 +88,11 @@
   m_bMFMEnabledFlag = false;
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   m_numScaledRefLayerOffsets = 0;
+#endif
+#endif
 #if POC_RESET_FLAG
   m_pocAdjustmentValue     = 0;
 #endif
-#endif //SVC_EXTENSION
 }
 
@@ -173,11 +175,4 @@
     }
   }
-
-#if LAYER_CTB
-  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
-  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
-  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
-  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
-#endif
 }
 
@@ -876,4 +871,5 @@
 #if SVC_EXTENSION
   m_cSPS.setLayerId(m_layerId);
+#endif
 #if REF_IDX_MFM
 #if !M0457_COL_PICTURE_SIGNALING
@@ -881,4 +877,5 @@
 #endif
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
   for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
@@ -886,5 +883,5 @@
     m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
   }
-#endif //SVC_EXTENSION
+#endif
   ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
   profileTierLevel.setLevelIdc(m_level);
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.h
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/TEncTop.h	(revision 466)
@@ -140,10 +140,12 @@
   Int                     m_ilSampleOnlyPred;
 #endif
+#if SCALED_REF_LAYER_OFFSETS
   UInt                    m_numScaledRefLayerOffsets;
   Window                  m_scaledRefLayerWindow[MAX_LAYERS];
+#endif
 #if POC_RESET_FLAG
   Int                     m_pocAdjustmentValue;
 #endif
-#endif //SVC_EXTENSION
+#endif
 protected:
   Void  xGetNewPicBuffer  ( TComPic*& rpcPic );           ///< get picture buffer which will be processed
@@ -207,8 +209,10 @@
   Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
   Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
+#if SCALED_REF_LAYER_OFFSETS
   Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
   UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
   Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
-#endif //SVC_EXTENSION
+#endif
+#endif
 
   // -------------------------------------------------------------------------------------------------------------------
Index: branches/SHM-4.0-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
===================================================================
--- branches/SHM-4.0-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 465)
+++ branches/SHM-4.0-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp	(revision 466)
@@ -2,5 +2,5 @@
  * License, included below. This software may be subject to other third party
  * and contributor rights, including patent rights, and no such rights are
- * granted under this license.  
+ * granted under this license.
  *
  * Copyright (c) 2010-2013, ITU/ISO/IEC
@@ -51,5 +51,5 @@
   for ( Int iList =0 ; iList<2 ; iList++ )
   {
-    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
     {
       for ( Int comp=0 ; comp<3 ;comp++ )
@@ -74,4 +74,8 @@
   TComPicYuv*   pPic = slice->getPic()->getPicYuvOrg();
   Int   iSample  = 0;
+#if O0194_WEIGHTED_PREDICTION_CGS
+  // Define here to assign the parameter of "iSample"
+  wpACDCParam weightACDCParam[3];
+#endif
 
   // calculate DC/AC value for Y
@@ -81,4 +85,7 @@
   pOrg = pPic->getLumaAddr();
   Int64  iOrgACY  = xCalcACValueSlice(slice, pOrg, iOrgNormDCY);
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[0].iSamples = iSample;
+#endif
 
   // calculate DC/AC value for Cb
@@ -88,4 +95,7 @@
   pOrg = pPic->getCbAddr();
   Int64  iOrgACCb  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCb);
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[1].iSamples = iSample;
+#endif
 
   // calculate DC/AC value for Cr
@@ -95,6 +105,11 @@
   pOrg = pPic->getCrAddr();
   Int64  iOrgACCr  = xCalcACValueUVSlice(slice, pOrg, iOrgNormDCCr);
-
+#if O0194_WEIGHTED_PREDICTION_CGS
+  weightACDCParam[2].iSamples = iSample;
+#endif
+
+#if !O0194_WEIGHTED_PREDICTION_CGS
   wpACDCParam weightACDCParam[3];
+#endif
   weightACDCParam[0].iAC = iOrgACY;
   weightACDCParam[0].iDC = iOrgNormDCY;
@@ -138,7 +153,7 @@
   for ( Int iList=0 ; iList<2 ; iList++ )
   {
-    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
-    {
-      for ( Int iComp=0 ; iComp<3 ;iComp++ ) 
+    for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
+    {
+      for ( Int iComp=0 ; iComp<3 ;iComp++ )
       {
         wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
@@ -154,7 +169,7 @@
     for ( Int iList=0 ; iList<2 ; iList++ )
     {
-      for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) 
+      for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )
       {
-        for ( Int iComp=0 ; iComp<3 ;iComp++ ) 
+        for ( Int iComp=0 ; iComp<3 ;iComp++ )
         {
           wpScalingParam  *pwp = &(m_wp[iList][iRefIdx][iComp]);
@@ -195,5 +210,5 @@
   // selecting whether WP is used, or not
   xSelectWP(slice, m_wp, iDenom);
-  
+
   slice->setWpScaling( m_wp );
 
@@ -216,4 +231,9 @@
       slice->getWpAcDcParam(currWeightACDCParam);
       slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam);
+#if O0194_WEIGHTED_PREDICTION_CGS
+      if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(1)){
+        refWeightACDCParam = (wpACDCParam *)g_refWeightACDCParam;
+      }
+#endif
 
       for ( Int comp = 0; comp < 3; comp++ )
@@ -229,4 +249,13 @@
         Int64 refDC = refWeightACDCParam[comp].iDC;
         Int64 refAC = refWeightACDCParam[comp].iAC;
+#if O0194_WEIGHTED_PREDICTION_CGS
+        if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(1)){
+          refAC *= (double)currWeightACDCParam[comp].iSamples/refWeightACDCParam[comp].iSamples;
+#if O0194_JOINT_US_BITSHIFT
+          refAC *= (1<<(g_bitDepthYLayer[1]-g_bitDepthYLayer[0]));
+          refDC *= (1<<(g_bitDepthYLayer[1]-g_bitDepthYLayer[0]));
+#endif
+         }
+#endif
 
         // calculating iWeight and iOffset params
@@ -234,4 +263,13 @@
         Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
         Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom );
+#if O0194_WEIGHTED_PREDICTION_CGS
+        if (slice->getRefPic(eRefPicList, refIdxTemp)->isILR(1)){
+        }
+        else{
+          dWeight = 1;
+          offset  = 0;
+        }
+        weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) );
+#endif
 
         // Chroma offset range limitation
@@ -253,4 +291,10 @@
         if(deltaWeight > 127 || deltaWeight < -128)
           return (false);
+#if O0194_WEIGHTED_PREDICTION_CGS
+        // make sure the reference frames other than ILR are not using weighted prediction
+        if (!(slice->getRefPic(eRefPicList, refIdxTemp)->isILR(1))){
+          continue;
+        }
+#endif
 
         m_wp[refList][refIdxTemp][comp].bPresentFlag = true;
@@ -264,5 +308,5 @@
 }
 
-/** select whether weighted pred enables or not. 
+/** select whether weighted pred enables or not.
  * \param TComSlice *slice
  * \param wpScalingParam
@@ -325,5 +369,5 @@
 }
 
-/** calculate DC value of original image for luma. 
+/** calculate DC value of original image for luma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -345,5 +389,5 @@
 }
 
-/** calculate AC value of original image for luma. 
+/** calculate AC value of original image for luma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -363,5 +407,5 @@
 }
 
-/** calculate DC value of original image for chroma. 
+/** calculate DC value of original image for chroma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -383,5 +427,5 @@
 }
 
-/** calculate AC value of original image for chroma. 
+/** calculate AC value of original image for chroma.
  * \param TComSlice *slice
  * \param Pel *pPel
@@ -401,5 +445,5 @@
 }
 
-/** calculate DC value. 
+/** calculate DC value.
  * \param Pel *pPel
  * \param Int iWidth
@@ -423,5 +467,5 @@
 }
 
-/** calculate AC value. 
+/** calculate AC value.
  * \param Pel *pPel
  * \param Int iWidth
@@ -446,5 +490,5 @@
 }
 
-/** calculate SAD values for both WP version and non-WP version. 
+/** calculate SAD values for both WP version and non-WP version.
  * \param Pel *pOrgPel
  * \param Pel *pRefPel
