Index: trunk/source/Lib/TLibCommon/AccessUnit.h
===================================================================
--- trunk/source/Lib/TLibCommon/AccessUnit.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/AccessUnit.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/CommonDef.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/CommonDef.h	(revision 595)
@@ -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.
  *
@@ -40,4 +40,5 @@
 
 #include <algorithm>
+
 #if _MSC_VER > 1000
 // disable "signed and unsigned mismatch"
@@ -57,7 +58,7 @@
 #if SVC_EXTENSION
 #include <vector>
-#define NV_VERSION        "5.0 (HM-12.1)"                 ///< Current software version
+#define NV_VERSION        "5.0 (HM-13.0)"                 ///< Current software version
 #else
-#define NV_VERSION        "12.1"                ///< Current software version
+#define NV_VERSION        "13.0"                ///< Current software version
 #endif
 
Index: trunk/source/Lib/TLibCommon/ContextModel.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/ContextModel.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/ContextModel.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/ContextModel.h
===================================================================
--- trunk/source/Lib/TLibCommon/ContextModel.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/ContextModel.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/ContextModel3DBuffer.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/ContextModel3DBuffer.h
===================================================================
--- trunk/source/Lib/TLibCommon/ContextModel3DBuffer.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/ContextModel3DBuffer.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/ContextTables.h
===================================================================
--- trunk/source/Lib/TLibCommon/ContextTables.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/ContextTables.h	(revision 595)
@@ -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 @@
 //! \ingroup TLibCommon
 //! \{
-#define FIX827 1 ///< Fix for issue #827: CABAC init tables
-#define FIX712 1 ///< Fix for issue #712: CABAC init tables
 
 // ====================================================================================================================
@@ -58,5 +56,4 @@
 
 #define NUM_PART_SIZE_CTX             4       ///< number of context models for partition size
-#define NUM_CU_AMP_CTX                1       ///< number of context models for partition size (AMP)
 #define NUM_PRED_MODE_CTX             1       ///< number of context models for prediction mode
 
@@ -69,5 +66,5 @@
 #define NUM_REF_NO_CTX                2       ///< number of context models for reference index
 #define NUM_TRANS_SUBDIV_FLAG_CTX     3       ///< number of context models for transform subdivision flags
-#define NUM_QT_CBF_CTX                5       ///< number of context models for QT CBF
+#define NUM_QT_CBF_CTX                4       ///< number of context models for QT CBF
 #define NUM_QT_ROOT_CBF_CTX           1       ///< number of context models for QT ROOT CBF
 #define NUM_DELTA_QP_CTX              3       ///< number of context models for dQP
@@ -88,5 +85,5 @@
 #define NUM_ABS_FLAG_CTX_CHROMA        2      ///< number of context models for greater than 2 flag of chroma
 
-#define NUM_MVP_IDX_CTX               2       ///< number of context models for MVP index
+#define NUM_MVP_IDX_CTX               1       ///< number of context models for MVP index
 
 #define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
@@ -146,15 +143,7 @@
 INIT_PART_SIZE[3][NUM_PART_SIZE_CTX] =  
 {
-  { 154,  139,  CNU,  CNU, }, 
-  { 154,  139,  CNU,  CNU, }, 
-  { 184,  CNU,  CNU,  CNU, }, 
-};
-
-static const UChar 
-INIT_CU_AMP_POS[3][NUM_CU_AMP_CTX] =  
-{
-  { 154, }, 
-  { 154, }, 
-  { CNU, }, 
+  { 154,  139,  154,  154 },
+  { 154,  139,  154,  154 },
+  { 184,  CNU,  CNU,  CNU },
 };
 
@@ -218,7 +207,7 @@
 INIT_QT_CBF[3][2*NUM_QT_CBF_CTX] =  
 {
-  { 153,  111,  CNU,  CNU,  CNU,  149,   92,  167,  CNU,  CNU, }, 
-  { 153,  111,  CNU,  CNU,  CNU,  149,  107,  167,  CNU,  CNU, }, 
-  { 111,  141,  CNU,  CNU,  CNU,   94,  138,  182,  CNU,  CNU, }, 
+  { 153,  111,  CNU,  CNU,   149,   92,  167,  154 },
+  { 153,  111,  CNU,  CNU,   149,  107,  167,  154 },
+  { 111,  141,  CNU,  CNU,    94,  138,  182,  154 },
 };
 
@@ -286,7 +275,7 @@
 INIT_MVP_IDX[3][NUM_MVP_IDX_CTX] =  
 {
-  { 168,  CNU, }, 
-  { 168,  CNU, }, 
-  { CNU,  CNU, }, 
+  { 168 },
+  { 168 },
+  { CNU }, 
 };
 
@@ -302,13 +291,7 @@
 INIT_SAO_TYPE_IDX[3][NUM_SAO_TYPE_IDX_CTX] = 
 {
-#if FIX827
   { 160, },
   { 185, },
   { 200, },
-#else
-  { 200, },
-  { 185, }, 
-  { 160, },
-#endif
 };
 
@@ -316,13 +299,7 @@
 INIT_TRANS_SUBDIV_FLAG[3][NUM_TRANS_SUBDIV_FLAG_CTX] =
 {
-#if FIX712
   { 224,  167,  122, },
   { 124,  138,   94, },
   { 153,  138,  138, },
-#else
-  { 153,  138,  138, },
-  { 124,  138,   94, },
-  { 224,  167,  122, },
-#endif
 };
 
Index: trunk/source/Lib/TLibCommon/NAL.h
===================================================================
--- trunk/source/Lib/TLibCommon/NAL.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/NAL.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/SEI.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/SEI.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/SEI.h
===================================================================
--- trunk/source/Lib/TLibCommon/SEI.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/SEI.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComBitCounter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitCounter.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComBitCounter.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComBitStream.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComBitStream.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComBitStream.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComBitStream.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComCABACTables.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComCABACTables.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComCABACTables.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComCABACTables.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComCABACTables.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComCABACTables.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComDataCU.cpp	(revision 595)
@@ -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.
  *
@@ -309,24 +309,5 @@
   }
 }
-#if !HM_CLEANUP_SAO
-const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
-{
-  this->tileID = src.tileID;
-  this->sliceID= src.sliceID;
-  this->startSU= src.startSU;
-  this->endSU  = src.endSU;
-  this->widthSU= src.widthSU;
-  this->heightSU=src.heightSU;
-  this->posX   = src.posX;
-  this->posY   = src.posY;
-  this->width  = src.width;
-  this->height = src.height;
-  ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
-  this->allBordersAvailable = src.allBordersAvailable;
-
-  return *this;
-}
-
-#endif
+
 // ====================================================================================================================
 // Public member functions
@@ -547,5 +528,5 @@
 *- set last-coded qp value according to input last-coded qp 
 */
-Void TComDataCU::initEstData( UInt uiDepth, Int qp )
+Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass )
 {
   m_dTotalCost         = MAX_DOUBLE;
@@ -575,5 +556,5 @@
       m_pePartSize[ui] = SIZE_NONE;
       m_pePredMode[ui] = MODE_NONE;
-      m_CUTransquantBypass[ui] = false;
+      m_CUTransquantBypass[ui] = bTransquantBypass;
       m_pbIPCMFlag[ui] = 0;
       m_phQP[ui] = qp;
@@ -2550,5 +2531,4 @@
   TComDataCU* pcCULeft = 0;
   pcCULeft = getPULeft( uiLeftPartIdx, uiPartIdxLB );
-
   Bool isAvailableA1 = pcCULeft &&
   pcCULeft->isDiffMER(xP -1, yP+nPSH-1, xP, yP) &&
@@ -2582,5 +2562,4 @@
   TComDataCU* pcCUAbove = 0;
   pcCUAbove = getPUAbove( uiAbovePartIdx, uiPartIdxRT );
-
   Bool isAvailableB1 = pcCUAbove &&
   pcCUAbove->isDiffMER(xP+nPSW-1, yP-1, xP, yP) &&
@@ -2614,5 +2593,4 @@
   TComDataCU* pcCUAboveRight = 0;
   pcCUAboveRight = getPUAboveRight( uiAboveRightPartIdx, uiPartIdxRT );
-
   Bool isAvailableB0 = pcCUAboveRight &&
   pcCUAboveRight->isDiffMER(xP+nPSW, yP-1, xP, yP) &&
@@ -2645,5 +2623,4 @@
   TComDataCU* pcCULeftBottom = 0;
   pcCULeftBottom = this->getPUBelowLeft( uiLeftBottomPartIdx, uiPartIdxLB );
-
   Bool isAvailableA0 = pcCULeftBottom &&
   pcCULeftBottom->isDiffMER(xP-1, yP+nPSH, xP, yP) &&
@@ -2671,5 +2648,4 @@
     return;
   }
-
   // above left 
   if( iCount < 4 )
@@ -2678,5 +2654,4 @@
     TComDataCU* pcCUAboveLeft = 0;
     pcCUAboveLeft = getPUAboveLeft( uiAboveLeftPartIdx, uiAbsPartAddr );
-
     Bool isAvailableB2 = pcCUAboveLeft &&
     pcCUAboveLeft->isDiffMER(xP-1, yP-1, xP, yP) &&
@@ -3013,4 +2988,5 @@
     }
   }
+  
   // Above predictor search
   bAdded = xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
@@ -3025,8 +3001,6 @@
     xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
   }
-  bAdded = bAddedSmvp;
-  if (pInfo->iN==2) bAdded = true;
-
-  if(!bAdded)
+
+  if (!bAddedSmvp)
   {
     bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
@@ -3626,375 +3600,4 @@
   return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 
 }
-#if !HM_CLEANUP_SAO
-/** Set neighboring blocks availabilities for non-deblocked filtering 
- * \param numLCUInPicWidth number of LCUs in picture width
- * \param numLCUInPicHeight number of LCUs in picture height
- * \param numSUInLCUWidth number of SUs in LCU width
- * \param numSUInLCUHeight number of SUs in LCU height
- * \param picWidth picture width
- * \param picHeight picture height
- * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
- * \param bTopTileBoundary true means that top boundary coincides tile boundary
- * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
- * \param bLeftTileBoundary true means that left boundary coincides tile boundary
- * \param bRightTileBoundary true means that right boundary coincides tile boundary
- * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
- */
-Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
-                                                    ,std::vector<Bool>& LFCrossSliceBoundary
-                                                    ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
-                                                    ,Bool bIndependentTileBoundaryEnabled)
-{
-  UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
-  Int* pSliceIDMapLCU = m_piSliceSUMap;
-  Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
-  UInt uiLPelX, uiTPelY;
-  UInt width, height;
-  Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
-  Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
-  Bool* pbAvailBorder;
-  Bool* pbAvail;
-  UInt rTLSU, rBRSU, widthSU, heightSU;
-  UInt zRefSU;
-  Int* pRefID;
-  Int* pRefMapLCU;
-  UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
-  Int* pRRefMapLCU= NULL;
-  Int* pLRefMapLCU= NULL;
-  Int* pTRefMapLCU= NULL;
-  Int* pBRefMapLCU= NULL;
-  Int  sliceID;
-  UInt numSGU = (UInt)m_vNDFBlock.size();
-
-  for(Int i=0; i< numSGU; i++)
-  {
-    NDBFBlockInfo& rSGU = m_vNDFBlock[i];
-
-    sliceID = rSGU.sliceID;
-    uiLPelX = rSGU.posX;
-    uiTPelY = rSGU.posY;
-    width   = rSGU.width;
-    height  = rSGU.height;
-    rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
-    rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
-    widthSU   = rSGU.widthSU;
-    heightSU  = rSGU.heightSU;
-
-    pbAvailBorder = rSGU.isBorderAvailable;
-
-    bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
-    bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
-    bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
-    bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
-
-    bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
-    bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
-    bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
-    bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
-
-    //       SGU_L
-    pbAvail = &(pbAvailBorder[SGU_L]);
-    if(bPicLBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
-      if(bLCULBoundary)
-      {
-        rLRefSU     = rTLSU + numSUInLCUWidth -1;
-        zRefSU      = g_auiRasterToZscan[rLRefSU];
-        pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
-      }
-      else
-      {
-        zRefSU   = g_auiRasterToZscan[rTLSU - 1];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_R
-    pbAvail = &(pbAvailBorder[SGU_R]);
-    if(bPicRBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
-      if(bLCURBoundary)
-      {
-        rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
-        zRefSU       = g_auiRasterToZscan[rRRefSU];
-        pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
-      }
-      else
-      {
-        zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_T
-    pbAvail = &(pbAvailBorder[SGU_T]);
-    if(bPicTBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
-      if(bLCUTBoundary)
-      {
-        rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
-        zRefSU       = g_auiRasterToZscan[rTRefSU];
-        pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
-      }
-      else
-      {
-        zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_B
-    pbAvail = &(pbAvailBorder[SGU_B]);
-    if(bPicBBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
-      if(bLCUBBoundary)
-      {
-        rBRefSU      = rTLSU % numSUInLCUWidth;
-        zRefSU       = g_auiRasterToZscan[rBRefSU];
-        pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
-      }
-      else
-      {
-        zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_TL
-    pbAvail = &(pbAvailBorder[SGU_TL]);
-    if(bPicTBoundary || bPicLBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      if(bLCUTBoundary && bLCULBoundary)
-      {
-        zRefSU       = numSUInLCU -1;
-        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
-      }
-      else if(bLCUTBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
-        pRefMapLCU  = pTRefMapLCU;
-      }
-      else if(bLCULBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
-        pRefMapLCU  = pLRefMapLCU;
-      }
-      else //inside LCU
-      {
-        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_TR
-    pbAvail = &(pbAvailBorder[SGU_TR]);
-    if(bPicTBoundary || bPicRBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      if(bLCUTBoundary && bLCURBoundary)
-      {
-        zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
-        pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);        
-      }
-      else if(bLCUTBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
-        pRefMapLCU  = pTRefMapLCU;
-      }
-      else if(bLCURBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
-        pRefMapLCU  = pRRefMapLCU;
-      }
-      else //inside LCU
-      {
-        zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_BL
-    pbAvail = &(pbAvailBorder[SGU_BL]);
-    if(bPicBBoundary || bPicLBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      if(bLCUBBoundary && bLCULBoundary)
-      {
-        zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
-        pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);        
-      }
-      else if(bLCUBBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
-        pRefMapLCU  = pBRefMapLCU;
-      }
-      else if(bLCULBoundary)
-      {
-        zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
-        pRefMapLCU  = pLRefMapLCU;
-      }
-      else //inside LCU
-      {
-        zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
-        pRefMapLCU  = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    //       SGU_BR
-    pbAvail = &(pbAvailBorder[SGU_BR]);
-    if(bPicBBoundary || bPicRBoundary)
-    {
-      *pbAvail = false;
-    }
-    else if (onlyOneSliceInPic)
-    {
-      *pbAvail = true;
-    }
-    else
-    {
-      if(bLCUBBoundary && bLCURBoundary)
-      {
-        zRefSU = 0;
-        pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
-      }
-      else if(bLCUBBoundary)
-      {
-        zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
-        pRefMapLCU = pBRefMapLCU;
-      }
-      else if(bLCURBoundary)
-      {
-        zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
-        pRefMapLCU = pRRefMapLCU;
-      }
-      else //inside LCU
-      {
-        zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
-        pRefMapLCU = pSliceIDMapLCU;
-      }
-      pRefID = pRefMapLCU + zRefSU;
-      *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
-    }
-
-    if(bIndependentTileBoundaryEnabled)
-    {
-      //left LCU boundary
-      if(!bPicLBoundary && bLCULBoundary)
-      {
-        if(bLeftTileBoundary)
-        {
-          pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
-        }
-      }
-      //right LCU boundary
-      if(!bPicRBoundary && bLCURBoundary)
-      {
-        if(bRightTileBoundary)
-        {
-          pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
-        }
-      }
-      //top LCU boundary
-      if(!bPicTBoundary && bLCUTBoundary)
-      {
-        if(bTopTileBoundary)
-        {
-          pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
-        }
-      }
-      //down LCU boundary
-      if(!bPicBBoundary && bLCUBBoundary)
-      {
-        if(bDownTileBoundary)
-        {
-          pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
-        }
-      }
-    }
-    rSGU.allBordersAvailable = true;
-    for(Int b=0; b< NUM_SGU_BORDER; b++)
-    {
-      if(pbAvailBorder[b] == false)
-      {
-        rSGU.allBordersAvailable = false;
-        break;
-      }
-    }
-  }
-}
-
-#endif
 
 #if SVC_EXTENSION
@@ -4077,4 +3680,4 @@
   rcMvFieldEnhance.setMvField( cMv, rcMvFieldBase.getRefIdx() );
 }
-#endif
+#endif //SVC_EXTENSION
 //! \}
Index: trunk/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComDataCU.h	(revision 595)
@@ -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.
  *
@@ -55,45 +55,4 @@
 //! \{
 
-#if !HM_CLEANUP_SAO
-// ====================================================================================================================
-// Non-deblocking in-loop filter processing block data structure
-// ====================================================================================================================
-
-/// Non-deblocking filter processing block border tag
-enum NDBFBlockBorderTag
-{
-  SGU_L = 0,
-  SGU_R,
-  SGU_T,
-  SGU_B,
-  SGU_TL,
-  SGU_TR,
-  SGU_BL,
-  SGU_BR,
-  NUM_SGU_BORDER
-};
-
-/// Non-deblocking filter processing block information
-struct NDBFBlockInfo
-{
-  Int   tileID;   //!< tile ID
-  Int   sliceID;  //!< slice ID
-  UInt  startSU;  //!< starting SU z-scan address in LCU
-  UInt  endSU;    //!< ending SU z-scan address in LCU
-  UInt  widthSU;  //!< number of SUs in width
-  UInt  heightSU; //!< number of SUs in height
-  UInt  posX;     //!< top-left X coordinate in picture
-  UInt  posY;     //!< top-left Y coordinate in picture
-  UInt  width;    //!< number of pixels in width
-  UInt  height;   //!< number of pixels in height
-  Bool  isBorderAvailable[NUM_SGU_BORDER];  //!< the border availabilities
-  Bool  allBordersAvailable;
-
-  NDBFBlockInfo():tileID(0), sliceID(0), startSU(0), endSU(0) {} //!< constructor
-  const NDBFBlockInfo& operator= (const NDBFBlockInfo& src);  //!< "=" operator
-};
-#endif
-
-
 // ====================================================================================================================
 // Class definition
@@ -161,8 +120,4 @@
   Pel*          m_pcIPCMSampleCr;     ///< PCM sample buffer (Cr)
 
-#if !HM_CLEANUP_SAO
-  Int*          m_piSliceSUMap;       ///< pointer of slice ID map
-  std::vector<NDBFBlockInfo> m_vNDFBlock;
-#endif
   // -------------------------------------------------------------------------------------------------------------------
   // neighbour access variables
@@ -241,5 +196,5 @@
   
   Void          initCU                ( TComPic* pcPic, UInt uiCUAddr );
-  Void          initEstData           ( UInt uiDepth, Int qp );
+  Void          initEstData           ( UInt uiDepth, Int qp, Bool bTransquantBypass );
   Void          initSubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp );
   Void          setOutsideCUPart      ( UInt uiAbsPartIdx, UInt uiDepth );
@@ -392,20 +347,4 @@
   Void          setIPCMFlagSubParts   (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth);
 
-#if !HM_CLEANUP_SAO
-  /// get slice ID for SU
-  Int           getSUSliceID          (UInt uiIdx)              {return m_piSliceSUMap[uiIdx];      } 
-
-  /// get the pointer of slice ID map
-  Int*          getSliceSUMap         ()                        {return m_piSliceSUMap;             }
-
-  /// set the pointer of slice ID map
-  Void          setSliceSUMap         (Int *pi)                 {m_piSliceSUMap = pi;               }
-
-  std::vector<NDBFBlockInfo>* getNDBFilterBlocks()      {return &m_vNDFBlock;}
-  Void setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt numLCUInPicHeight, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
-                                          ,std::vector<Bool>& LFCrossSliceBoundary
-                                          ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
-                                          ,Bool bIndependentTileBoundaryEnabled );
-#endif
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for accessing partition information
@@ -442,9 +381,4 @@
   
   Void          compressMV            ();
-  
-#if SVC_EXTENSION
-  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
-  UInt          getLayerId ()               { return m_layerId; }
-#endif
   
   // -------------------------------------------------------------------------------------------------------------------
@@ -490,4 +424,5 @@
   Void          deriveLeftBottomIdxGeneral    ( UInt uiAbsPartIdx, UInt uiPartIdx, UInt& ruiPartIdxLB );
   
+  
   // -------------------------------------------------------------------------------------------------------------------
   // member functions for modes
@@ -497,7 +432,4 @@
   Bool          isSkipped ( UInt uiPartIdx );                                                     ///< SKIP (no residual)
   Bool          isBipredRestriction( UInt puIdx );
-#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
-  Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
-#endif
 
   // -------------------------------------------------------------------------------------------------------------------
@@ -525,12 +457,19 @@
 
 #if SVC_EXTENSION
+  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt          getLayerId ()               { return m_layerId; }
+#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
+  Bool          isInterLayerReference(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
+#endif
 #if FAST_INTRA_SHVC
   Int           reduceSetOfIntraModes              (  UInt   uiAbsPartIdx, Int* uiIntraDirPred, Int &fullSetOfModes );
 #endif
-
 #if REF_IDX_ME_ZEROMV
   Bool xCheckZeroMVILRMerge(UChar uhInterDir, TComMvField& cMvFieldL0, TComMvField& cMvFieldL1);
   Bool xCheckZeroMVILRMvdL1Zero(Int iRefList, Int iRefIdx, Int MvpIdx);
 #endif
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
+  Void          scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
 #endif
 
@@ -546,9 +485,4 @@
   UInt          getCoefScanIdx(UInt uiAbsPartIdx, UInt uiWidth, Bool bIsLuma, Bool bIsIntra);
 
-#if SVC_EXTENSION
-  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
-  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping = 0 );
-  Void          scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
-#endif
 };
 
Index: trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComInterpolationFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComInterpolationFilter.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComInterpolationFilter.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComList.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComList.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComList.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComLoopFilter.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComLoopFilter.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComLoopFilter.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComLoopFilter.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComLoopFilter.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComMotionInfo.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComMotionInfo.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComMv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComMv.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComMv.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComPattern.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPattern.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPattern.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComPattern.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPattern.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPattern.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPic.cpp	(revision 595)
@@ -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.
  *
@@ -48,7 +48,4 @@
 TComPic::TComPic()
 : m_uiTLayer                              (0)
-#if SVC_EXTENSION
-, m_layerId( 0 )
-#endif
 , m_bUsedByCurr                           (false)
 , m_bIsLongTerm                           (false)
@@ -59,13 +56,8 @@
 , m_bNeededForOutput                      (false)
 , m_uiCurrSliceIdx                        (0)
-#if !HM_CLEANUP_SAO
-, m_pSliceSUMap                           (NULL)
-, m_pbValidSlice                          (NULL)
-, m_sliceGranularityForNDBFilter          (0)
-, m_bIndependentSliceBoundaryForNDBFilter (false)
-, m_bIndependentTileBoundaryForNDBFilter  (false)
-, m_pNDBFilterYuvTmp                      (NULL)
-#endif
 , m_bCheckLTMSB                           (false)
+#if SVC_EXTENSION
+, m_layerId( 0 )
+#endif
 {
 #if SVC_EXTENSION
@@ -214,5 +206,5 @@
   } 
 }
-#if HM_CLEANUP_SAO
+
 Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
 {
@@ -221,341 +213,4 @@
   return (mergeCtbInSliceSeg && mergeCtbInTile);
 }
-#else
-/** Create non-deblocked filter information
- * \param pSliceStartAddress array for storing slice start addresses
- * \param numSlices number of slices in picture
- * \param sliceGranularityDepth slice granularity 
- * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross".
- * \param numTiles number of tiles in picture
- * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross".
- */
-Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
-                                    ,std::vector<Bool>* LFCrossSliceBoundary
-                                    ,Int numTiles
-                                    ,Bool bNDBFilterCrossTileBoundary)
-{
-  UInt maxNumSUInLCU = getNumPartInCU();
-  UInt numLCUInPic   = getNumCUsInFrame();
-#if REPN_FORMAT_IN_VPS
-  UInt picWidth      = getSlice(0)->getPicWidthInLumaSamples();
-  UInt picHeight     = getSlice(0)->getPicHeightInLumaSamples();
-#else
-  UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
-  UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
-#endif
-  Int  numLCUsInPicWidth = getFrameWidthInCU();
-  Int  numLCUsInPicHeight= getFrameHeightInCU();
-  UInt maxNumSUInLCUWidth = getNumPartInWidth();
-  UInt maxNumSUInLCUHeight= getNumPartInHeight();
-  Int  numSlices = (Int) sliceStartAddress.size() - 1;
-  m_bIndependentSliceBoundaryForNDBFilter = false;
-  if(numSlices > 1)
-  {
-    for(Int s=0; s< numSlices; s++)
-    {
-      if((*LFCrossSliceBoundary)[s] == false)
-      {
-        m_bIndependentSliceBoundaryForNDBFilter = true;
-      }
-    }
-  }
-  m_sliceGranularityForNDBFilter = sliceGranularityDepth;
-  m_bIndependentTileBoundaryForNDBFilter  = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false));
-
-  m_pbValidSlice = new Bool[numSlices];
-  for(Int s=0; s< numSlices; s++)
-  {
-    m_pbValidSlice[s] = true;
-  }
-  m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic];
-
-  //initialization
-  for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ )
-  {
-    m_pSliceSUMap[i] = -1;
-  }
-  for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ )
-  {
-    TComDataCU* pcCU = getCU( CUAddr );
-    pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU)); 
-    pcCU->getNDBFilterBlocks()->clear();
-  }
-  m_vSliceCUDataLink.clear();
-
-  m_vSliceCUDataLink.resize(numSlices);
-
-  UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr;
-  UInt LPelX, TPelY, LCUX, LCUY;
-  UInt currSU;
-  UInt startSU, endSU;
-
-  for(Int s=0; s< numSlices; s++)
-  {
-    //1st step: decide the real start address
-    startAddr = sliceStartAddress[s];
-    endAddr   = sliceStartAddress[s+1] -1;
-
-    startLCU            = startAddr / maxNumSUInLCU;
-    firstCUInStartLCU   = startAddr % maxNumSUInLCU;
-
-    endLCU              = endAddr   / maxNumSUInLCU;
-    lastCUInEndLCU      = endAddr   % maxNumSUInLCU;   
-
-    uiAddr = m_apcPicSym->getCUOrderMap(startLCU);
-
-    LCUX      = getCU(uiAddr)->getCUPelX();
-    LCUY      = getCU(uiAddr)->getCUPelY();
-    LPelX     = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ];
-    TPelY     = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ];
-    currSU    = firstCUInStartLCU;
-
-    Bool bMoveToNextLCU = false;
-    Bool bSliceInOneLCU = (startLCU == endLCU);
-
-    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
-    {
-      currSU ++;
-
-      if(bSliceInOneLCU)
-      {
-        if(currSU > lastCUInEndLCU)
-        {
-          m_pbValidSlice[s] = false;
-          break;
-        }
-      }
-
-      if(currSU >= maxNumSUInLCU )
-      {
-        bMoveToNextLCU = true;
-        break;
-      }
-
-      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
-      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
-
-    }
-
-
-    if(!m_pbValidSlice[s])
-    {
-      continue;
-    }
-
-    if(currSU != firstCUInStartLCU)
-    {
-      if(!bMoveToNextLCU)
-      {
-        firstCUInStartLCU = currSU;
-      }
-      else
-      {
-        startLCU++;
-        firstCUInStartLCU = 0;
-        assert( startLCU < getNumCUsInFrame());
-      }
-      assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr);
-    }
-
-
-    //2nd step: assign NonDBFilterInfo to each processing block
-    for(UInt i= startLCU; i <= endLCU; i++)
-    {
-      startSU = (i == startLCU)?(firstCUInStartLCU):(0);
-      endSU   = (i == endLCU  )?(lastCUInEndLCU   ):(maxNumSUInLCU -1);
-
-      uiAddr = m_apcPicSym->getCUOrderMap(i);
-      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
-
-      TComDataCU* pcCU = getCU(uiAddr);
-      m_vSliceCUDataLink[s].push_back(pcCU);
-
-      createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight);
-    }
-  }
-
-  //step 3: border availability
-  for(Int s=0; s< numSlices; s++)
-  {
-    if(!m_pbValidSlice[s])
-    {
-      continue;
-    }
-
-    for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++)
-    {
-      TComDataCU* pcCU = m_vSliceCUDataLink[s][i];
-      uiAddr = pcCU->getAddr();
-
-      if(pcCU->getPic()==0)
-      {
-        continue;
-      }
-      Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
-      Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false;
-
-      if(m_bIndependentTileBoundaryForNDBFilter)
-      {
-        //left
-        if( uiAddr % numLCUsInPicWidth != 0)
-        {
-          bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false;
-        }
-        //right
-        if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) )
-        {
-          bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false;
-        }
-        //top
-        if( uiAddr >= numLCUsInPicWidth)
-        {
-          bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) !=  iTileID )?true:false;
-        }
-        //down
-        if( uiAddr + numLCUsInPicWidth < numLCUInPic )
-        {
-          bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false;
-        }
-
-      }
-
-      pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight
-        , *LFCrossSliceBoundary
-        ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary
-        ,m_bIndependentTileBoundaryForNDBFilter);
-
-    }
-
-  }
-
-  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
-  {
-    m_pNDBFilterYuvTmp = new TComPicYuv();
-#if AUXILIARY_PICTURES
-    m_pNDBFilterYuvTmp->create(picWidth, picHeight, getChromaFormat(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
-#else
-    m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
-#endif
-
-  }
-
-}
-
-/** Create non-deblocked filter information for LCU
- * \param tileID tile index
- * \param sliceID slice index
- * \param pcCU CU data pointer
- * \param startSU start SU index in LCU
- * \param endSU end SU index in LCU
- * \param sliceGranularyDepth slice granularity
- * \param picWidth picture width
- * \param picHeight picture height
- */
-Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight)
-{
-  UInt LCUX          = pcCU->getCUPelX();
-  UInt LCUY          = pcCU->getCUPelY();
-  Int* pCUSliceMap    = pcCU->getSliceSUMap();
-  UInt maxNumSUInLCU = getNumPartInCU();
-  UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1);
-  UInt maxNumSUInLCUWidth = getNumPartInWidth();
-  UInt LPelX, TPelY;
-  UInt currSU;
-
-
-  //get the number of valid NBFilterBLock
-  currSU   = startSU;
-  while(currSU <= endSU)
-  {
-    LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
-    TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
-
-    while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
-    {
-      currSU += maxNumSUInSGU;
-      if(currSU >= maxNumSUInLCU || currSU > endSU)
-      {
-        break;
-      }
-      LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
-      TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
-    }
-
-    if(currSU >= maxNumSUInLCU || currSU > endSU)
-    {
-      break;
-    }
-
-    NDBFBlockInfo NDBFBlock;
-
-    NDBFBlock.tileID  = tileID;
-    NDBFBlock.sliceID = sliceID;
-    NDBFBlock.posY    = TPelY;
-    NDBFBlock.posX    = LPelX;
-    NDBFBlock.startSU = currSU;
-
-    UInt uiLastValidSU  = currSU;
-    UInt uiIdx, uiLPelX_su, uiTPelY_su;
-    for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++)
-    {
-      if(uiIdx > endSU)
-      {
-        break;        
-      }
-      uiLPelX_su   = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
-      uiTPelY_su   = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
-      if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight ))
-      {
-        continue;
-      }
-      pCUSliceMap[uiIdx] = sliceID;
-      uiLastValidSU = uiIdx;
-    }
-    NDBFBlock.endSU = uiLastValidSU;
-
-    UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ];
-    UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU   ];
-    NDBFBlock.widthSU  = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1;
-    NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1;
-    NDBFBlock.width    = NDBFBlock.widthSU  * getMinCUWidth();
-    NDBFBlock.height   = NDBFBlock.heightSU * getMinCUHeight();
-
-    pcCU->getNDBFilterBlocks()->push_back(NDBFBlock);
-
-    currSU += maxNumSUInSGU;
-  }
-
-}
-
-/** destroy non-deblocked filter information for LCU
- */
-Void TComPic::destroyNonDBFilterInfo()
-{
-  if(m_pbValidSlice != NULL)
-  {
-    delete[] m_pbValidSlice;
-    m_pbValidSlice = NULL;
-  }
-
-  if(m_pSliceSUMap != NULL)
-  {
-    delete[] m_pSliceSUMap;
-    m_pSliceSUMap = NULL;
-  }
-  for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ )
-  {
-    TComDataCU* pcCU = getCU( CUAddr );
-    pcCU->getNDBFilterBlocks()->clear();
-  }
-
-  if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
-  {
-    m_pNDBFilterYuvTmp->destroy();
-    delete m_pNDBFilterYuvTmp;
-    m_pNDBFilterYuvTmp = NULL;
-  }
-
-}
-#endif
 
 #if SVC_EXTENSION
Index: trunk/source/Lib/TLibCommon/TComPic.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPic.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPic.h	(revision 595)
@@ -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.
  *
@@ -61,7 +61,4 @@
 private:
   UInt                  m_uiTLayer;               //  Temporal layer
-#if SVC_EXTENSION
-  UInt                  m_layerId;              //  Layer ID
-#endif
   Bool                  m_bUsedByCurr;            //  Used by current picture
   Bool                  m_bIsLongTerm;            //  IS long term picture
@@ -75,12 +72,4 @@
   Bool                  m_bNeededForOutput;
   UInt                  m_uiCurrSliceIdx;         // Index of current slice
-#if !HM_CLEANUP_SAO
-  Int*                  m_pSliceSUMap;
-  Bool*                 m_pbValidSlice;
-  Int                   m_sliceGranularityForNDBFilter;
-  Bool                  m_bIndependentSliceBoundaryForNDBFilter;
-  Bool                  m_bIndependentTileBoundaryForNDBFilter;
-  TComPicYuv*           m_pNDBFilterYuvTmp;    //!< temporary picture buffer when non-cross slice/tile boundary in-loop filtering is enabled
-#endif
   Bool                  m_bCheckLTMSB;
   
@@ -96,4 +85,5 @@
   SEIMessages  m_SEIs; ///< Any SEI messages that have been received.  If !NULL we own the object.
 #if SVC_EXTENSION
+  UInt                  m_layerId;              //  Layer ID
   Bool                  m_bSpatialEnhLayer[MAX_LAYERS];       // whether current layer is a spatial enhancement layer,
   TComPicYuv*           m_pcFullPelBaseRec[MAX_LAYERS];    // upsampled base layer recontruction for difference domain inter prediction
@@ -125,24 +115,4 @@
   UInt          getTLayer()                { return m_uiTLayer;   }
   Void          setTLayer( UInt uiTLayer ) { m_uiTLayer = uiTLayer; }
-#if SVC_EXTENSION
-  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
-  UInt          getLayerId ()               { return m_layerId; }
-  Bool          isSpatialEnhLayer(UInt refLayerIdc)             { return m_bSpatialEnhLayer[refLayerIdc]; }
-  Void          setSpatialEnhLayerFlag (UInt refLayerIdc, Bool b) { m_bSpatialEnhLayer[refLayerIdc] = b; }
-  Void          setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
-  TComPicYuv*   getFullPelBaseRec   (UInt refLayerIdc)  { return  m_pcFullPelBaseRec[refLayerIdc];  }
-#endif
-#if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
-  Bool          isILR( UInt currLayerId )   { return ( getIsLongTerm() && m_layerId < currLayerId ); }
-#endif
-
-#if REF_IDX_MFM
-  Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
-  Void          initUpsampledMvField  ();
-#endif
-#if MFM_ENCCONSTRAINT
-  Bool          checkSameRefInfo();
-#endif
-
   Bool          getUsedByCurr()             { return m_bUsedByCurr; }
   Void          setUsedByCurr( Bool bUsed ) { m_bUsedByCurr = bUsed; }
@@ -178,7 +148,4 @@
   
   Int           getStride()           { return m_apcPicYuv[1]->getStride(); }
-#if AUXILIARY_PICTURES
-  ChromaFormat  getChromaFormat() const { return m_apcPicYuv[1]->getChromaFormat(); }
-#endif
   Int           getCStride()          { return m_apcPicYuv[1]->getCStride(); }
   
@@ -201,20 +168,5 @@
   Window&       getDefDisplayWindow()   { return m_defaultDisplayWindow; }
 
-#if HM_CLEANUP_SAO
   Bool          getSAOMergeAvailability(Int currAddr, Int mergeAddr);
-#else
-  Void          createNonDBFilterInfo   (std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
-                                        ,std::vector<Bool>* LFCrossSliceBoundary
-                                        ,Int  numTiles = 1
-                                        ,Bool bNDBFilterCrossTileBoundary = true);
-  Void          createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight);
-  Void          destroyNonDBFilterInfo();
-
-  Bool          getValidSlice                                  (Int sliceID)  {return m_pbValidSlice[sliceID];}
-  Bool          getIndependentSliceBoundaryForNDBFilter        ()             {return m_bIndependentSliceBoundaryForNDBFilter;}
-  Bool          getIndependentTileBoundaryForNDBFilter         ()             {return m_bIndependentTileBoundaryForNDBFilter; }
-  TComPicYuv*   getYuvPicBufferForIndependentBoundaryProcessing()             {return m_pNDBFilterYuvTmp;}
-  std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
-#endif
 
   /* field coding parameters*/
@@ -239,4 +191,23 @@
 
 #if SVC_EXTENSION
+  Void          setLayerId (UInt layerId) { m_layerId = layerId; }
+  UInt          getLayerId ()               { return m_layerId; }
+  Bool          isSpatialEnhLayer(UInt refLayerIdc)             { return m_bSpatialEnhLayer[refLayerIdc]; }
+  Void          setSpatialEnhLayerFlag (UInt refLayerIdc, Bool b) { m_bSpatialEnhLayer[refLayerIdc] = b; }
+  Void          setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
+  TComPicYuv*   getFullPelBaseRec   (UInt refLayerIdc)  { return  m_pcFullPelBaseRec[refLayerIdc];  }
+#if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
+  Bool          isILR( UInt currLayerId )   { return ( getIsLongTerm() && m_layerId < currLayerId ); }
+#endif
+#if REF_IDX_MFM
+  Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
+  Void          initUpsampledMvField  ();
+#endif
+#if MFM_ENCCONSTRAINT
+  Bool          checkSameRefInfo();
+#endif
+#if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat() const { return m_apcPicYuv[1]->getChromaFormat(); }
+#endif
   Void  copyUpsampledPictureYuv(TComPicYuv*   pcPicYuvIn, TComPicYuv*   pcPicYuvOut); 
 #if AVC_SYNTAX
Index: trunk/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPicSym.cpp	(revision 595)
@@ -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.
  *
@@ -67,7 +67,5 @@
 ,m_puiTileIdxMap(NULL)
 ,m_puiInverseCUOrderMap(NULL)
-#if HM_CLEANUP_SAO
 ,m_saoBlkParams(NULL)
-#endif
 {};
 
@@ -131,9 +129,5 @@
   }
 
-#if HM_CLEANUP_SAO
   m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame];
-#else
-  m_saoParam = NULL;
-#endif
 }
 
@@ -191,17 +185,8 @@
   m_puiInverseCUOrderMap = NULL;
   
-#if HM_CLEANUP_SAO
   if(m_saoBlkParams)
   {
     delete[] m_saoBlkParams; m_saoBlkParams = NULL;
   }
-#else
-  if (m_saoParam)
-  {
-    TComSampleAdaptiveOffset::freeSaoParam(m_saoParam);
-    delete m_saoParam;
-    m_saoParam = NULL;
-  }
-#endif
 }
 
@@ -347,6 +332,4 @@
 }
 
-
-#if HM_CLEANUP_SAO
 Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu,
                                                       Bool& isLeftAvail,
@@ -419,10 +402,10 @@
       if(ctuAboveRigtht != NULL)
       {
-        Int curSliceStartTS  = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
-        Int aboveRigthtSliceStartTS = getCUOrderMap(ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
-
-        isAboveRightAvail = (curSliceStartTS == aboveRigthtSliceStartTS)?(true):
+        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
+        Int aboveRigthtSliceStartEncOrder = ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr();
+
+        isAboveRightAvail = (curSliceStartEncOrder == aboveRigthtSliceStartEncOrder)?(true):
           (
-          (curSliceStartTS > aboveRigthtSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
+          (curSliceStartEncOrder > aboveRigthtSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
           :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag())
           );          
@@ -431,10 +414,10 @@
       if(ctuBelowLeft != NULL)
       {
-        Int curSliceStartTS       = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
-        Int belowLeftSliceStartTS = getCUOrderMap(ctuBelowLeft->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions);
-
-        isBelowLeftAvail = (curSliceStartTS == belowLeftSliceStartTS)?(true):
+        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
+        Int belowLeftSliceStartEncOrder = ctuBelowLeft->getSlice()->getSliceCurStartCUAddr();
+
+        isBelowLeftAvail = (curSliceStartEncOrder == belowLeftSliceStartEncOrder)?(true):
           (
-          (curSliceStartTS > belowLeftSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
+          (curSliceStartEncOrder > belowLeftSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
           :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag())
           );
@@ -456,11 +439,4 @@
 
 }
-#else
-Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao)
-{
-  m_saoParam = new SAOParam;
-  sao->allocSaoParam(m_saoParam);
-}
-#endif
 
 TComTile::TComTile()
Index: trunk/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPicSym.h	(revision 595)
@@ -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.
  *
@@ -105,4 +105,9 @@
   UInt*         m_puiCUOrderMap;       //the map of LCU raster scan address relative to LCU encoding order 
   UInt*         m_puiTileIdxMap;       //the map of the tile index relative to LCU raster scan address 
+  UInt*         m_puiInverseCUOrderMap;
+
+  SAOBlkParam *m_saoBlkParams;
+
+#if SVC_EXTENSION
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   Int*          m_piTileSetIdxMap;     //the map of the tile set index relative to LCU raster scan address
@@ -110,10 +115,4 @@
   Bool*         m_pbSkippedTileSetFlag;
 #endif
-  UInt*         m_puiInverseCUOrderMap;
-
-#if HM_CLEANUP_SAO
-  SAOBlkParam *m_saoBlkParams;
-#else
-  SAOParam *m_saoParam;
 #endif
 
@@ -130,15 +129,4 @@
   UInt        getNumberOfCUsInFrame()   { return m_uiNumCUsInFrame;  }
   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;                }
-  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
-  UInt        getMaxDepth()             { return m_uhTotalDepth;               }
-#endif
   
   Void        setSlice(TComSlice* p, UInt i) { m_apcTComSlice[i] = p;           }
@@ -158,4 +146,24 @@
   UInt         getCUOrderMap( Int encCUOrder )                       { return *(m_puiCUOrderMap + (encCUOrder>=m_uiNumCUsInFrame ? m_uiNumCUsInFrame : encCUOrder)); }
   UInt         getTileIdxMap( Int i )                                { return *(m_puiTileIdxMap + i); }
+  Void         setInverseCUOrderMap( Int cuAddr, Int encCUOrder )    { *(m_puiInverseCUOrderMap + cuAddr) = encCUOrder; }
+  UInt         getInverseCUOrderMap( Int cuAddr )                    { return *(m_puiInverseCUOrderMap + (cuAddr>=m_uiNumCUsInFrame ? m_uiNumCUsInFrame : cuAddr)); }
+  UInt         getPicSCUEncOrder( UInt SCUAddr );
+  UInt         getPicSCUAddr( UInt SCUEncOrder );
+  Void         xCreateTComTileArray();
+  Void         xInitTiles();
+  UInt         xCalculateNxtCUAddr( UInt uiCurrCUAddr );
+  SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;}
+  Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail);
+
+#if SVC_EXTENSION
+#if LAYER_CTB
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+#endif
+#if AVC_SYNTAX
+  UInt        getMaxCUWidth()           { return m_uiMaxCUWidth;                }
+  UInt        getMaxCUHeight()          { return m_uiMaxCUHeight;               }
+  UInt        getMaxDepth()             { return m_uhTotalDepth;               }
+#endif
 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
   Void         setTileSetIdxMap( Int i, Int tileSetIdx, UChar setType, Bool skipFlag )
@@ -169,20 +177,5 @@
   Bool         getSkippedTileSetFlag( Int i )                        { return *(m_pbSkippedTileSetFlag + i); }
 #endif
-  Void         setInverseCUOrderMap( Int cuAddr, Int encCUOrder )    { *(m_puiInverseCUOrderMap + cuAddr) = encCUOrder; }
-  UInt         getInverseCUOrderMap( Int cuAddr )                    { return *(m_puiInverseCUOrderMap + (cuAddr>=m_uiNumCUsInFrame ? m_uiNumCUsInFrame : cuAddr)); }
-  UInt         getPicSCUEncOrder( UInt SCUAddr );
-  UInt         getPicSCUAddr( UInt SCUEncOrder );
-  Void         xCreateTComTileArray();
-  Void         xInitTiles();
-  UInt         xCalculateNxtCUAddr( UInt uiCurrCUAddr );
-#if HM_CLEANUP_SAO
-  SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;}
-  Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail);
-#else
-  Void allocSaoParam(TComSampleAdaptiveOffset *sao);
-  SAOParam *getSaoParam() { return m_saoParam; }
-#endif
-
-
+#endif //SVC_EXTENSION
 };// END CLASS DEFINITION TComPicSym
 
Index: trunk/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComPicYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPicYuv.h	(revision 595)
@@ -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.
  *
@@ -75,7 +75,4 @@
   Int   m_iPicWidth;            ///< Width of picture
   Int   m_iPicHeight;           ///< Height of picture
-#if AUXILIARY_PICTURES
-  ChromaFormat m_chromaFormatIDC; ////< Chroma Format
-#endif
   
   Int   m_iCuWidth;             ///< Width of Coding Unit (CU)
@@ -91,13 +88,17 @@
   Int   m_iChromaMarginY;
   
+  Bool  m_bIsBorderExtended;
+
+#if SVC_EXTENSION
+#if AUXILIARY_PICTURES
+  ChromaFormat m_chromaFormatIDC; ////< Chroma Format
+#endif
 #if SVC_UPSAMPLING
   Window  m_conformanceWindow;
 #endif
-
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Bool    m_isReconstructed;
 #endif
-
-  Bool  m_bIsBorderExtended;
+#endif //SVC_EXTENSION
   
 protected:
@@ -136,11 +137,4 @@
   Int   getWidth    ()     { return  m_iPicWidth;    }
   Int   getHeight   ()     { return  m_iPicHeight;   }
-#if AUXILIARY_PICTURES
-  ChromaFormat  getChromaFormat   ()                     const { return m_chromaFormatIDC; }
-#endif
-  
-#if SVC_EXTENSION
-  Void   setHeight   ( Int iPicHeight )     { m_iPicHeight = iPicHeight; }
-#endif
 
   Int   getStride   ()     { return (m_iPicWidth     ) + (m_iLumaMarginX  <<1); }
@@ -172,9 +166,4 @@
   Pel*  getCrAddr   ( Int iCuAddr, Int uiAbsZorderIdx ) { return m_piPicOrgV + m_cuOffsetC[iCuAddr] + m_buOffsetC[g_auiZscanToRaster[uiAbsZorderIdx]]; }
   
-#if SVC_UPSAMPLING
-  Window& getConformanceWindow()                           { return  m_conformanceWindow;             }
-  Void    setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
-#endif
-
   // ------------------------------------------------------------------------------------------------
   //  Miscellaneous
@@ -193,15 +182,23 @@
   Void  dump (Char* pFileName, Bool bAdd = false);
 
+  // Set border extension flag
+  Void  setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
+  
+#if SVC_EXTENSION
+  Void   setHeight   ( Int iPicHeight )     { m_iPicHeight = iPicHeight; }
+#if SVC_UPSAMPLING
+  Window& getConformanceWindow()                           { return  m_conformanceWindow;             }
+  Void    setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
+#endif
 #if M0040_ADAPTIVE_RESOLUTION_CHANGE
   Void  setReconstructed(Bool x) { m_isReconstructed = x;    }
   Bool  isReconstructed()        { return m_isReconstructed; }
 #endif
-
 #if AUXILIARY_PICTURES
+  ChromaFormat  getChromaFormat   ()                     const { return m_chromaFormatIDC; }
   Void convertToMonochrome();
 #endif
-
-  // Set border extension flag
-  Void  setBorderExtension(Bool b) { m_bIsBorderExtended = b; }
+#endif //SVC_EXTENSION
+
 };// END CLASS DEFINITION TComPicYuv
 
Index: trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPicYuvMD5.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPrediction.cpp	(revision 595)
@@ -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.
  *
@@ -408,4 +408,5 @@
 }
 
+
 Void TComPrediction::motionCompensation ( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx )
 {
Index: trunk/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComPrediction.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComRdCost.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRdCost.cpp	(revision 595)
@@ -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.
  *
@@ -410,6 +410,8 @@
     }
   }
-  else if ( ( (iWidth % 4) == 0 ) && ( (iHeight % 4) == 0 ) )
-  {
+  else
+  {
+    assert(iWidth % 4 == 0 && iHeight % 4 == 0);
+    
     for ( y=0; y<iHeight; y+= 4 )
     {
@@ -420,16 +422,4 @@
       pi0 += iStride0*4;
       pi1 += iStride1*4;
-    }
-  }
-  else
-  {
-    for ( y=0; y<iHeight; y+= 2 )
-    {
-      for ( x=0; x<iWidth; x+= 2 )
-      {
-        uiSum += xCalcHADs8x8( &pi0[x], &pi1[x], iStride0, iStride1, 1 );
-      }
-      pi0 += iStride0*2;
-      pi1 += iStride1*2;
     }
   }
Index: trunk/source/Lib/TLibCommon/TComRdCost.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRdCost.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComRom.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRom.cpp	(revision 595)
@@ -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.
  *
@@ -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;
@@ -106,9 +97,4 @@
 
 UInt g_auiPUOffset[8] = { 0, 8, 4, 4, 2, 10, 1, 5};
-
-#if FAST_INTRA_SHVC
-UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
-UInt g_predefSetIntraModes[NUM_INTRA_MODE-1] = {26,10,18,34,2,22,14,30,6,24,12,28,8,20,16,32,4,17,19,15,21,13,23,11,25,9,27,7,29,5,31,3,33,0,2};
-#endif
 
 Void initZscanToRaster ( Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt*& rpuiCurrIdx )
@@ -321,14 +307,5 @@
 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.
@@ -528,4 +505,18 @@
 
 #if SVC_EXTENSION
+#if FAST_INTRA_SHVC
+UInt g_reducedSetIntraModes[NUM_INTRA_MODE-1] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; 
+UInt g_predefSetIntraModes[NUM_INTRA_MODE-1] = {26,10,18,34,2,22,14,30,6,24,12,28,8,20,16,32,4,17,19,15,21,13,23,11,25,9,27,7,29,5,31,3,33,0,2};
+#endif
+#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
 Int g_mvScalingFactor  [MAX_LAYERS][2] = {{0,0}, {0,0}};
 Int g_posScalingFactor [MAX_LAYERS][2] = {{0,0}, {0,0}};
@@ -571,5 +562,15 @@
   };
 }
+#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
+#endif //SVC_EXTENSION
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComRom.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComRom.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComRom.h	(revision 595)
@@ -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.
  *
@@ -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;
@@ -139,9 +129,4 @@
 
 extern const UChar  g_aucIntraModeNumFast[ MAX_CU_DEPTH ];
-
-#if FAST_INTRA_SHVC
-extern       UInt  g_reducedSetIntraModes[NUM_INTRA_MODE-1];
-extern       UInt  g_predefSetIntraModes[NUM_INTRA_MODE-1];
-#endif
 
 // ====================================================================================================================
@@ -287,8 +272,22 @@
 
 #if SVC_EXTENSION
+#if FAST_INTRA_SHVC
+extern       UInt  g_reducedSetIntraModes[NUM_INTRA_MODE-1];
+extern       UInt  g_predefSetIntraModes[NUM_INTRA_MODE-1];
+#endif
 extern Int g_mvScalingFactor  [MAX_LAYERS][2];
 extern Int g_posScalingFactor [MAX_LAYERS][2];
 std::string NaluToStr( NalUnitType nalu );
-#endif
+#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
+#endif //SVC_EXTENSION
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp	(revision 595)
@@ -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.
  *
@@ -44,5 +44,4 @@
 //! \ingroup TLibCommon
 //! \{
-#if HM_CLEANUP_SAO
 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 
 
@@ -698,1326 +697,5 @@
   return pBuf;
 }
-#else
-
-SAOParam::~SAOParam()
-{
-  for (Int i = 0 ; i<3; i++)
-  {
-    if (psSaoPart[i])
-    {
-      delete [] psSaoPart[i];
-    }
-  }
-}
-
-// ====================================================================================================================
-// Tables
-// ====================================================================================================================
-
-TComSampleAdaptiveOffset::TComSampleAdaptiveOffset()
-{
-  m_pClipTable = NULL;
-  m_pClipTableBase = NULL;
-  m_pChromaClipTable = NULL;
-  m_pChromaClipTableBase = NULL;
-  m_iOffsetBo = NULL;
-  m_iChromaOffsetBo = NULL;
-  m_lumaTableBo = NULL;
-  m_chromaTableBo = NULL;
-  m_iUpBuff1 = NULL;
-  m_iUpBuff2 = NULL;
-  m_iUpBufft = NULL;
-  ipSwap = NULL;
-
-  m_pTmpU1 = NULL;
-  m_pTmpU2 = NULL;
-  m_pTmpL1 = NULL;
-  m_pTmpL2 = NULL;
-}
-
-TComSampleAdaptiveOffset::~TComSampleAdaptiveOffset()
-{
-
-}
-
-const Int TComSampleAdaptiveOffset::m_aiNumCulPartsLevel[5] =
-{
-  1,   //level 0
-  5,   //level 1
-  21,  //level 2
-  85,  //level 3
-  341, //level 4
-};
-
-const UInt TComSampleAdaptiveOffset::m_auiEoTable[9] =
-{
-  1, //0    
-  2, //1   
-  0, //2
-  3, //3
-  4, //4
-  0, //5  
-  0, //6  
-  0, //7 
-  0
-};
-
-const Int TComSampleAdaptiveOffset::m_iNumClass[MAX_NUM_SAO_TYPE] =
-{
-  SAO_EO_LEN,
-  SAO_EO_LEN,
-  SAO_EO_LEN,
-  SAO_EO_LEN,
-  SAO_BO_LEN
-};
-
-const UInt TComSampleAdaptiveOffset::m_uiMaxDepth = SAO_MAX_DEPTH;
-
-
-/** convert Level Row Col to Idx
- * \param   level,  row,  col
- */
-Int  TComSampleAdaptiveOffset::convertLevelRowCol2Idx(Int level, Int row, Int col)
-{
-  Int idx;
-  if (level == 0)
-  {
-    idx = 0;
-  }
-  else if (level == 1)
-  {
-    idx = 1 + row*2 + col;
-  }
-  else if (level == 2)
-  {
-    idx = 5 + row*4 + col;
-  }
-  else if (level == 3)
-  {
-    idx = 21 + row*8 + col;
-  }
-  else // (level == 4)
-  {
-    idx = 85 + row*16 + col;
-  }
-  return idx;
-}
-
-/** create SampleAdaptiveOffset memory.
- * \param 
- */
-Void TComSampleAdaptiveOffset::create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight )
-{
-  m_iPicWidth  = uiSourceWidth;
-  m_iPicHeight = uiSourceHeight;
-
-  m_uiMaxCUWidth  = uiMaxCUWidth;
-  m_uiMaxCUHeight = uiMaxCUHeight;
-
-  m_iNumCuInWidth  = m_iPicWidth / m_uiMaxCUWidth;
-  m_iNumCuInWidth += ( m_iPicWidth % m_uiMaxCUWidth ) ? 1 : 0;
-
-  m_iNumCuInHeight  = m_iPicHeight / m_uiMaxCUHeight;
-  m_iNumCuInHeight += ( m_iPicHeight % m_uiMaxCUHeight ) ? 1 : 0;
-
-  Int iMaxSplitLevelHeight = (Int)(logf((Float)m_iNumCuInHeight)/logf(2.0));
-  Int iMaxSplitLevelWidth  = (Int)(logf((Float)m_iNumCuInWidth )/logf(2.0));
-
-  m_uiMaxSplitLevel = (iMaxSplitLevelHeight < iMaxSplitLevelWidth)?(iMaxSplitLevelHeight):(iMaxSplitLevelWidth);
-  m_uiMaxSplitLevel = (m_uiMaxSplitLevel< m_uiMaxDepth)?(m_uiMaxSplitLevel):(m_uiMaxDepth);
-  /* various structures are overloaded to store per component data.
-   * m_iNumTotalParts must allow for sufficient storage in any allocated arrays */
-  m_iNumTotalParts  = max(3,m_aiNumCulPartsLevel[m_uiMaxSplitLevel]);
-
-  UInt uiPixelRangeY = 1 << g_bitDepthY;
-  UInt uiBoRangeShiftY = g_bitDepthY - SAO_BO_BITS;
-
-  m_lumaTableBo = new Pel [uiPixelRangeY];
-  for (Int k2=0; k2<uiPixelRangeY; k2++)
-  {
-    m_lumaTableBo[k2] = 1 + (k2>>uiBoRangeShiftY);
-  }
-
-  UInt uiPixelRangeC = 1 << g_bitDepthC;
-  UInt uiBoRangeShiftC = g_bitDepthC - SAO_BO_BITS;
-
-  m_chromaTableBo = new Pel [uiPixelRangeC];
-  for (Int k2=0; k2<uiPixelRangeC; k2++)
-  {
-    m_chromaTableBo[k2] = 1 + (k2>>uiBoRangeShiftC);
-  }
-
-  m_iUpBuff1 = new Int[m_iPicWidth+2];
-  m_iUpBuff2 = new Int[m_iPicWidth+2];
-  m_iUpBufft = new Int[m_iPicWidth+2];
-
-  m_iUpBuff1++;
-  m_iUpBuff2++;
-  m_iUpBufft++;
-  Pel i;
-
-  UInt uiMaxY  = (1 << g_bitDepthY) - 1;;
-  UInt uiMinY  = 0;
-
-  Int iCRangeExt = uiMaxY>>1;
-
-  m_pClipTableBase = new Pel[uiMaxY+2*iCRangeExt];
-  m_iOffsetBo      = new Int[uiMaxY+2*iCRangeExt];
-
-  for(i=0;i<(uiMinY+iCRangeExt);i++)
-  {
-    m_pClipTableBase[i] = uiMinY;
-  }
-
-  for(i=uiMinY+iCRangeExt;i<(uiMaxY+  iCRangeExt);i++)
-  {
-    m_pClipTableBase[i] = i-iCRangeExt;
-  }
-
-  for(i=uiMaxY+iCRangeExt;i<(uiMaxY+2*iCRangeExt);i++)
-  {
-    m_pClipTableBase[i] = uiMaxY;
-  }
-
-  m_pClipTable = &(m_pClipTableBase[iCRangeExt]);
-
-  UInt uiMaxC  = (1 << g_bitDepthC) - 1;
-  UInt uiMinC  = 0;
-
-  Int iCRangeExtC = uiMaxC>>1;
-
-  m_pChromaClipTableBase = new Pel[uiMaxC+2*iCRangeExtC];
-  m_iChromaOffsetBo      = new Int[uiMaxC+2*iCRangeExtC];
-
-  for(i=0;i<(uiMinC+iCRangeExtC);i++)
-  {
-    m_pChromaClipTableBase[i] = uiMinC;
-  }
-
-  for(i=uiMinC+iCRangeExtC;i<(uiMaxC+  iCRangeExtC);i++)
-  {
-    m_pChromaClipTableBase[i] = i-iCRangeExtC;
-  }
-
-  for(i=uiMaxC+iCRangeExtC;i<(uiMaxC+2*iCRangeExtC);i++)
-  {
-    m_pChromaClipTableBase[i] = uiMaxC;
-  }
-
-  m_pChromaClipTable = &(m_pChromaClipTableBase[iCRangeExtC]);
-
-  m_pTmpL1 = new Pel [m_uiMaxCUHeight+1];
-  m_pTmpL2 = new Pel [m_uiMaxCUHeight+1];
-  m_pTmpU1 = new Pel [m_iPicWidth];
-  m_pTmpU2 = new Pel [m_iPicWidth];
-}
-
-/** destroy SampleAdaptiveOffset memory.
- * \param 
- */
-Void TComSampleAdaptiveOffset::destroy()
-{
-  if (m_pClipTableBase)
-  {
-    delete [] m_pClipTableBase; m_pClipTableBase = NULL;
-  }
-  if (m_iOffsetBo)
-  {
-    delete [] m_iOffsetBo; m_iOffsetBo = NULL;
-  }
-  if (m_lumaTableBo)
-  {
-    delete[] m_lumaTableBo; m_lumaTableBo = NULL;
-  }
-
-  if (m_pChromaClipTableBase)
-  {
-    delete [] m_pChromaClipTableBase; m_pChromaClipTableBase = NULL;
-  }
-  if (m_iChromaOffsetBo)
-  {
-    delete [] m_iChromaOffsetBo; m_iChromaOffsetBo = NULL;
-  }
-  if (m_chromaTableBo)
-  {
-    delete[] m_chromaTableBo; m_chromaTableBo = NULL;
-  }
-
-  if (m_iUpBuff1)
-  {
-    m_iUpBuff1--;
-    delete [] m_iUpBuff1; m_iUpBuff1 = NULL;
-  }
-  if (m_iUpBuff2)
-  {
-    m_iUpBuff2--;
-    delete [] m_iUpBuff2; m_iUpBuff2 = NULL;
-  }
-  if (m_iUpBufft)
-  {
-    m_iUpBufft--;
-    delete [] m_iUpBufft; m_iUpBufft = NULL;
-  }
-  if (m_pTmpL1)
-  {
-    delete [] m_pTmpL1; m_pTmpL1 = NULL;
-  }
-  if (m_pTmpL2)
-  {
-    delete [] m_pTmpL2; m_pTmpL2 = NULL;
-  }
-  if (m_pTmpU1)
-  {
-    delete [] m_pTmpU1; m_pTmpU1 = NULL;
-  }
-  if (m_pTmpU2)
-  {
-    delete [] m_pTmpU2; m_pTmpU2 = NULL;
-  }
-}
-
-/** allocate memory for SAO parameters
- * \param    *pcSaoParam
- */
-Void TComSampleAdaptiveOffset::allocSaoParam(SAOParam *pcSaoParam)
-{
-  pcSaoParam->iMaxSplitLevel = m_uiMaxSplitLevel;
-  pcSaoParam->psSaoPart[0] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
-  initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,0);
-  pcSaoParam->psSaoPart[1] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
-  pcSaoParam->psSaoPart[2] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
-  initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,1);
-  initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,2);
-  pcSaoParam->numCuInWidth  = m_iNumCuInWidth;
-  pcSaoParam->numCuInHeight = m_iNumCuInHeight;
-  pcSaoParam->saoLcuParam[0] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
-  pcSaoParam->saoLcuParam[1] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
-  pcSaoParam->saoLcuParam[2] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
-}
-
-/** initialize SAO parameters
- * \param    *pcSaoParam,  iPartLevel,  iPartRow,  iPartCol,  iParentPartIdx,  StartCUX,  EndCUX,  StartCUY,  EndCUY,  iYCbCr
- */
-Void TComSampleAdaptiveOffset::initSAOParam(SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr)
-{
-  Int j;
-  Int iPartIdx = convertLevelRowCol2Idx(iPartLevel, iPartRow, iPartCol);
-
-  SAOQTPart* pSaoPart;
-
-  pSaoPart = &(pcSaoParam->psSaoPart[iYCbCr][iPartIdx]);
-
-  pSaoPart->PartIdx   = iPartIdx;
-  pSaoPart->PartLevel = iPartLevel;
-  pSaoPart->PartRow   = iPartRow;
-  pSaoPart->PartCol   = iPartCol;
-
-  pSaoPart->StartCUX  = StartCUX;
-  pSaoPart->EndCUX    = EndCUX;
-  pSaoPart->StartCUY  = StartCUY;
-  pSaoPart->EndCUY    = EndCUY;
-
-  pSaoPart->UpPartIdx = iParentPartIdx;
-  pSaoPart->iBestType   = -1;
-  pSaoPart->iLength     =  0;
-
-  pSaoPart->subTypeIdx = 0;
-
-  for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
-  {
-    pSaoPart->iOffset[j] = 0;
-  }
-
-  if(pSaoPart->PartLevel != m_uiMaxSplitLevel)
-  {
-    Int DownLevel    = (iPartLevel+1 );
-    Int DownRowStart = (iPartRow << 1);
-    Int DownColStart = (iPartCol << 1);
-
-    Int iDownRowIdx, iDownColIdx;
-    Int NumCUWidth,  NumCUHeight;
-    Int NumCULeft;
-    Int NumCUTop;
-
-    Int DownStartCUX, DownStartCUY;
-    Int DownEndCUX, DownEndCUY;
-
-    NumCUWidth  = EndCUX - StartCUX +1;
-    NumCUHeight = EndCUY - StartCUY +1;
-    NumCULeft   = (NumCUWidth  >> 1);
-    NumCUTop    = (NumCUHeight >> 1);
-
-    DownStartCUX= StartCUX;
-    DownEndCUX  = DownStartCUX + NumCULeft - 1;
-    DownStartCUY= StartCUY;
-    DownEndCUY  = DownStartCUY + NumCUTop  - 1;
-    iDownRowIdx = DownRowStart + 0;
-    iDownColIdx = DownColStart + 0;
-
-    pSaoPart->DownPartsIdx[0]= convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
-
-    initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
-
-    DownStartCUX = StartCUX + NumCULeft;
-    DownEndCUX   = EndCUX;
-    DownStartCUY = StartCUY;
-    DownEndCUY   = DownStartCUY + NumCUTop -1;
-    iDownRowIdx  = DownRowStart + 0;
-    iDownColIdx  = DownColStart + 1;
-
-    pSaoPart->DownPartsIdx[1] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
-
-    initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx,  DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
-
-    DownStartCUX = StartCUX;
-    DownEndCUX   = DownStartCUX + NumCULeft -1;
-    DownStartCUY = StartCUY + NumCUTop;
-    DownEndCUY   = EndCUY;
-    iDownRowIdx  = DownRowStart + 1;
-    iDownColIdx  = DownColStart + 0;
-
-    pSaoPart->DownPartsIdx[2] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
-
-    initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
-
-    DownStartCUX = StartCUX+ NumCULeft;
-    DownEndCUX   = EndCUX;
-    DownStartCUY = StartCUY + NumCUTop;
-    DownEndCUY   = EndCUY;
-    iDownRowIdx  = DownRowStart + 1;
-    iDownColIdx  = DownColStart + 1;
-
-    pSaoPart->DownPartsIdx[3] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
-
-    initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx,DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
-  }
-  else
-  {
-    pSaoPart->DownPartsIdx[0]=pSaoPart->DownPartsIdx[1]= pSaoPart->DownPartsIdx[2]= pSaoPart->DownPartsIdx[3]= -1; 
-  }
-}
-
-/** free memory of SAO parameters
- * \param   pcSaoParam
- */
-Void TComSampleAdaptiveOffset::freeSaoParam(SAOParam *pcSaoParam)
-{
-  delete [] pcSaoParam->psSaoPart[0];
-  delete [] pcSaoParam->psSaoPart[1];
-  delete [] pcSaoParam->psSaoPart[2];
-  pcSaoParam->psSaoPart[0] = 0;
-  pcSaoParam->psSaoPart[1] = 0;
-  pcSaoParam->psSaoPart[2] = 0;
-  if( pcSaoParam->saoLcuParam[0]) 
-  {
-    delete [] pcSaoParam->saoLcuParam[0]; pcSaoParam->saoLcuParam[0] = NULL;
-  }
-  if( pcSaoParam->saoLcuParam[1]) 
-  {
-    delete [] pcSaoParam->saoLcuParam[1]; pcSaoParam->saoLcuParam[1] = NULL;
-  }
-  if( pcSaoParam->saoLcuParam[2]) 
-  {
-    delete [] pcSaoParam->saoLcuParam[2]; pcSaoParam->saoLcuParam[2] = NULL;
-  }
-} 
-
-/** reset SAO parameters
- * \param   pcSaoParam
- */
-Void TComSampleAdaptiveOffset::resetSAOParam(SAOParam *pcSaoParam)
-{
-  Int iNumComponet = 3;
-  for(Int c=0; c<iNumComponet; c++)
-  {
-if (c<2)
-  {
-    pcSaoParam->bSaoFlag[c] = 0;
-  }
-    for(Int i=0; i< m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; i++)
-    {
-      pcSaoParam->psSaoPart[c][i].iBestType     = -1;
-      pcSaoParam->psSaoPart[c][i].iLength       =  0;
-      pcSaoParam->psSaoPart[c][i].bSplit        = false; 
-      pcSaoParam->psSaoPart[c][i].bProcessed    = false;
-      pcSaoParam->psSaoPart[c][i].dMinCost      = MAX_DOUBLE;
-      pcSaoParam->psSaoPart[c][i].iMinDist      = MAX_INT;
-      pcSaoParam->psSaoPart[c][i].iMinRate      = MAX_INT;
-      pcSaoParam->psSaoPart[c][i].subTypeIdx    = 0;
-      for (Int j=0;j<MAX_NUM_SAO_OFFSETS;j++)
-      {
-        pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
-        pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
-        pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
-      }
-    }
-    pcSaoParam->oneUnitFlag[0]   = 0;
-    pcSaoParam->oneUnitFlag[1]   = 0;
-    pcSaoParam->oneUnitFlag[2]   = 0;
-    resetLcuPart(pcSaoParam->saoLcuParam[0]);
-    resetLcuPart(pcSaoParam->saoLcuParam[1]);
-    resetLcuPart(pcSaoParam->saoLcuParam[2]);
-  }
-}
-
-/** get the sign of input variable
- * \param   x
- */
-inline Int xSign(Int x)
-{
-  return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31)));
-}
-
-/** initialize variables for SAO process
- * \param  pcPic picture data pointer
- */
-Void TComSampleAdaptiveOffset::createPicSaoInfo(TComPic* pcPic)
-{
-  m_pcPic   = pcPic;
-  m_bUseNIF = ( pcPic->getIndependentSliceBoundaryForNDBFilter() || pcPic->getIndependentTileBoundaryForNDBFilter() );
-  if(m_bUseNIF)
-  {
-    m_pcYuvTmp = pcPic->getYuvPicBufferForIndependentBoundaryProcessing();
-  }
-}
-
-Void TComSampleAdaptiveOffset::destroyPicSaoInfo()
-{
-
-}
-
-/** sample adaptive offset process for one LCU
- * \param   iAddr, iSaoType, iYCbCr
- */
-Void TComSampleAdaptiveOffset::processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr)
-{
-  if(!m_bUseNIF)
-  {
-    processSaoCuOrg( iAddr, iSaoType, iYCbCr);
-  }
-  else
-  {  
-    Int  isChroma = (iYCbCr != 0)? 1:0;
-    Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
-    Pel* pPicRest = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr);
-    Pel* pPicDec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
-
-    std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
-
-    //variables
-    UInt  xPos, yPos, width, height;
-    Bool* pbBorderAvail;
-    UInt  posOffset;
-
-    for(Int i=0; i< vFilterBlocks.size(); i++)
-    {
-      xPos        = vFilterBlocks[i].posX   >> isChroma;
-      yPos        = vFilterBlocks[i].posY   >> isChroma;
-      width       = vFilterBlocks[i].width  >> isChroma;
-      height      = vFilterBlocks[i].height >> isChroma;
-      pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
-
-      posOffset = (yPos* stride) + xPos;
-
-      processSaoBlock(pPicDec+ posOffset, pPicRest+ posOffset, stride, iSaoType, width, height, pbBorderAvail, iYCbCr);
-    }
-  }
-}
-
-/** Perform SAO for non-cross-slice or non-cross-tile process
- * \param  pDec to-be-filtered block buffer pointer
- * \param  pRest filtered block buffer pointer
- * \param  stride picture buffer stride
- * \param  saoType SAO offset type
- * \param  xPos x coordinate
- * \param  yPos y coordinate
- * \param  width block width
- * \param  height block height
- * \param  pbBorderAvail availabilities of block border pixels
- */
-Void TComSampleAdaptiveOffset::processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int saoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr)
-{
-  //variables
-  Int startX, startY, endX, endY, x, y;
-  Int signLeft,signRight,signDown,signDown1;
-  UInt edgeType;
-  Pel *pClipTbl = (iYCbCr==0)?m_pClipTable:m_pChromaClipTable;
-  Int *pOffsetBo = (iYCbCr==0)?m_iOffsetBo: m_iChromaOffsetBo;
-
-  switch (saoType)
-  {
-  case SAO_EO_0: // dir: -
-    {
-
-      startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
-      endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
-      for (y=0; y< height; y++)
-      {
-        signLeft = xSign(pDec[startX] - pDec[startX-1]);
-        for (x=startX; x< endX; x++)
-        {
-          signRight =  xSign(pDec[x] - pDec[x+1]); 
-          edgeType =  signRight + signLeft + 2;
-          signLeft  = -signRight;
-
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-        pDec  += stride;
-        pRest += stride;
-      }
-      break;
-    }
-  case SAO_EO_1: // dir: |
-    {
-      startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
-      endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
-      if (!pbBorderAvail[SGU_T])
-      {
-        pDec  += stride;
-        pRest += stride;
-      }
-      for (x=0; x< width; x++)
-      {
-        m_iUpBuff1[x] = xSign(pDec[x] - pDec[x-stride]);
-      }
-      for (y=startY; y<endY; y++)
-      {
-        for (x=0; x< width; x++)
-        {
-          signDown  = xSign(pDec[x] - pDec[x+stride]); 
-          edgeType = signDown + m_iUpBuff1[x] + 2;
-          m_iUpBuff1[x]= -signDown;
-
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-        pDec  += stride;
-        pRest += stride;
-      }
-      break;
-    }
-  case SAO_EO_2: // dir: 135
-    {
-      Int posShift= stride + 1;
-
-      startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
-      endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
-
-      //prepare 2nd line upper sign
-      pDec += stride;
-      for (x=startX; x< endX+1; x++)
-      {
-        m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);
-      }
-
-      //1st line
-      pDec -= stride;
-      if(pbBorderAvail[SGU_TL])
-      {
-        x= 0;
-        edgeType      =  xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2;
-        pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-
-      }
-      if(pbBorderAvail[SGU_T])
-      {
-        for(x= 1; x< endX; x++)
-        {
-          edgeType      =  xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2;
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-      }
-      pDec   += stride;
-      pRest  += stride;
-
-
-      //middle lines
-      for (y= 1; y< height-1; y++)
-      {
-        for (x=startX; x<endX; x++)
-        {
-          signDown1      =  xSign(pDec[x] - pDec[x+ posShift]) ;
-          edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-
-          m_iUpBufft[x+1] = -signDown1; 
-        }
-        m_iUpBufft[startX] = xSign(pDec[stride+startX] - pDec[startX-1]);
-
-        ipSwap     = m_iUpBuff1;
-        m_iUpBuff1 = m_iUpBufft;
-        m_iUpBufft = ipSwap;
-
-        pDec  += stride;
-        pRest += stride;
-      }
-
-      //last line
-      if(pbBorderAvail[SGU_B])
-      {
-        for(x= startX; x< width-1; x++)
-        {
-          edgeType =  xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-      }
-      if(pbBorderAvail[SGU_BR])
-      {
-        x= width -1;
-        edgeType =  xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
-        pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-      }
-      break;
-    } 
-  case SAO_EO_3: // dir: 45
-    {
-      Int  posShift     = stride - 1;
-      startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
-      endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
-
-      //prepare 2nd line upper sign
-      pDec += stride;
-      for (x=startX-1; x< endX; x++)
-      {
-        m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);
-      }
-
-
-      //first line
-      pDec -= stride;
-      if(pbBorderAvail[SGU_T])
-      {
-        for(x= startX; x< width -1; x++)
-        {
-          edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2;
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-      }
-      if(pbBorderAvail[SGU_TR])
-      {
-        x= width-1;
-        edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2;
-        pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-      }
-      pDec  += stride;
-      pRest += stride;
-
-      //middle lines
-      for (y= 1; y< height-1; y++)
-      {
-        for(x= startX; x< endX; x++)
-        {
-          signDown1      =  xSign(pDec[x] - pDec[x+ posShift]) ;
-          edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
-
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-          m_iUpBuff1[x-1] = -signDown1; 
-        }
-        m_iUpBuff1[endX-1] = xSign(pDec[endX-1 + stride] - pDec[endX]);
-
-        pDec  += stride;
-        pRest += stride;
-      }
-
-      //last line
-      if(pbBorderAvail[SGU_BL])
-      {
-        x= 0;
-        edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
-        pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-
-      }
-      if(pbBorderAvail[SGU_B])
-      {
-        for(x= 1; x< endX; x++)
-        {
-          edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
-          pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
-        }
-      }
-      break;
-    }   
-  case SAO_BO:
-    {
-      for (y=0; y< height; y++)
-      {
-        for (x=0; x< width; x++)
-        {
-          pRest[x] = pOffsetBo[pDec[x]];
-        }
-        pRest += stride;
-        pDec  += stride;
-      }
-      break;
-    }
-  default: break;
-  }
-
-}
-
-/** sample adaptive offset process for one LCU crossing LCU boundary
- * \param   iAddr, iSaoType, iYCbCr
- */
-Void TComSampleAdaptiveOffset::processSaoCuOrg(Int iAddr, Int iSaoType, Int iYCbCr)
-{
-  Int x,y;
-  TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
-  Pel* pRec;
-  Int  iStride;
-  Int  iLcuWidth  = m_uiMaxCUWidth;
-  Int  iLcuHeight = m_uiMaxCUHeight;
-  UInt uiLPelX    = pTmpCu->getCUPelX();
-  UInt uiTPelY    = pTmpCu->getCUPelY();
-  UInt uiRPelX;
-  UInt uiBPelY;
-  Int  iSignLeft;
-  Int  iSignRight;
-  Int  iSignDown;
-  Int  iSignDown1;
-  Int  iSignDown2;
-  UInt uiEdgeType;
-  Int iPicWidthTmp;
-  Int iPicHeightTmp;
-  Int iStartX;
-  Int iStartY;
-  Int iEndX;
-  Int iEndY;
-  Int iIsChroma = (iYCbCr!=0)? 1:0;
-  Int iShift;
-  Int iCuHeightTmp;
-  Pel *pTmpLSwap;
-  Pel *pTmpL;
-  Pel *pTmpU;
-  Pel *pClipTbl = NULL;
-  Int *pOffsetBo = NULL;
-
-  iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
-  iPicHeightTmp = m_iPicHeight >> iIsChroma;
-  iLcuWidth     = iLcuWidth    >> iIsChroma;
-  iLcuHeight    = iLcuHeight   >> iIsChroma;
-  uiLPelX       = uiLPelX      >> iIsChroma;
-  uiTPelY       = uiTPelY      >> iIsChroma;
-  uiRPelX       = uiLPelX + iLcuWidth  ;
-  uiBPelY       = uiTPelY + iLcuHeight ;
-  uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
-  uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
-  iLcuWidth     = uiRPelX - uiLPelX;
-  iLcuHeight    = uiBPelY - uiTPelY;
-
-  if(pTmpCu->getPic()==0)
-  {
-    return;
-  }
-  if (iYCbCr == 0)
-  {
-    pRec       = m_pcPic->getPicYuvRec()->getLumaAddr(iAddr);
-    iStride    = m_pcPic->getStride();
-  } 
-  else if (iYCbCr == 1)
-  {
-    pRec       = m_pcPic->getPicYuvRec()->getCbAddr(iAddr);
-    iStride    = m_pcPic->getCStride();
-  }
-  else 
-  {
-    pRec       = m_pcPic->getPicYuvRec()->getCrAddr(iAddr);
-    iStride    = m_pcPic->getCStride();
-  }
-
-//   if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1)
-  {
-    iCuHeightTmp = (m_uiMaxCUHeight >> iIsChroma);
-    iShift = (m_uiMaxCUWidth>> iIsChroma)-1;
-    for (Int i=0;i<iCuHeightTmp+1;i++)
-    {
-      m_pTmpL2[i] = pRec[iShift];
-      pRec += iStride;
-    }
-    pRec -= (iStride*(iCuHeightTmp+1));
-
-    pTmpL = m_pTmpL1; 
-    pTmpU = &(m_pTmpU1[uiLPelX]); 
-  }
-
-  pClipTbl = (iYCbCr==0)? m_pClipTable:m_pChromaClipTable;
-  pOffsetBo = (iYCbCr==0)? m_iOffsetBo:m_iChromaOffsetBo;
-
-  switch (iSaoType)
-  {
-  case SAO_EO_0: // dir: -
-    {
-      iStartX = (uiLPelX == 0) ? 1 : 0;
-      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
-      for (y=0; y<iLcuHeight; y++)
-      {
-        iSignLeft = xSign(pRec[iStartX] - pTmpL[y]);
-        for (x=iStartX; x< iEndX; x++)
-        {
-          iSignRight =  xSign(pRec[x] - pRec[x+1]); 
-          uiEdgeType =  iSignRight + iSignLeft + 2;
-          iSignLeft  = -iSignRight;
-
-          pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
-        }
-        pRec += iStride;
-      }
-      break;
-    }
-  case SAO_EO_1: // dir: |
-    {
-      iStartY = (uiTPelY == 0) ? 1 : 0;
-      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
-      if (uiTPelY == 0)
-      {
-        pRec += iStride;
-      }
-      for (x=0; x< iLcuWidth; x++)
-      {
-        m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x]);
-      }
-      for (y=iStartY; y<iEndY; y++)
-      {
-        for (x=0; x<iLcuWidth; x++)
-        {
-          iSignDown  = xSign(pRec[x] - pRec[x+iStride]); 
-          uiEdgeType = iSignDown + m_iUpBuff1[x] + 2;
-          m_iUpBuff1[x]= -iSignDown;
-
-          pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
-        }
-        pRec += iStride;
-      }
-      break;
-    }
-  case SAO_EO_2: // dir: 135
-    {
-      iStartX = (uiLPelX == 0)            ? 1 : 0;
-      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
-
-      iStartY = (uiTPelY == 0) ?             1 : 0;
-      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
-
-      if (uiTPelY == 0)
-      {
-        pRec += iStride;
-      }
-
-      for (x=iStartX; x<iEndX; x++)
-      {
-        m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x-1]);
-      }
-      for (y=iStartY; y<iEndY; y++)
-      {
-        iSignDown2 = xSign(pRec[iStride+iStartX] - pTmpL[y]);
-        for (x=iStartX; x<iEndX; x++)
-        {
-          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
-          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
-          m_iUpBufft[x+1] = -iSignDown1; 
-          pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
-        }
-        m_iUpBufft[iStartX] = iSignDown2;
-
-        ipSwap     = m_iUpBuff1;
-        m_iUpBuff1 = m_iUpBufft;
-        m_iUpBufft = ipSwap;
-
-        pRec += iStride;
-      }
-      break;
-    } 
-  case SAO_EO_3: // dir: 45
-    {
-      iStartX = (uiLPelX == 0) ? 1 : 0;
-      iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
-
-      iStartY = (uiTPelY == 0) ? 1 : 0;
-      iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
-
-      if (iStartY == 1)
-      {
-        pRec += iStride;
-      }
-
-      for (x=iStartX-1; x<iEndX; x++)
-      {
-        m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x+1]);
-      }
-      for (y=iStartY; y<iEndY; y++)
-      {
-        x=iStartX;
-        iSignDown1      =  xSign(pRec[x] - pTmpL[y+1]) ;
-        uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
-        m_iUpBuff1[x-1] = -iSignDown1; 
-        pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
-        for (x=iStartX+1; x<iEndX; x++)
-        {
-          iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
-          uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
-          m_iUpBuff1[x-1] = -iSignDown1; 
-          pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
-        }
-        m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
-
-        pRec += iStride;
-      } 
-      break;
-    }   
-  case SAO_BO:
-    {
-      for (y=0; y<iLcuHeight; y++)
-      {
-        for (x=0; x<iLcuWidth; x++)
-        {
-          pRec[x] = pOffsetBo[pRec[x]];
-        }
-        pRec += iStride;
-      }
-      break;
-    }
-  default: break;
-  }
-//   if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1)
-  {
-    pTmpLSwap = m_pTmpL1;
-    m_pTmpL1  = m_pTmpL2;
-    m_pTmpL2  = pTmpLSwap;
-  }
-}
-/** Sample adaptive offset process
- * \param pcPic, pcSaoParam  
- */
-Void TComSampleAdaptiveOffset::SAOProcess(SAOParam* pcSaoParam)
-{
-  {
-    m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0);
-    m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0);
-
-    if(m_bUseNIF)
-    {
-      m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
-    }
-    if (m_saoLcuBasedOptimization)
-    {
-      pcSaoParam->oneUnitFlag[0] = 0;  
-      pcSaoParam->oneUnitFlag[1] = 0;  
-      pcSaoParam->oneUnitFlag[2] = 0;  
-    }
-    Int iY  = 0;
-    {
-      processSaoUnitAll( pcSaoParam->saoLcuParam[iY], pcSaoParam->oneUnitFlag[iY], iY);
-    }
-    {
-       processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);//Cb
-       processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);//Cr
-    }
-    m_pcPic = NULL;
-  }
-}
-
-Pel* TComSampleAdaptiveOffset::getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr, Int iAddr)
-{
-  switch (iYCbCr)
-  {
-  case 0:
-    return pcPicYuv->getLumaAddr(iAddr);
-    break;
-  case 1:
-    return pcPicYuv->getCbAddr(iAddr);
-    break;
-  case 2:
-    return pcPicYuv->getCrAddr(iAddr);
-    break;
-  default:
-    return NULL;
-    break;
-  }
-}
-/** Process SAO all units 
- * \param saoLcuParam SAO LCU parameters
- * \param oneUnitFlag one unit flag
- * \param yCbCr color componet index
- */
-Void TComSampleAdaptiveOffset::processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr)
-{
-  Pel *pRec;
-  Int picWidthTmp;
-
-  if (yCbCr == 0)
-  {
-    pRec        = m_pcPic->getPicYuvRec()->getLumaAddr();
-    picWidthTmp = m_iPicWidth;
-  } 
-  else if (yCbCr == 1)
-  {
-    pRec        = m_pcPic->getPicYuvRec()->getCbAddr();
-    picWidthTmp = m_iPicWidth>>1;
-  }
-  else 
-  {
-    pRec        = m_pcPic->getPicYuvRec()->getCrAddr();
-    picWidthTmp = m_iPicWidth>>1;
-  }
-
-  memcpy(m_pTmpU1, pRec, sizeof(Pel)*picWidthTmp);
-
-  Int  i;
-  UInt edgeType;
-  Pel* ppLumaTable = NULL;
-  Pel* pClipTable = NULL;
-  Int* pOffsetBo = NULL;
-  Int  typeIdx;
-
-  Int offset[LUMA_GROUP_NUM+1];
-  Int idxX;
-  Int idxY;
-  Int addr;
-  Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
-  Int frameHeightInCU = m_pcPic->getFrameHeightInCU();
-  Int stride;
-  Pel *tmpUSwap;
-  Int isChroma = (yCbCr == 0) ? 0:1;
-  Bool mergeLeftFlag;
-  Int saoBitIncrease = (yCbCr == 0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC;
-
-  pOffsetBo = (yCbCr==0) ? m_iOffsetBo : m_iChromaOffsetBo;
-
-  offset[0] = 0;
-  for (idxY = 0; idxY< frameHeightInCU; idxY++)
-  { 
-    addr = idxY * frameWidthInCU;
-    if (yCbCr == 0)
-    {
-      pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(addr);
-      stride = m_pcPic->getStride();
-      picWidthTmp = m_iPicWidth;
-    }
-    else if (yCbCr == 1)
-    {
-      pRec  = m_pcPic->getPicYuvRec()->getCbAddr(addr);
-      stride = m_pcPic->getCStride();
-      picWidthTmp = m_iPicWidth>>1;
-    }
-    else
-    {
-      pRec  = m_pcPic->getPicYuvRec()->getCrAddr(addr);
-      stride = m_pcPic->getCStride();
-      picWidthTmp = m_iPicWidth>>1;
-    }
-
-    //     pRec += iStride*(m_uiMaxCUHeight-1);
-    for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++)
-    {
-      m_pTmpL1[i] = pRec[0];
-      pRec+=stride;
-    }
-    pRec-=(stride<<1);
-
-    memcpy(m_pTmpU2, pRec, sizeof(Pel)*picWidthTmp);
-
-    for (idxX = 0; idxX < frameWidthInCU; idxX++)
-    {
-      addr = idxY * frameWidthInCU + idxX;
-
-      if (oneUnitFlag)
-      {
-        typeIdx = saoLcuParam[0].typeIdx;
-        mergeLeftFlag = (addr == 0)? 0:1;
-      }
-      else
-      {
-        typeIdx = saoLcuParam[addr].typeIdx;
-        mergeLeftFlag = saoLcuParam[addr].mergeLeftFlag;
-      }
-      if (typeIdx>=0)
-      {
-        if (!mergeLeftFlag)
-        {
-
-          if (typeIdx == SAO_BO)
-          {
-            for (i=0; i<SAO_MAX_BO_CLASSES+1;i++)
-            {
-              offset[i] = 0;
-            }
-            for (i=0; i<saoLcuParam[addr].length; i++)
-            {
-              offset[ (saoLcuParam[addr].subTypeIdx +i)%SAO_MAX_BO_CLASSES  +1] = saoLcuParam[addr].offset[i] << saoBitIncrease;
-            }
-
-            ppLumaTable = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo;
-            pClipTable = (yCbCr==0)?m_pClipTable:m_pChromaClipTable;
-
-            Int bitDepth = (yCbCr==0) ? g_bitDepthY : g_bitDepthC;
-            for (i=0;i<(1<<bitDepth);i++)
-            {
-              pOffsetBo[i] = pClipTable[i + offset[ppLumaTable[i]]];
-            }
-
-          }
-          if (typeIdx == SAO_EO_0 || typeIdx == SAO_EO_1 || typeIdx == SAO_EO_2 || typeIdx == SAO_EO_3)
-          {
-            for (i=0;i<saoLcuParam[addr].length;i++)
-            {
-              offset[i+1] = saoLcuParam[addr].offset[i] << saoBitIncrease;
-            }
-            for (edgeType=0;edgeType<6;edgeType++)
-            {
-              m_iOffsetEo[edgeType]= offset[m_auiEoTable[edgeType]];
-            }
-          }
-        }
-        processSaoCu(addr, typeIdx, yCbCr);
-      }
-      else
-      {
-        if (idxX != (frameWidthInCU-1))
-        {
-          if (yCbCr == 0)
-          {
-            pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(addr);
-            stride = m_pcPic->getStride();
-          }
-          else if (yCbCr == 1)
-          {
-            pRec  = m_pcPic->getPicYuvRec()->getCbAddr(addr);
-            stride = m_pcPic->getCStride();
-          }
-          else
-          {
-            pRec  = m_pcPic->getPicYuvRec()->getCrAddr(addr);
-            stride = m_pcPic->getCStride();
-          }
-          Int widthShift = m_uiMaxCUWidth>>isChroma;
-          for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++)
-          {
-            m_pTmpL1[i] = pRec[widthShift-1];
-            pRec+=stride;
-          }
-        }
-      }
-    }
-    tmpUSwap = m_pTmpU1;
-    m_pTmpU1 = m_pTmpU2;
-    m_pTmpU2 = tmpUSwap;
-  }
-
-}
-/** Reset SAO LCU part 
- * \param saoLcuParam
- */
-Void TComSampleAdaptiveOffset::resetLcuPart(SaoLcuParam* saoLcuParam)
-{
-  Int i,j;
-  for (i=0;i<m_iNumCuInWidth*m_iNumCuInHeight;i++)
-  {
-    saoLcuParam[i].mergeUpFlag     =  1;
-    saoLcuParam[i].mergeLeftFlag =  0;
-    saoLcuParam[i].partIdx   =  0;
-    saoLcuParam[i].typeIdx      = -1;
-    for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
-    {
-      saoLcuParam[i].offset[j] = 0;
-    }
-    saoLcuParam[i].subTypeIdx = 0;
-  }
-}
-
-/** convert QP part to SAO unit 
-* \param saoParam SAO parameter 
-* \param partIdx SAO part index
-* \param yCbCr color component index
- */
-Void TComSampleAdaptiveOffset::convertQT2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr)
-{
-
-  SAOQTPart*  saoPart= &(saoParam->psSaoPart[yCbCr][partIdx]);
-  if (!saoPart->bSplit)
-  {
-    convertOnePart2SaoUnit(saoParam, partIdx, yCbCr);
-    return;
-  }
-
-  if (saoPart->PartLevel < m_uiMaxSplitLevel)
-  {
-    convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[0], yCbCr);
-    convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[1], yCbCr);
-    convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[2], yCbCr);
-    convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[3], yCbCr);
-  }
-}
-/** convert one SAO part to SAO unit 
-* \param saoParam SAO parameter 
-* \param partIdx SAO part index
-* \param yCbCr color component index
- */
-Void TComSampleAdaptiveOffset::convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr)
-{
-  Int j;
-  Int idxX;
-  Int idxY;
-  Int addr;
-  Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
-  SAOQTPart* saoQTPart = saoParam->psSaoPart[yCbCr];
-  SaoLcuParam* saoLcuParam = saoParam->saoLcuParam[yCbCr];
-
-  for (idxY = saoQTPart[partIdx].StartCUY; idxY<= saoQTPart[partIdx].EndCUY; idxY++)
-  {
-    for (idxX = saoQTPart[partIdx].StartCUX; idxX<= saoQTPart[partIdx].EndCUX; idxX++)
-    {
-      addr = idxY * frameWidthInCU + idxX;
-      saoLcuParam[addr].partIdxTmp = (Int)partIdx; 
-      saoLcuParam[addr].typeIdx    = saoQTPart[partIdx].iBestType;
-      saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx;
-      if (saoLcuParam[addr].typeIdx!=-1)
-      {
-        saoLcuParam[addr].length    = saoQTPart[partIdx].iLength;
-        for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
-        {
-          saoLcuParam[addr].offset[j] = saoQTPart[partIdx].iOffset[j];
-        }
-      }
-      else
-      {
-        saoLcuParam[addr].length    = 0;
-        saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx;
-        for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
-        {
-          saoLcuParam[addr].offset[j] = 0;
-        }
-      }
-    }
-  }
-}
-
-Void TComSampleAdaptiveOffset::resetSaoUnit(SaoLcuParam* saoUnit)
-{
-  saoUnit->partIdx       = 0;
-  saoUnit->partIdxTmp    = 0;
-  saoUnit->mergeLeftFlag = 0;
-  saoUnit->mergeUpFlag   = 0;
-  saoUnit->typeIdx       = -1;
-  saoUnit->length        = 0;
-  saoUnit->subTypeIdx    = 0;
-
-  for (Int i=0;i<4;i++)
-  {
-    saoUnit->offset[i] = 0;
-  }
-}
-
-Void TComSampleAdaptiveOffset::copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc )
-{
-  saoUnitDst->mergeLeftFlag = saoUnitSrc->mergeLeftFlag;
-  saoUnitDst->mergeUpFlag   = saoUnitSrc->mergeUpFlag;
-  saoUnitDst->typeIdx       = saoUnitSrc->typeIdx;
-  saoUnitDst->length        = saoUnitSrc->length;
-
-  saoUnitDst->subTypeIdx  = saoUnitSrc->subTypeIdx;
-  for (Int i=0;i<4;i++)
-  {
-    saoUnitDst->offset[i] = saoUnitSrc->offset[i];
-  }
-}
-#endif
+
 /** PCM LF disable process. 
  * \param pcPic picture (TComPic) pointer
Index: trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h	(revision 595)
@@ -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.
  *
@@ -45,6 +45,4 @@
 //! \{
 
-
-#if HM_CLEANUP_SAO
 // ====================================================================================================================
 // Constants
@@ -105,107 +103,4 @@
 
 };
-#else
-
-// ====================================================================================================================
-// Constants
-// ====================================================================================================================
-
-#define SAO_MAX_DEPTH                 4
-#define SAO_BO_BITS                   5
-#define LUMA_GROUP_NUM                (1<<SAO_BO_BITS)
-#define MAX_NUM_SAO_OFFSETS           4
-#define MAX_NUM_SAO_CLASS             33
-// ====================================================================================================================
-// Class definition
-// ====================================================================================================================
-
-/// Sample Adaptive Offset class
-class TComSampleAdaptiveOffset
-{
-protected:
-  TComPic*          m_pcPic;
-
-  static const UInt m_uiMaxDepth;
-  static const Int m_aiNumCulPartsLevel[5];
-  static const UInt m_auiEoTable[9];
-  Int *m_iOffsetBo;
-  Int *m_iChromaOffsetBo;
-  Int m_iOffsetEo[LUMA_GROUP_NUM];
-
-  Int  m_iPicWidth;
-  Int  m_iPicHeight;
-  UInt m_uiMaxSplitLevel;
-  UInt m_uiMaxCUWidth;
-  UInt m_uiMaxCUHeight;
-  Int  m_iNumCuInWidth;
-  Int  m_iNumCuInHeight;
-  Int  m_iNumTotalParts;
-  static const Int m_iNumClass[MAX_NUM_SAO_TYPE];
-
-  UInt m_uiSaoBitIncreaseY;
-  UInt m_uiSaoBitIncreaseC;  //for chroma
-  UInt m_uiQP;
-
-  Pel   *m_pClipTable;
-  Pel   *m_pClipTableBase;
-  Pel   *m_lumaTableBo;
-  Pel   *m_pChromaClipTable;
-  Pel   *m_pChromaClipTableBase;
-  Pel   *m_chromaTableBo;
-  Int   *m_iUpBuff1;
-  Int   *m_iUpBuff2;
-  Int   *m_iUpBufft;
-  Int   *ipSwap;
-  Bool  m_bUseNIF;       //!< true for performing non-cross slice boundary ALF
-  TComPicYuv* m_pcYuvTmp;    //!< temporary picture buffer pointer when non-across slice/tile boundary SAO is enabled
-
-  Pel* m_pTmpU1;
-  Pel* m_pTmpU2;
-  Pel* m_pTmpL1;
-  Pel* m_pTmpL2;
-  Int     m_maxNumOffsetsPerPic;
-  Bool    m_saoLcuBoundary;
-  Bool    m_saoLcuBasedOptimization;
-
-  Void xPCMRestoration        (TComPic* pcPic);
-  Void xPCMCURestoration      (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth);
-  Void xPCMSampleRestoration  (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
-public:
-  TComSampleAdaptiveOffset         ();
-  virtual ~TComSampleAdaptiveOffset();
-
-  Void create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight );
-  Void destroy ();
-
-  Int  convertLevelRowCol2Idx(Int level, Int row, Int col);
-
-  Void initSAOParam   (SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr);
-  Void allocSaoParam  (SAOParam* pcSaoParam);
-  Void resetSAOParam  (SAOParam *pcSaoParam);
-  static Void freeSaoParam   (SAOParam *pcSaoParam);
-  
-  Void SAOProcess(SAOParam* pcSaoParam);
-  Void processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr);
-  Pel* getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr,Int iAddr = 0);
-
-  Void processSaoCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);  //!< LCU-basd SAO process without slice granularity 
-  Void createPicSaoInfo(TComPic* pcPic);
-  Void destroyPicSaoInfo();
-  Void processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int iSaoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);
-
-  Void resetLcuPart(SaoLcuParam* saoLcuParam);
-  Void convertQT2SaoUnit(SAOParam* saoParam, UInt partIdx, Int yCbCr);
-  Void convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr);
-  Void processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr);
-  Void setSaoLcuBoundary (Bool bVal)  {m_saoLcuBoundary = bVal;}
-  Bool getSaoLcuBoundary ()           {return m_saoLcuBoundary;}
-  Void setSaoLcuBasedOptimization (Bool bVal)  {m_saoLcuBasedOptimization = bVal;}
-  Bool getSaoLcuBasedOptimization ()           {return m_saoLcuBasedOptimization;}
-  Void resetSaoUnit(SaoLcuParam* saoUnit);
-  Void copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc );
-  Void PCMLFDisableProcess    ( TComPic* pcPic);                        ///< interface function for ALF process 
-};
-
-#endif
 
 //! \}
Index: trunk/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComSlice.cpp	(revision 595)
@@ -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.
  *
@@ -143,7 +143,5 @@
   initWpAcDcParam();
   m_saoEnabledFlag = false;
-#if HM_CLEANUP_SAO
   m_saoEnabledFlagChroma = false;
-#endif
 }
 
@@ -987,5 +985,7 @@
 {
   TComPic*                 rpcPic;
+#if !FIX1172
   setAssociatedIRAPPOC(pocCRA);
+#endif
   Int pocCurr = getPOC(); 
 
@@ -1277,4 +1277,10 @@
   {
     rpcPic = *(iterPic++);
+#if BUGFIX_INTRAPERIOD
+    if(!rpcPic->getReconMark())
+    {
+      continue;
+    }
+#endif
     if (rpcPic->getPOC() == this->getPOC())
     {
@@ -1373,4 +1379,6 @@
   }
 }
+
+
 
 /** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
@@ -2176,21 +2184,21 @@
 {
   // For layer 0
-  setNumLayersInIdList(0, 1);
-  setLayerSetLayerIdList(0, 0, 0);
-
+  m_numLayerInIdList[0] = 1;
+  m_layerSetLayerIdList[0][0] = 0;
+  
   // For other layers
   Int i, m, n;
-  for( i = 1; i <= getNumLayerSets() - 1; i++ )
+  for( i = 1; i <= m_numLayerSets - 1; i++ )
   {
     n = 0;
-    for( m = 0; m <= this->getMaxLayerId(); m++)
-    {
-      if(this->getLayerIdIncludedFlag(i, m))
-      {
-        setLayerSetLayerIdList(i, n, m);
+    for( m = 0; m <= m_maxLayerId; m++)
+    {
+      if( m_layerIdIncludedFlag[i][m] )
+      {
+        m_layerSetLayerIdList[i][n] = m;
         n++;
       }
     }
-    setNumLayersInIdList(i, n);
+    m_numLayerInIdList[i] = n;
   }
 }
@@ -2505,5 +2513,4 @@
 , m_qpBDOffsetY               (  0)
 , m_qpBDOffsetC               (  0)
-, m_useLossless               (false)
 , m_uiPCMBitDepthLuma         (  8)
 , m_uiPCMBitDepthChroma       (  8)
Index: trunk/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComSlice.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComSlice.h	(revision 595)
@@ -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.
  *
@@ -714,5 +714,5 @@
   UInt    getNumReorderPics(UInt tLayer)                        { return m_numReorderPics[tLayer]; }
   
-  Void    setMaxDecPicBuffering(UInt v, UInt tLayer)            { m_uiMaxDecPicBuffering[tLayer] = v;    }
+  Void    setMaxDecPicBuffering(UInt v, UInt tLayer)            { assert(tLayer < MAX_TLAYER); m_uiMaxDecPicBuffering[tLayer] = v;    }
   UInt    getMaxDecPicBuffering(UInt tLayer)                    { return m_uiMaxDecPicBuffering[tLayer]; }
   
@@ -1320,6 +1320,4 @@
   Int         m_qpBDOffsetC;
 
-  Bool        m_useLossless;
-
   UInt        m_uiPCMBitDepthLuma;
   UInt        m_uiPCMBitDepthChroma;
@@ -1340,7 +1338,5 @@
   Bool        m_scalingListEnabledFlag;
   Bool        m_scalingListPresentFlag;
-
   TComScalingList*     m_scalingList;   //!< ScalingList class pointer
-
   UInt        m_uiMaxDecPicBuffering[MAX_TLAYER]; 
   UInt        m_uiMaxLatencyIncrease[MAX_TLAYER];  // Really max latency increase plus 1 (value 0 expresses no limit)
@@ -1456,8 +1452,4 @@
   UInt getMaxTrSize   ()         { return  m_uiMaxTrSize;   }
   
-  // Tool list
-  Bool getUseLossless ()         { return m_useLossless; }
-  Void setUseLossless ( Bool b ) { m_useLossless  = b; }
-  
   // AMP accuracy
   Int       getAMPAcc   ( UInt uiDepth ) { return m_iAMPAcc[uiDepth]; }
@@ -1499,7 +1491,6 @@
 #endif
   TComScalingList* getScalingList ()       { return m_scalingList; }               //!< get ScalingList class pointer in SPS
-
   UInt getMaxDecPicBuffering  (UInt tlayer)            { return m_uiMaxDecPicBuffering[tlayer]; }
-  Void setMaxDecPicBuffering  ( UInt ui, UInt tlayer ) { m_uiMaxDecPicBuffering[tlayer] = ui;   }
+  Void setMaxDecPicBuffering  ( UInt ui, UInt tlayer ) { assert(tlayer < MAX_TLAYER);  m_uiMaxDecPicBuffering[tlayer] = ui;   }
   UInt getMaxLatencyIncrease  (UInt tlayer)            { return m_uiMaxLatencyIncrease[tlayer];   }
   Void setMaxLatencyIncrease  ( UInt ui , UInt tlayer) { m_uiMaxLatencyIncrease[tlayer] = ui;      }
Index: trunk/source/Lib/TLibCommon/TComTrQuant.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComTrQuant.cpp	(revision 595)
@@ -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.
  *
@@ -1082,5 +1082,5 @@
     UInt uiLog2TrSize = g_aucConvertToBit[ iWidth ] + 2;
     Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType];
-    assert(scalingListType < 6);
+    assert(scalingListType < SCALING_LIST_NUM);
     Int *piQuantCoeff = 0;
     piQuantCoeff = getQuantCoeff(scalingListType,m_cQP.m_iRem,uiLog2TrSize-2);
@@ -1321,5 +1321,5 @@
     Pel* pResi = rpcResidual + uiAddr;
     Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTxt];
-    assert(scalingListType < 6);
+    assert(scalingListType < SCALING_LIST_NUM);
     invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
   }
@@ -1522,5 +1522,5 @@
   const UInt uiMaxNumCoeff       = uiWidth * uiHeight;
   Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType];
-  assert(scalingListType < 6);
+  assert(scalingListType < SCALING_LIST_NUM);
   
   Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                   // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
Index: trunk/source/Lib/TLibCommon/TComTrQuant.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComTrQuant.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComTrQuant.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComWeightPrediction.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComWeightPrediction.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComYuv.cpp	(revision 595)
@@ -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.
  *
@@ -604,7 +604,7 @@
     {
 #if DISABLING_CLIP_FOR_BIPREDME
-      pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ;
+      pDst[x ] = 2 * pDst[x] - pSrc[x];
 #else
-      pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] );
+      pDst[x ] = ClipY(2 * pDst[x] - pSrc[x]);
 #endif
     }
@@ -624,9 +624,9 @@
     {
 #if DISABLING_CLIP_FOR_BIPREDME
-      pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ;
-      pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ;
+      pDstU[x ] = 2 * pDstU[x] - pSrcU[x];
+      pDstV[x ] = 2 * pDstV[x] - pSrcV[x];
 #else
-      pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] );
-      pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] );
+      pDstU[x ] = ClipC(2 * pDstU[x] - pSrcU[x]);
+      pDstV[x ] = ClipC(2 * pDstV[x] - pSrcV[x]);
 #endif
     }
Index: trunk/source/Lib/TLibCommon/TComYuv.h
===================================================================
--- trunk/source/Lib/TLibCommon/TComYuv.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TComYuv.h	(revision 595)
@@ -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.
  *
Index: trunk/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- trunk/source/Lib/TLibCommon/TypeDef.h	(revision 588)
+++ trunk/source/Lib/TLibCommon/TypeDef.h	(revision 595)
@@ -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.
  *
@@ -59,4 +59,7 @@
 #define RESOLUTION_BASED_DPB             1      ///< JCTVC-P0192: Assign layers to sub-DPBs based on the rep_format() signaled in the VPS
 #define SUB_BITSTREAM_PROPERTY_SEI       1      ///< JCTVC-P0204: Sub-bitstream property SEI message
+#if SUB_BITSTREAM_PROPERTY_SEI
+#define MAX_SUB_STREAMS                  1024
+#endif
 #define O0109_O0199_FLAGS_TO_VUI         1      ///< JCTVC-O0109, O0199: move single_layer_for_non_irap_flag and higher_layer_flag to vps_vui
 #define O0109_VIEW_ID_LEN                1      ///< JCTVC-O0109: view_id_len_minus1 to view_id_len, and add constraint (1<<view_id_len) is greater than or equal to NumViews
@@ -112,4 +115,7 @@
 #if VPS_EXTNS
 #define VPS_EXTN_MASK_AND_DIM_INFO       1      ///< Include avc_base_layer_flag, splitting_flag, scalability mask and dimension related info
+#if VPS_EXTN_MASK_AND_DIM_INFO
+#define MAX_VPS_NUM_SCALABILITY_TYPES    16
+#endif
 #define VPS_EXTN_OP_LAYER_SETS           1      ///< Include output layer sets in VPS extension
 #define VPS_EXTN_PROFILE_INFO            1      ///< Include profile information for layer sets in VPS extension
@@ -222,4 +228,13 @@
 #define O0149_CROSS_LAYER_BLA_FLAG       1      ///< JCTVC-O0149: signal cross_layer_bla_flag in slice header
 
+#if VIEW_ID_RELATED_SIGNALING
+/// scalability types
+enum ScalabilityType
+{
+  VIEW_ORDER_INDEX  = 1,
+  SCALABILITY_ID = 2,
+};
+#endif
+
 #else
 #define SYNTAX_OUTPUT                    0
@@ -229,9 +244,8 @@
 //! \ingroup TLibCommon
 //! \{
-
-#define HM_CLEANUP_SAO                  1  ///< JCTVC-N0230, 1) three SAO encoder-only software bugfixes. 2) new SAO implementation without picture quadtree, fine-grained slice legacies, and other redundancies.
-#if HM_CLEANUP_SAO  
+#define BUGFIX_INTRAPERIOD 1
 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
-#endif
+
+#define FIX1172 1 ///< fix ticket #1172
 
 #define MAX_NUM_PICS_IN_SOP           1024
@@ -240,9 +254,6 @@
 #define MAX_NESTING_NUM_LAYER       64
 
-#if VPS_EXTN_MASK_AND_DIM_INFO
-#define MAX_VPS_NUM_SCALABILITY_TYPES             16
-#endif
+#if VPS_RENAME
 #define MAX_VPS_OP_LAYER_SETS_PLUS1               3
-#if VPS_RENAME
 #define MAX_VPS_LAYER_SETS_PLUS1                  1024
 #define MAX_VPS_LAYER_ID_PLUS1                    MAX_LAYERS
@@ -253,8 +264,4 @@
 #endif
 
-#if SUB_BITSTREAM_PROPERTY_SEI
-#define MAX_SUB_STREAMS                           1024
-#endif
-
 #define MAX_CPB_CNT                     32  ///< Upper bound of (cpb_cnt_minus1 + 1)
 #if O0137_MAX_LAYERID
@@ -277,7 +284,4 @@
 #define C1FLAG_NUMBER               8 // maximum number of largerThan1 flag coded in one chunk :  16 in HM5
 #define C2FLAG_NUMBER               1 // maximum number of largerThan2 flag coded in one chunk:  16 in HM5 
-#if !HM_CLEANUP_SAO
-#define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1  ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode
-#endif
 #define SAO_ENCODING_CHOICE              1  ///< I0184: picture early termination
 #if SAO_ENCODING_CHOICE
@@ -383,5 +387,9 @@
 typedef       bool                Bool;
 
+#ifdef __arm__
+typedef       signed char         Char;
+#else
 typedef       char                Char;
+#endif
 typedef       unsigned char       UChar;
 typedef       short               Short;
@@ -432,5 +440,4 @@
 };
 
-#if HM_CLEANUP_SAO
 enum SAOComponentIdx
 {
@@ -523,78 +530,4 @@
 };
 
-
-#else
-#define NUM_DOWN_PART 4
-
-enum SAOTypeLen
-{
-  SAO_EO_LEN    = 4, 
-  SAO_BO_LEN    = 4,
-  SAO_MAX_BO_CLASSES = 32
-};
-
-enum SAOType
-{
-  SAO_EO_0 = 0, 
-  SAO_EO_1,
-  SAO_EO_2, 
-  SAO_EO_3,
-  SAO_BO,
-  MAX_NUM_SAO_TYPE
-};
-
-typedef struct _SaoQTPart
-{
-  Int         iBestType;
-  Int         iLength;
-  Int         subTypeIdx ;                 ///< indicates EO class or BO band position
-  Int         iOffset[4];
-  Int         StartCUX;
-  Int         StartCUY;
-  Int         EndCUX;
-  Int         EndCUY;
-
-  Int         PartIdx;
-  Int         PartLevel;
-  Int         PartCol;
-  Int         PartRow;
-
-  Int         DownPartsIdx[NUM_DOWN_PART];
-  Int         UpPartIdx;
-
-  Bool        bSplit;
-
-  //---- encoder only start -----//
-  Bool        bProcessed;
-  Double      dMinCost;
-  Int64       iMinDist;
-  Int         iMinRate;
-  //---- encoder only end -----//
-} SAOQTPart;
-
-typedef struct _SaoLcuParam
-{
-  Bool       mergeUpFlag;
-  Bool       mergeLeftFlag;
-  Int        typeIdx;
-  Int        subTypeIdx;                  ///< indicates EO class or BO band position
-  Int        offset[4];
-  Int        partIdx;
-  Int        partIdxTmp;
-  Int        length;
-} SaoLcuParam;
-
-struct SAOParam
-{
-  Bool       bSaoFlag[2];
-  SAOQTPart* psSaoPart[3];
-  Int        iMaxSplitLevel;
-  Bool         oneUnitFlag[3];
-  SaoLcuParam* saoLcuParam[3];
-  Int          numCuInHeight;
-  Int          numCuInWidth;
-  ~SAOParam();
-};
-#endif
 /// parameters for deblocking filter
 typedef struct _LFCUParam
@@ -788,12 +721,4 @@
   };
 }
-#if VIEW_ID_RELATED_SIGNALING
-/// scalability types
-  enum ScalabilityType
-  {
-    VIEW_ORDER_INDEX  = 1,
-    SCALABILITY_ID = 2,
-  };
-#endif
 //! \}
 
