Index: /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 638)
@@ -84,5 +84,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  m_DepthMADPred = 0;
+  m_depthMADPred = 0;
 #endif
 }
@@ -600,9 +600,9 @@
 
 #if KWU_RC_VIEWRC_E0227
-  ("ViewWiseTargetBits, -vtbr" ,  m_ViewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
-  ("TargetBitAssign, -ta", m_ViewWiseRateCtrl, false, "View-wise rate control on/off")
+  ("ViewWiseTargetBits, -vtbr" ,  m_viewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")
 #endif
 #if KWU_RC_MADPRED_E0227
-  ("DepthMADPred, -dm", m_DepthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+  ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
 #endif
 #else
@@ -612,9 +612,9 @@
 
 #if KWU_RC_VIEWRC_E0227
-  ("ViewWiseTargetBits, -vtbr" ,  m_ViewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
-  ("TargetBitAssign, -ta", m_ViewWiseRateCtrl, false, "View-wise rate control on/off")
+  ("ViewWiseTargetBits, -vtbr" ,  m_viewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
+  ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")
 #endif
 #if KWU_RC_MADPRED_E0227
-  ("DepthMADPred, -dm", m_DepthMADPred, (UInt)0, "Depth based MAD prediction on/off")
+  ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
 #endif
 #endif
@@ -2325,14 +2325,14 @@
 
 #if KWU_RC_MADPRED_E0227
-    printf("Depth based MAD prediction   : %d\n", m_DepthMADPred);
+    printf("Depth based MAD prediction   : %d\n", m_depthMADPred);
 #endif
 #if KWU_RC_VIEWRC_E0227
-    printf("View-wise Rate control       : %d\n", m_ViewWiseRateCtrl);
-    if(m_ViewWiseRateCtrl)
+    printf("View-wise Rate control       : %d\n", m_viewWiseRateCtrl);
+    if(m_viewWiseRateCtrl)
     {
 
       printf("ViewWiseTargetBits           : ");
-      for (int i = 0 ; i < m_iNumberOfViews ; i++)
-        printf("%d ", m_ViewTargetBits[i]);
+      for (Int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_viewTargetBits[i]);
       printf("\n");
     }
@@ -2351,14 +2351,14 @@
 
 #if KWU_RC_MADPRED_E0227
-    printf("Depth based MAD prediction   : %d\n", m_DepthMADPred);
+    printf("Depth based MAD prediction   : %d\n", m_depthMADPred);
 #endif
 #if KWU_RC_VIEWRC_E0227
-    printf("View-wise Rate control       : %d\n", m_ViewWiseRateCtrl);
-    if(m_ViewWiseRateCtrl)
+    printf("View-wise Rate control       : %d\n", m_viewWiseRateCtrl);
+    if(m_viewWiseRateCtrl)
     {
 
       printf("ViewWiseTargetBits           : ");
-      for (int i = 0 ; i < m_iNumberOfViews ; i++)
-        printf("%d ", m_ViewTargetBits[i]);
+      for (Int i = 0 ; i < m_iNumberOfViews ; i++)
+        printf("%d ", m_viewTargetBits[i]);
       printf("\n");
     }
Index: /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncCfg.h	(revision 638)
@@ -369,9 +369,9 @@
 
 #if KWU_RC_VIEWRC_E0227
-  vector<Int>     m_ViewTargetBits;
-  bool      m_ViewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+  vector<Int>     m_viewTargetBits;
+  Bool      m_viewWiseRateCtrl;                              ///< Flag for using view-wise rate control
 #endif
 #if KWU_RC_MADPRED_E0227
-  UInt       m_DepthMADPred;
+  UInt       m_depthMADPred;
 #endif
 #else
@@ -381,9 +381,9 @@
 
 #if KWU_RC_VIEWRC_E0227
-  vector<Int>     m_ViewTargetBits;
-  bool      m_ViewWiseRateCtrl;                              ///< Flag for using view-wise rate control
+  vector<Int>     m_viewTargetBits;
+  Bool      m_viewWiseRateCtrl;                              ///< Flag for using view-wise rate control
 #endif
 #if KWU_RC_MADPRED_E0227
-  UInt       m_DepthMADPred;
+  UInt       m_depthMADPred;
 #endif
 #endif
Index: /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/App/TAppEncoder/TAppEncTop.cpp	(revision 638)
@@ -536,5 +536,5 @@
   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
   {
-    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_DepthMADPred       : 0);
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
 
     if(m_cTEncTop.getUseDepthMADPred())
@@ -547,11 +547,11 @@
   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
   {
-    m_cTEncTop.setUseViewWiseRateCtrl(m_ViewWiseRateCtrl);
+    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
 
     if(m_iNumberOfViews == 1)
     {
-      if(m_ViewWiseRateCtrl)
-      {
-        m_cTEncTop.setTargetBitrate(m_ViewTargetBits[layerIdInVps>>1]);
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
       }
       else
@@ -562,7 +562,7 @@
     else
     {
-      if(m_ViewWiseRateCtrl)
-      {
-        m_cTEncTop.setTargetBitrate(m_ViewTargetBits[layerIdInVps>>1]);
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
       }
       else
@@ -624,5 +624,5 @@
   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
   {
-    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_DepthMADPred       : 0);
+    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
 
     if(m_cTEncTop.getUseDepthMADPred())
@@ -636,10 +636,10 @@
   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
   {
-    m_cTEncTop.setUseViewWiseRateCtrl(m_ViewWiseRateCtrl);
+    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
     if(m_iNumberOfViews == 1)
     {
-      if(m_ViewWiseRateCtrl)
-      {
-        m_cTEncTop.setTargetBitrate(m_ViewTargetBits[layerIdInVps>>1]);
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
       }
       else
@@ -650,7 +650,7 @@
     else
     {
-      if(m_ViewWiseRateCtrl)
-      {
-        m_cTEncTop.setTargetBitrate(m_ViewTargetBits[layerIdInVps>>1]);
+      if(m_viewWiseRateCtrl)
+      {
+        m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
       }
       else
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibCommon/TypeDef.h	(revision 638)
@@ -302,5 +302,5 @@
 #endif
 
-#define RATE_CONTROL_LAMBDA_DOMAIN                  1  ///< JCTVC-K0103, rate control by R-lambda model
+#define RATE_CONTROL_LAMBDA_DOMAIN                  0  ///< JCTVC-K0103, rate control by R-lambda model
 #define M0036_RC_IMPROVEMENT                        1  ///< JCTVC-M0036, improvement for R-lambda model based rate control
 #define TICKET_1090_FIX                             1
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCfg.h	(revision 638)
@@ -312,5 +312,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  UInt       m_uiDepthMADPred;
+  UInt       m_depthMADPred;
 #endif
 #if KWU_RC_VIEWRC_E0227
@@ -323,5 +323,5 @@
 
 #if KWU_RC_MADPRED_E0227
-  UInt       m_uiDepthMADPred;
+  UInt       m_depthMADPred;
 #endif
 #if KWU_RC_VIEWRC_E0227
@@ -842,6 +842,6 @@
 
 #if KWU_RC_MADPRED_E0227
-  UInt      getUseDepthMADPred    ()                { return m_uiDepthMADPred;        }
-  Void      setUseDepthMADPred    (UInt b)          { m_uiDepthMADPred    = b;        }
+  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
 #endif
 #if KWU_RC_VIEWRC_E0227
@@ -858,6 +858,6 @@
 
 #if KWU_RC_MADPRED_E0227
-  UInt      getUseDepthMADPred    ()                { return m_uiDepthMADPred;        }
-  Void      setUseDepthMADPred    (UInt b)          { m_uiDepthMADPred    = b;        }
+  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
+  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
 #endif
 #if KWU_RC_VIEWRC_E0227
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.cpp	(revision 638)
@@ -103,5 +103,17 @@
   
   m_bEncodeDQP = false;
-#if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+#endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+#endif
+#endif
+#if KWU_RC_MADPRED_E0227
   m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
@@ -257,7 +269,19 @@
   m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
 
-#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
+  m_LCUPredictionSAD = 0;
   m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+#endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
   m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
+  m_temporalSAD      = 0;
+#endif
+#endif
+#if KWU_RC_MADPRED_E0227
+  m_LCUPredictionSAD = 0;
+  m_addSADDepth      = 0;
   m_temporalSAD      = 0;
   m_spatialSAD       = 0;
@@ -673,5 +697,5 @@
     }
 
-#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     if ( uiDepth <= m_addSADDepth )
     {
@@ -679,4 +703,18 @@
       m_addSADDepth = uiDepth;
     }
+#endif
+#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+    if ( uiDepth <= m_addSADDepth )
+    {
+      m_LCUPredictionSAD += m_temporalSAD;
+      m_addSADDepth = uiDepth;
+    }
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+if ( uiDepth <= m_addSADDepth )
+{
+  m_LCUPredictionSAD += m_temporalSAD;
+  m_addSADDepth = uiDepth;
+}
 #endif
 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
@@ -1022,5 +1060,18 @@
           {
             xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
-#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#elif RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
+            if ( uiDepth <= m_addSADDepth )
+            {
+              m_LCUPredictionSAD += m_spatialSAD;
+              m_addSADDepth = uiDepth;
+            }
+#endif
+#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
             if ( uiDepth <= m_addSADDepth )
             {
@@ -2261,5 +2312,14 @@
   rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
   
-#if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
+#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
+  UChar uhDepth = rpcTempCU->getDepth( 0 );
+  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
+  {
+    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
+      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
+      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
+    m_spatialSAD = (Int)SAD;
+  }
+#elif RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
   UChar uhDepth = rpcTempCU->getDepth( 0 );
   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncCu.h	(revision 638)
@@ -102,5 +102,17 @@
   Bool                    m_bUseSBACRD;
   TEncRateCtrl*           m_pcRateCtrl;
-#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
+#if RATE_CONTROL_LAMBDA_DOMAIN
+#if !M0036_RC_IMPROVEMENT
+  UInt                    m_LCUPredictionSAD;
+  Int                     m_addSADDepth;
+  Int                     m_temporalSAD;
+#endif
+#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
+  UInt                    m_LCUPredictionSAD;
+  Int                     m_addSADDepth;
+  Int                     m_temporalSAD;
+#endif
+#endif
+#if KWU_RC_MADPRED_E0227
   UInt                    m_LCUPredictionSAD;
   Int                     m_addSADDepth;
@@ -108,4 +120,5 @@
   Int                     m_spatialSAD;
 #endif
+
 public:
   /// copy parameters from encoder class
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncRateCtrl.cpp	(revision 638)
@@ -726,5 +726,4 @@
   m_lastPicture = NULL;
   list<TEncRCPic*>::reverse_iterator it;
-#if KWU_RC_MADPRED_E0227
   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
   {
@@ -735,5 +734,4 @@
     }
   }
-#endif
 #endif
 
@@ -2486,5 +2484,5 @@
 {
   Int     x, y;
-  double dMAD = 0.0;
+  Double dMAD = 0.0;
   Int Sum = 0;
   Double SAD = 0.0;
Index: /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 637)
+++ /branches/HTM-8.2-dev0-KWU/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 638)
@@ -1139,7 +1139,7 @@
       if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
       {
-        double zn, zf, focallength, position, camshift;
-        double basepos;
-        bool bInterpolated;
+        Double zn, zf, focallength, position, camshift;
+        Double basepos;
+        Bool bInterpolated;
         Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
 
@@ -1252,7 +1252,7 @@
           if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
           {
-            double zn, zf, focallength, position, camShift;
-            double basePos;
-            bool bInterpolated;
+            Double zn, zf, focallength, position, camShift;
+            Double basePos;
+            Bool bInterpolated;
             Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
             Int disparity;
