Index: trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 655)
+++ trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 872)
@@ -4,5 +4,5 @@
  * granted under this license.  
  *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
+* Copyright (c) 2010-2014, ITU/ISO/IEC
  * All rights reserved.
  *
@@ -42,6 +42,4 @@
 using namespace std;
 
-#if RATE_CONTROL_LAMBDA_DOMAIN
-
 //sequence level
 TEncRCSeq::TEncRCSeq()
@@ -67,8 +65,6 @@
   m_bitsLeft            = 0;
   m_useLCUSeparateModel = false;
-#if M0036_RC_IMPROVEMENT
   m_adaptiveBit         = 0;
   m_lastLambda          = 0.0;
-#endif
 }
 
@@ -78,9 +74,5 @@
 }
 
-#if M0036_RC_IMPROVEMENT
 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
-#else
-Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
-#endif
 {
   destroy();
@@ -109,5 +101,4 @@
     m_betaUpdate  = 0.025;
   }
-#if M0036_RC_IMPROVEMENT
   else if ( m_seqTargetBpp < 0.2 )
   {
@@ -125,11 +116,4 @@
     m_betaUpdate  = 0.2;
   }
-#else
-  else
-  {
-    m_alphaUpdate = 0.1;
-    m_betaUpdate  = 0.05;
-  }
-#endif
   m_averageBits     = (Int)(m_targetBits / totalFrames);
   Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
@@ -172,8 +156,6 @@
   m_framesLeft = m_totalFrames;
   m_bitsLeft   = m_targetBits;
-#if M0036_RC_IMPROVEMENT
   m_adaptiveBit = adaptiveBit;
   m_lastLambda = 0.0;
-#endif
 }
 
@@ -233,5 +215,4 @@
     for ( Int i=0; i<m_numberOfLevel; i++ )
     {
-#if RATE_CONTROL_INTRA
       if (i>0)
       {
@@ -244,8 +225,4 @@
         m_picPara[i].m_beta  = BETA2;
       }
-#else
-      m_picPara[i].m_alpha = 3.2003;
-      m_picPara[i].m_beta  = -1.367;
-#endif
     }
   }
@@ -271,11 +248,6 @@
       for ( Int j=0; j<m_numberOfLCU; j++)
       {
-#if RATE_CONTROL_INTRA
         m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
         m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
-#else
-        m_LCUPara[i][j].m_alpha = 3.2003;
-        m_LCUPara[i][j].m_beta  = -1.367;
-#endif
       }
     }
@@ -299,21 +271,4 @@
 }
 
-#if !RATE_CONTROL_INTRA
-Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
-{
-  Double bpp = ( (Double)orgBits ) / m_picHeight / m_picHeight;
-  if ( bpp > 0.2 )
-  {
-    return orgBits * 5;
-  }
-  if ( bpp > 0.1 )
-  {
-    return orgBits * 7;
-  }
-  return orgBits * 10;
-}
-#endif
-
-#if M0036_RC_IMPROVEMENT
 Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
 {
@@ -326,5 +281,4 @@
   delete[] bitsRatio;
 }
-#endif
 
 //GOP level
@@ -349,5 +303,4 @@
   Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
 
-#if M0036_RC_IMPROVEMENT
   if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
   {
@@ -409,5 +362,4 @@
     delete []equaCoeffB;
   }
-#endif
 
   m_picTargetBitInGOP = new Int[numPic];
@@ -422,9 +374,5 @@
   {
     currPicRatio = encRCSeq->getBitRatio( i );
-#if M0036_RC_IMPROVEMENT
     m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
-#else
-    m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
-#endif
   }
 
@@ -436,5 +384,4 @@
 }
 
-#if M0036_RC_IMPROVEMENT
 Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
 {
@@ -482,5 +429,4 @@
   return solution;
 }
-#endif
 
 Void TEncRCGOP::destroy()
@@ -534,8 +480,4 @@
 
   m_LCUs         = NULL;
-#if !M0036_RC_IMPROVEMENT
-  m_lastPicture  = NULL;
-#endif
-
 #if KWU_RC_MADPRED_E0227
   m_lastIVPicture = NULL;
@@ -543,7 +485,4 @@
 
   m_picActualHeaderBits = 0;
-#if !M0036_RC_IMPROVEMENT
-  m_totalMAD            = 0.0;
-#endif
   m_picActualBits       = 0;
   m_picQP               = 0;
@@ -574,9 +513,5 @@
   }
 
-#if M0036_RC_IMPROVEMENT
   targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
-#else
-  targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
-#endif
 
   if ( targetBits < 100 )
@@ -691,9 +626,5 @@
       m_LCUs[LCUIdx].m_lambda     = 0.0;
       m_LCUs[LCUIdx].m_targetBits = 0;
-#if M0036_RC_IMPROVEMENT
       m_LCUs[LCUIdx].m_bitWeight  = 1.0;
-#else
-      m_LCUs[LCUIdx].m_MAD        = 0.0;
-#endif
       Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
       Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
@@ -708,7 +639,4 @@
   }
   m_picActualHeaderBits = 0;
-#if !M0036_RC_IMPROVEMENT
-  m_totalMAD            = 0.0;
-#endif
   m_picActualBits       = 0;
   m_picQP               = 0;
@@ -723,17 +651,4 @@
 
 
-#if !M0036_RC_IMPROVEMENT
-  m_lastPicture = NULL;
-  list<TEncRCPic*>::reverse_iterator it;
-  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
-  {
-    if ( (*it)->getFrameLevel() == m_frameLevel )
-    {
-      m_lastPicture = (*it);
-      break;
-    }
-  }
-#endif
-
 #if KWU_RC_MADPRED_E0227
   list<TEncRCPic*>::reverse_iterator it;
@@ -775,14 +690,9 @@
 
 
-#if RATE_CONTROL_INTRA
 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
-#else
-Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
-#endif
 {
   Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
   Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
   Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
-#if RATE_CONTROL_INTRA
   Double estLambda;
   if (eSliceType == I_SLICE)
@@ -794,7 +704,4 @@
     estLambda = alpha * pow( bpp, beta );
   }
-#else
-  Double estLambda = alpha * pow( bpp, beta );
-#endif  
   
   Double lastLevelLambda = -1.0;
@@ -844,10 +751,8 @@
   m_estPicLambda = estLambda;
 
-#if M0036_RC_IMPROVEMENT
   Double totalWeight = 0.0;
   // initial BU bit allocation weight
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
-#if RC_FIX
     Double alphaLCU, betaLCU;
     if ( m_encRCSeq->getUseLCUSeparateModel() )
@@ -861,8 +766,4 @@
       betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     }
-#else
-    Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
-    Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
-#endif
 
     m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
@@ -879,5 +780,4 @@
     m_LCUs[i].m_bitWeight = BUTargetBits;
   }
-#endif
 
   return estLambda;
@@ -989,9 +889,52 @@
 
 
-#if RATE_CONTROL_INTRA
 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType)  
-#else 
-Double TEncRCPic::getLCUTargetBpp()
-#endif
+{
+  Int   LCUIdx    = getLCUCoded();
+  Double bpp      = -1.0;
+  Int avgBits     = 0;
+
+  if (eSliceType == I_SLICE)
+  {
+    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
+    Int bitrateWindow = min(4,noOfLCUsLeft);
+    Double MAD      = getLCU(LCUIdx).m_costIntra;
+
+    if (m_remainingCostIntra > 0.1 )
+    {
+      Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
+      avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
+    }
+    else
+    {
+      avgBits = Int( m_bitsLeft / m_LCULeft );
+    }
+    m_remainingCostIntra -= MAD;
+  }
+  else
+  {
+  Double totalWeight = 0;
+  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
+  {
+    totalWeight += m_LCUs[i].m_bitWeight;
+  }
+  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
+  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
+  }
+
+  if ( avgBits < 1 )
+  {
+    avgBits = 1;
+  }
+
+  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
+  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
+
+  return bpp;
+}
+
+
+#if KWU_RC_MADPRED_E0227
+Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
 {
   Int   LCUIdx    = getLCUCoded();
@@ -1003,83 +946,4 @@
 #endif
 
-#if RATE_CONTROL_INTRA
-  if (eSliceType == I_SLICE){
-    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
-    Int bitrateWindow = min(4,noOfLCUsLeft);
-    Double MAD      = getLCU(LCUIdx).m_costIntra;
-
-    if (m_remainingCostIntra > 0.1 )
-    {
-      Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
-      avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
-    }
-    else
-    {
-      avgBits = Int( m_bitsLeft / m_LCULeft );
-    }
-    m_remainingCostIntra -= MAD;
-  }
-  else
-  {
-#endif
-#if M0036_RC_IMPROVEMENT
-  Double totalWeight = 0;
-  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
-  {
-    totalWeight += m_LCUs[i].m_bitWeight;
-  }
-  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
-  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
-#else
-  if ( m_lastPicture == NULL )
-  {
-    avgBits = Int( m_bitsLeft / m_LCULeft );
-  }
-  else
-  {
-    MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
-    totalMAD = m_lastPicture->getTotalMAD();
-    for ( Int i=0; i<LCUIdx; i++ )
-    {
-      totalMAD -= m_lastPicture->getLCU(i).m_MAD;
-    }
-
-    if ( totalMAD > 0.1 )
-    {
-      avgBits = Int( m_bitsLeft * MAD / totalMAD );
-    }
-    else
-    {
-      avgBits = Int( m_bitsLeft / m_LCULeft );
-    }
-  }
-#endif
-#if RATE_CONTROL_INTRA
-  }
-#endif
-
-  if ( avgBits < 1 )
-  {
-    avgBits = 1;
-  }
-
-  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
-  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
-
-  return bpp;
-}
-
-
-#if KWU_RC_MADPRED_E0227
-Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
-{
-  Int   LCUIdx    = getLCUCoded();
-  Double bpp      = -1.0;
-  Int avgBits     = 0;
-#if !M0036_RC_IMPROVEMENT
-  Double totalMAD = -1.0;
-  Double MAD      = -1.0;
-#endif
-
   Double totalMAD = -1.0;
   Double MAD      = -1.0;
@@ -1300,11 +1164,6 @@
     beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
 
-#if M0036_RC_IMPROVEMENT
     alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
-#else
-    alpha = Clip3( 0.05, 20.0, alpha );
-    beta  = Clip3( -3.0, -0.1, beta  );
-#endif
 
     TRCParameter rcPara;
@@ -1319,18 +1178,9 @@
   alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
   double lnbpp = log( bpp );
-#if M0036_RC_IMPROVEMENT
   lnbpp = Clip3( -5.0, -0.1, lnbpp );
-#else
-  lnbpp = Clip3( -5.0, 1.0, lnbpp );
-#endif
   beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
 
-#if M0036_RC_IMPROVEMENT
   alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
   beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
-#else
-  alpha = Clip3( 0.05, 20.0, alpha );
-  beta  = Clip3( -3.0, -0.1, beta  );
-#endif
   TRCParameter rcPara;
   rcPara.m_alpha = alpha;
@@ -1340,24 +1190,4 @@
 }
 
-#if !M0036_RC_IMPROVEMENT
-Double TEncRCPic::getEffectivePercentage()
-{
-  Int effectivePiexels = 0;
-  Int totalPixels = 0;
-
-  for ( Int i=0; i<m_numberOfLCU; i++ )
-  {
-    totalPixels += m_LCUs[i].m_numberOfPixel;
-    if ( m_LCUs[i].m_QP > 0 )
-    {
-      effectivePiexels += m_LCUs[i].m_numberOfPixel;
-    }
-  }
-
-  Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;
-  return effectivePixelPercentage;
-}
-#endif
-
 Double TEncRCPic::calAverageQP()
 {
@@ -1414,13 +1244,5 @@
 }
 
-#if M0036_RC_IMPROVEMENT
-#if RATE_CONTROL_INTRA
 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
-#else
-Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
-#endif
-#else
-Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
-#endif
 {
   m_picActualHeaderBits = actualHeaderBits;
@@ -1435,8 +1257,6 @@
   }
   m_picLambda           = averageLambda;
-#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
 #if KWU_RC_MADPRED_E0227
   m_totalMAD = 0;
-#endif
   for ( Int i=0; i<m_numberOfLCU; i++ )
   {
@@ -1447,5 +1267,4 @@
   Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
   Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
-#if RATE_CONTROL_INTRA
   if (eSliceType == I_SLICE)
   {
@@ -1454,5 +1273,4 @@
   else
   {
-#endif
   // update parameters
   Double picActualBits = ( Double )m_picActualBits;
@@ -1461,20 +1279,11 @@
   Double inputLambda   = m_picLambda;
 
-#if M0036_RC_IMPROVEMENT
   if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
-#else
-  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
-#endif
   {
     alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
     beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
 
-#if M0036_RC_IMPROVEMENT
     alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
     beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
-#else
-    alpha = Clip3( 0.05, 20.0, alpha );
-    beta  = Clip3( -3.0, -0.1, beta  );
-#endif
     TRCParameter rcPara;
     rcPara.m_alpha = alpha;
@@ -1488,21 +1297,10 @@
   alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
   double lnbpp = log( picActualBpp );
-#if M0036_RC_IMPROVEMENT
   lnbpp = Clip3( -5.0, -0.1, lnbpp );
-#else
-  lnbpp = Clip3( -5.0, 1.0, lnbpp );
-#endif
   beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
 
-#if M0036_RC_IMPROVEMENT
   alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
   beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
-#else
-  alpha = Clip3( 0.05, 20.0, alpha );
-  beta  = Clip3( -3.0, -0.1, beta  );
-#endif
-#if RATE_CONTROL_INTRA
-  }
-#endif
+  }
 
   TRCParameter rcPara;
@@ -1512,5 +1310,4 @@
   m_encRCSeq->setPicPara( m_frameLevel, rcPara );
 
-#if M0036_RC_IMPROVEMENT
   if ( m_frameLevel == 1 )
   {
@@ -1519,8 +1316,6 @@
     m_encRCSeq->setLastLambda( updateLastLambda );
   }
-#endif
-}
-
-#if RATE_CONTROL_INTRA
+}
+
 Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
 {
@@ -1611,5 +1406,4 @@
   return estLambda;
 }
-#endif
 
 TEncRateCtrl::TEncRateCtrl()
@@ -1645,5 +1439,4 @@
 }
 
-#if M0036_RC_IMPROVEMENT
 #if KWU_RC_MADPRED_E0227
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int layerID )
@@ -1651,7 +1444,4 @@
 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
 #endif
-#else
-Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
-#endif
 {
   destroy();
@@ -1668,10 +1458,6 @@
 
   Int numberOfLevel = 1;
-#if M0036_RC_IMPROVEMENT
   Int adaptiveBit = 0;
   if ( keepHierBits > 0 )
-#else
-  if ( keepHierBits )
-#endif
   {
     numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
@@ -1696,9 +1482,5 @@
   }
 
-#if M0036_RC_IMPROVEMENT
   if ( keepHierBits > 0 )
-#else
-  if ( keepHierBits )
-#endif
   {
     Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
@@ -1733,10 +1515,8 @@
         bitsRatio[3] = 14;
       }
-#if M0036_RC_IMPROVEMENT
       if ( keepHierBits == 2 )
       {
         adaptiveBit = 1;
       }
-#endif
     }
     else if ( GOPSize == 8 && !isLowdelay )
@@ -1786,18 +1566,12 @@
         bitsRatio[7] = 1;
       }
-#if M0036_RC_IMPROVEMENT
       if ( keepHierBits == 2 )
       {
         adaptiveBit = 2;
       }
-#endif
     }
     else
     {
-#if M0036_RC_IMPROVEMENT
       printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
-#else
-      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
-#endif
     }
   }
@@ -1812,9 +1586,5 @@
     }
   }
-#if M0036_RC_IMPROVEMENT
   if ( keepHierBits > 0 )
-#else
-  if ( keepHierBits )
-#endif
   {
     if ( GOPSize == 4 && isLowdelay )
@@ -1851,9 +1621,5 @@
 
   m_encRCSeq = new TEncRCSeq;
-#if M0036_RC_IMPROVEMENT
   m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
-#else
-  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
-#endif
   m_encRCSeq->initBitsRatio( bitsRatio );
   m_encRCSeq->initGOPID2Level( GOPID2Level );
@@ -1894,648 +1660,2 @@
 }
 
-#else
-
-#define ADJUSTMENT_FACTOR       0.60
-#define HIGH_QSTEP_THRESHOLD    9.5238
-#define HIGH_QSTEP_ALPHA        4.9371
-#define HIGH_QSTEP_BETA         0.0922
-#define LOW_QSTEP_ALPHA         16.7429
-#define LOW_QSTEP_BETA          -1.1494
-
-#define MAD_PRED_Y1             1.0
-#define MAD_PRED_Y2             0.0
-
-enum MAD_HISOTRY {
-  MAD_PPPrevious = 0,
-  MAD_PPrevious  = 1,
-  MAD_Previous   = 2
-};
-
-Void    MADLinearModel::initMADLinearModel()
-{
-  m_activeOn = false;
-  m_paramY1  = 1.0;
-  m_paramY2  = 0.0;
-  m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;
-}
-
-Double  MADLinearModel::getMAD()
-{
-  Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;
-
-  if(costPredMAD < 0)
-  {
-    costPredMAD = m_costMADs[MAD_Previous];
-    m_paramY1   = MAD_PRED_Y1;
-    m_paramY2   = MAD_PRED_Y2;
-  } 
-  return costPredMAD;
-}
-
-Void    MADLinearModel::updateMADLiearModel()
-{
-  Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));
-  Double dNewY2 =  (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));
-  
-  m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;
-  m_paramY2 =      0.20*m_paramY2+ 0.10*dNewY2;
-}
-
-Void    MADLinearModel::updateMADHistory(Double dMAD)
-{
-  m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];
-  m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];
-  m_costMADs[MAD_Previous  ] = dMAD;
-  m_activeOn = (m_costMADs[MAD_Previous  ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);
-}
-
-
-Void    PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()
-{
-  m_paramHighX1 = HIGH_QSTEP_ALPHA;
-  m_paramHighX2 = HIGH_QSTEP_BETA;
-  m_paramLowX1  = LOW_QSTEP_ALPHA;
-  m_paramLowX2  = LOW_QSTEP_BETA;
-}
-
-Int     PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)
-{
-  Double qStep;
-  Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));
-  
-  if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)
-  {
-    qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));
-  }
-  else
-  {
-    qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));
-  }
-  
-  return xConvertQStep2QP(qStep);
-}
-
-Void    PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)
-{
-  Double qStep     = xConvertQP2QStep(qp);
-  Double invqStep = (1/qStep);
-  Double paramNewX1, paramNewX2;
-  
-  if(qStep >= HIGH_QSTEP_THRESHOLD)
-  {
-    paramNewX2    = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));
-    paramNewX1    = (23.3772-200*paramNewX2);
-    m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;
-    m_paramHighX2 = 0.70*HIGH_QSTEP_BETA  + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;
-  }
-  else
-  {
-    paramNewX2   = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));
-    paramNewX1   = (5.8091-9.5455*paramNewX2);
-    m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;
-    m_paramLowX2 = 0.90*LOW_QSTEP_BETA  + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;
-  }
-}
-
-Bool    PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )
-{ 
-  Double qStep = xConvertQP2QStep(qpReference);
-
-  if (qStep > xConvertQP2QStep(MAX_QP) 
-    ||qStep < xConvertQP2QStep(MIN_QP) )
-  {
-    return false;
-  }
-
-  return true;
-}
-
-Double  PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )
-{
-  Int i;
-  Double qStep;
-  static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };
-
-  qStep = mapQP2QSTEP[qp % 6];
-  for( i=0; i<(qp/6); i++)
-  {
-    qStep *= 2;
-  }
-
-  return qStep;
-}
-
-Int     PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )
-{
-  Int per = 0, rem = 0;
-
-  if( qStep < xConvertQP2QStep(MIN_QP))
-  {
-    return MIN_QP;
-  }
-  else if (qStep > xConvertQP2QStep(MAX_QP) )
-  {
-    return MAX_QP;
-  }
-
-  while( qStep > xConvertQP2QStep(5) )
-  {
-    qStep /= 2.0;
-    per++;
-  }
-
-  if (qStep <= 0.625)
-  {
-    rem = 0;
-  }
-  else if (qStep <= 0.703)
-  {
-    rem = 1;
-  }
-  else if (qStep <= 0.797)
-  {
-    rem = 2;
-  }
-  else if (qStep <= 0.891)
-  {
-    rem = 3;
-  }
-  else if (qStep <= 1.000)
-  {
-    rem = 4;
-  }
-  else
-  {
-    rem = 5;
-  }
-  return (per * 6 + rem);
-}
-
-
-Void  TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)
-{
-  Int leftInHeight, leftInWidth;
-
-  m_sourceWidthInLCU         = (sourceWidth  / maxCUWidth  ) + (( sourceWidth  %  maxCUWidth ) ? 1 : 0);
-  m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0);  
-  m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
-
-  m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
-  m_currBitrate              = ( targetKbps << 10 );
-
-  m_frameRate                = frameRate;
-  m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
-  m_nonRefFrameNum           = sizeGOP-m_refFrameNum;
-  m_sizeGOP                  = sizeGOP;
-  m_numOfPixels              = ((sourceWidth*sourceHeight*3)>>1);
-  m_indexGOP                 = 0;
-  m_indexFrame               = 0;
-  m_indexLCU                 = 0;
-  m_indexUnit                = 0;
-  m_indexRefFrame            = 0;
-  m_indexNonRefFrame         = 0;
-  m_occupancyVB              = 0;
-  m_initialOVB               = 0;
-  m_targetBufLevel           = 0;
-  m_initialTBL               = 0;
-  m_occupancyVBInFrame       = 0;
-  m_remainingBitsInGOP       = (m_currBitrate*sizeGOP/m_frameRate);
-  m_remainingBitsInFrame     = 0;
-  m_numUnitInFrame           = m_sourceWidthInLCU*m_sourceHeightInLCU;
-  m_cMADLinearModel.        initMADLinearModel();
-  m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();
-
-  m_costRefAvgWeighting      = 0.0;
-  m_costNonRefAvgWeighting   = 0.0;
-  m_costAvgbpp               = 0.0;  
-  m_activeUnitLevelOn        = false;
-
-  m_pcFrameData              = new FrameData   [sizeGOP+1];         initFrameData(qp);
-  m_pcLCUData                = new LCUData     [m_numUnitInFrame];  initUnitData (qp);
-
-  for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight)  
-  {
-    leftInHeight = sourceHeight - i;
-    leftInHeight = min(leftInHeight, maxCUHeight);
-    for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)
-    {
-      leftInWidth = sourceWidth - j;
-      leftInWidth = min(leftInWidth, maxCUWidth);
-      m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;
-      m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;
-      m_pcLCUData[addressUnit].m_pixels       = ((leftInHeight*leftInWidth*3)>>1);
-    }
-  }
-}
-
-Void  TEncRateCtrl::destroy()
-{
-  if(m_pcFrameData)
-  {
-    delete [] m_pcFrameData;
-    m_pcFrameData = NULL;
-  }
-  if(m_pcLCUData)
-  {
-    delete [] m_pcLCUData;
-    m_pcLCUData = NULL;
-  }
-}
-
-Void  TEncRateCtrl::initFrameData   (Int qp)
-{
-  for(Int i = 0 ; i <= m_sizeGOP; i++)
-  {
-    m_pcFrameData[i].m_isReferenced = false;
-    m_pcFrameData[i].m_costMAD      = 0.0;
-    m_pcFrameData[i].m_bits         = 0;
-    m_pcFrameData[i].m_qp           = qp;
-  }
-}
-
-Void  TEncRateCtrl::initUnitData    (Int qp)
-{
-  for(Int i = 1 ; i < m_numUnitInFrame; i++)
-  {
-    m_pcLCUData[i].m_qp            = qp;
-    m_pcLCUData[i].m_bits          = 0;
-    m_pcLCUData[i].m_pixels        = 0;
-    m_pcLCUData[i].m_widthInPixel  = 0;
-    m_pcLCUData[i].m_heightInPixel = 0;
-    m_pcLCUData[i].m_costMAD       = 0.0;
-  }
-}
-
-Int  TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)
-{
-  Int numofReferenced = 0;
-  Int finalQP = 0;
-  FrameData* pcFrameData;
-
-  m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);
-  pcFrameData     = &m_pcFrameData[m_indexPOCInGOP];
-    
-  if(m_indexFrame != 0)
-  {
-    if(isReferenced)
-    {
-      Double gamma = m_isLowdelay ? 0.5 : 0.25;
-      Double beta  = m_isLowdelay ? 0.9 : 0.6;
-      Int    numRemainingRefFrames  = m_refFrameNum    - m_indexRefFrame;
-      Int    numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;
-      
-      Double targetBitsOccupancy  = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));
-      Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));
-
-      m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);
-  
-      if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)
-      {
-        finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;
-      }
-      else
-      {
-        Double costPredMAD   = m_cMADLinearModel.getMAD();
-        Int    qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;
-        Int    qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;
-        finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);
-        finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));
-        m_activeUnitLevelOn    = true;
-        m_remainingBitsInFrame = m_targetBits;
-        m_costAvgbpp           = (m_targetBits/(Double)m_numOfPixels);
-      }
-
-      m_indexRefFrame++;
-    }
-    else
-    {
-      Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;
-      Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;
-       
-      if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp
-        ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)
-      {
-        finalQP = (fwdQP+bwdQP);
-      }
-      else if(bwdQP != fwdQP)
-      {
-        finalQP = ((bwdQP+fwdQP+2)>>1);
-      }
-      else
-      {
-        finalQP = bwdQP+2;
-      }
-      m_indexNonRefFrame++;
-    }
-  }
-  else
-  {
-    Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;
-    Int lastQPplus2  = m_pcFrameData[0].m_qp + 2;
-
-    for(Int idx = 1; idx <= m_sizeGOP; idx++)
-    {
-      if(m_pcFrameData[idx].m_isReferenced)
-      {
-        finalQP += m_pcFrameData[idx].m_qp;
-        numofReferenced++;
-      }
-    }
-    
-    finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);
-    finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));
-
-    Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;
-    Int    bufLevel  = m_occupancyVB + m_initialOVB;
-
-    if(abs(bufLevel) > costAvgFrameBits)
-    {
-      if(bufLevel < 0)
-      {
-        finalQP -= 2;
-      }
-      else
-      {
-        finalQP += 2;
-      }
-    }
-    m_indexRefFrame++;
-  }
-  finalQP = max(MIN_QP, min(MAX_QP, finalQP));
-
-  for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)
-  {
-    m_pcLCUData[indexLCU].m_qp = finalQP;
-  }
-
-  pcFrameData->m_isReferenced = isReferenced;
-  pcFrameData->m_qp           = finalQP;
-
-  return finalQP;
-}
-
-Bool  TEncRateCtrl::calculateUnitQP ()
-{
-  if(!m_activeUnitLevelOn || m_indexLCU == 0)
-  {
-    return false;
-  }
-  Int upperQPBound, lowerQPBound, finalQP;
-  Int    colQP        = m_pcLCUData[m_indexLCU].m_qp;
-  Double colMAD       = m_pcLCUData[m_indexLCU].m_costMAD;
-  Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;
-
-
-  Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));
-  Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));
-  Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);
-  
-
-  if( m_indexLCU >= m_sourceWidthInLCU)
-  {
-    upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;
-    lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;
-  }
-  else
-  {
-    upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;
-    lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;
-  }
-
-  if(targetBits < 0)
-  {
-    finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;
-  }
-  else
-  {
-    finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);
-  }
-  
-  finalQP = max(lowerQPBound, min(upperQPBound, finalQP));
-  m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));
-  
-  return true;
-}
-
-Void  TEncRateCtrl::updateRCGOPStatus()
-{
-  m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;
-  
-  FrameData cFrameData = m_pcFrameData[m_sizeGOP];
-  initFrameData();
-
-  m_pcFrameData[0]   = cFrameData;
-  m_indexGOP++;
-  m_indexFrame       = 0;
-  m_indexRefFrame    = 0;
-  m_indexNonRefFrame = 0;
-}
-
-Void  TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)
-{
-  FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];
-  Int occupancyBits;
-  Double adjustmentBits;
-
-  m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;
-  occupancyBits        = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));
-  
-  if( (occupancyBits < 0) && (m_initialOVB > 0) )
-  {
-    adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );
-
-    if(m_initialOVB < 0)
-    {
-      adjustmentBits = m_initialOVB;
-      occupancyBits += (Int)adjustmentBits;
-      m_initialOVB   =  0;
-    }
-  }
-  else if( (occupancyBits > 0) && (m_initialOVB < 0) )
-  {
-    adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );
-    
-    if(occupancyBits < 0)
-    {
-      adjustmentBits = occupancyBits;
-      m_initialOVB  += (Int)adjustmentBits;
-      occupancyBits  =  0;
-    }
-  }
-
-  if(m_indexGOP == 0)
-  {
-    m_initialOVB = occupancyBits;
-  }
-  else
-  {
-    m_occupancyVB= m_occupancyVB + occupancyBits;
-  }
-
-  if(pcFrameData->m_isReferenced)
-  {
-    m_costRefAvgWeighting  = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);
-
-    if(m_indexFrame == 0)
-    {
-      m_initialTBL = m_targetBufLevel  = (frameBits - (m_currBitrate/m_frameRate));
-    }
-    else
-    {
-      Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;
-      m_targetBufLevel =  m_targetBufLevel 
-                            - (m_initialTBL/(m_refFrameNum-1)) 
-                            + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance)))) 
-                            - (m_currBitrate/m_frameRate);
-    }
-
-    if(m_cMADLinearModel.IsUpdateAvailable())
-    {
-      m_cMADLinearModel.updateMADLiearModel();
-    }
-
-    if(eSliceType != I_SLICE &&
-       m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))
-    {
-      m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);
-    }
-  }
-  else
-  {
-    m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);
-  }
-
-  m_indexFrame++;
-  m_indexLCU             = 0;
-  m_indexUnit            = 0;
-  m_occupancyVBInFrame   = 0;
-  m_remainingBitsInFrame = 0;
-  m_codedPixels          = 0;
-  m_activeUnitLevelOn    = false;
-  m_costAvgbpp           = 0.0;
-}
-Void  TEncRateCtrl::updataRCUnitStatus ()
-{
-  if(!m_activeUnitLevelOn || m_indexLCU == 0)
-  {
-    return;
-  }
-
-  m_codedPixels  += m_pcLCUData[m_indexLCU-1].m_pixels;
-  m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;
-  m_occupancyVBInFrame   = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);
-
-  if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )
-  {
-    m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(m_pcLCUData[m_indexLCU-1].m_qp, m_pcLCUData[m_indexLCU-1].m_bits, m_pcLCUData[m_indexLCU-1].m_pixels, m_pcLCUData[m_indexLCU-1].m_costMAD);
-  }
-
-  m_indexUnit++;
-}
-
-Void  TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)
-{
-  Double costMAD = 0.0;
-  
-  for(Int i = 0; i < m_numUnitInFrame; i++)
-  {
-    costMAD    += m_pcLCUData[i].m_costMAD;
-  }
-  
-  m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);
-  m_pcFrameData[m_indexPOCInGOP].m_bits    = (Int)actualFrameBits;
-  
-  if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)
-  {
-    m_indexPrevPOCInGOP = m_indexPOCInGOP;
-    m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);
-  }
-}
-
-Void  TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)
-{
-  Int     x, y;
-  Double  costMAD = 0.0;
-
-  Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
-  Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
-  Int   stride = pcCU->getPic()->getStride();
-
-  Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
-  Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
-
-  for( y = 0; y < height; y++ )
-  {
-    for( x = 0; x < width; x++ )
-    {
-      costMAD += abs( pOrg[x] - pRec[x] );
-    }
-    pOrg += stride;
-    pRec += stride;
-  }
-  m_pcLCUData[m_indexLCU  ].m_qp      = qp;
-  m_pcLCUData[m_indexLCU  ].m_costMAD = (costMAD /(Double)(width*height));
-  m_pcLCUData[m_indexLCU++].m_bits    = (Int)actualLCUBits;
-}
-
-
-#if KWU_RC_MADPRED_E0227
-Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)
-{
-  Int     x, y;
-  Double dMAD = 0.0;
-  Int Sum = 0;
-  Double SAD = 0.0;
-
-  Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
-  Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
-  Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
-  Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
-
-  Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
-  Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
-
-  for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
-  {
-    for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
-    {
-      Sum += pDep[x];
-    }
-    pDep += iStride;
-  }
-
-  Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
-  Double fL = focalLen * abs( basePos - curPos );
-  Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
-  Int   disparity = (Int)(direction*fL * z);
-  Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
-  Int disp = disparity;
-
-  for( y = 0; y < height; y++ )
-  {
-    for( x = 0; x < width; x++ )
-    {
-      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
-      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
-    }
-    pOrg += iStride;
-    pRec += iStride;
-  }
-  m_pcLCUData[m_indexLCU].m_qp   = qp;
-  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(width*height));
-  m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
-}
-#endif
-
-
-Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
-{
-  Double adjustment  = ADJUSTMENT_FACTOR*reductionBits;
-  reductionBits     -= (Int)adjustment;
-  compensationBits  += (Int)adjustment;
-
-  return adjustment;
-}
-
-#endif
-
