Index: branches/HTM-14.1-update-dev1/doc/Doxyfile
===================================================================
--- branches/HTM-14.1-update-dev1/doc/Doxyfile	(revision 1286)
+++ branches/HTM-14.1-update-dev1/doc/Doxyfile	(revision 1287)
@@ -39,5 +39,5 @@
 # control system is used.
 
-PROJECT_NUMBER         = HM-16.4
+PROJECT_NUMBER         = HM-16.6
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
Index: branches/HTM-14.1-update-dev1/doc/software-manual.tex
===================================================================
--- branches/HTM-14.1-update-dev1/doc/software-manual.tex	(revision 1286)
+++ branches/HTM-14.1-update-dev1/doc/software-manual.tex	(revision 1287)
@@ -187,5 +187,5 @@
 \begin{abstract}
 This document is a user manual describing usage of reference software
-for the HEVC project. It applies to version 16.4
+for the HEVC project. It applies to version 16.6
 of the software.
 \end{abstract}
@@ -677,4 +677,22 @@
 \\
 
+\Option{SummaryOutFilename} &
+%\ShortOption{\None} &
+\Default{false} &
+Filename to use for producing summary output file. If empty, do not produce a file.
+\\
+
+\Option{SummaryPicFilenameBase} &
+%\ShortOption{\None} &
+\Default{false} &
+Base filename to use for producing summary picture output files. The actual filenames used will have I.txt, P.txt and B.txt appended. If empty, do not produce a file.
+\\
+
+\Option{SummaryVerboseness} &
+%\ShortOption{\None} &
+\Default{false} &
+Specifies the level of the verboseness of the text output.
+\\
+
 \Option{CabacZeroWordPaddingEnabled} &
 %\ShortOption{\None} &
@@ -751,4 +769,28 @@
 \\
 
+\Option{ClipInputVideoToRec709Range} &
+%\ShortOption{\None} &
+\Default{0} &
+If 1 then clip input video to the Rec. 709 Range on loading when InternalBitDepth is less than MSBExtendedBitDepth.
+\\
+
+\Option{ClipOutputVideoToRec709Range} &
+%\ShortOption{\None} &
+\Default{0} &
+If 1 then clip output video to the Rec. 709 Range on saving when OutputBitDepth is less than InternalBitDepth.
+\\
+
+\Option{EfficientFieldIRAPEnabled} &
+%\ShortOption{\None} &
+\Default{1} &
+Enable to code fields in a specific, potentially more efficient, order.
+\\
+
+\Option{HarmonizeGopFirstFieldCoupleEnabled} &
+%\ShortOption{\None} &
+\Default{1} &
+Enables harmonization of Gop first field couple.
+\\
+
 \end{OptionTableNoShorthand}
 
@@ -810,4 +852,10 @@
 \Default{false} &
 For --profile=main-RExt, specifies the value of general_intra_constraint_flag to use for RExt profiles.
+\\
+
+\Option{OnePictureOnlyConstraintFlag} &
+%\ShortOption{\None} &
+\Default{false} &
+For --profile=main-RExt, specifies the value of general_one_picture_only_constraint_flag to use for RExt profiles.
 \\
 
@@ -976,4 +1024,16 @@
 Specifies the search range used for bi-prediction refinement in motion
 estimation.
+\\
+
+\Option{ClipForBiPredMEEnabled} &
+%\ShortOption{\None} &
+\Default{0} &
+Enables clipping in the Bi-Pred ME, which prevents values over- or under-flowing. It is usually disabled to reduce encoder run-time.
+\\
+
+\Option{FastMEAssumingSmootherMVEnabled} &
+%\ShortOption{\None} &
+\Default{0} &
+Enables fast ME assuming a smoother MV.
 \\
 
@@ -1014,4 +1074,9 @@
 \\
 
+\Option{DisableIntraInInter} &
+%\ShortOption{\None} &
+\Default{0} &
+Flag to disable intra PUs in inter slices.
+\\
 
 \end{OptionTableNoShorthand}
@@ -1339,12 +1404,4 @@
 \\
 
-\Option{DeblockingFilterControlPresent}&
-%\ShortOption{\None}&
-\Default{false}&
-Enables or disables the presence of the deblocking filter control
-parameters in the picture parameter set and in the slice segment header.
-When disabled, the default deblocking filter parameters are used.
-\\
-
 \Option{LoopFilterOffsetInPPS}&
 %\ShortOption{\None}&
@@ -1377,5 +1434,6 @@
 %\ShortOption{\None}&
 \Default{false}&
-Enables or disables the use of a deblocking filter metric to evaluate the suitability of deblocking..
+Enables or disables the use of a deblocking filter metric to evaluate the suitability of deblocking. If enabled then
+LoopFilterOffsetInPPS and LoopFilterDisable must be 0.
 \\
 
@@ -1408,4 +1466,22 @@
 \\
 
+\Option{TestSAODisableAtPictureLevel} &
+%\ShortOption{\None} &
+\Default{false} &
+Enables the testing of disabling SAO at the picture level after having analysed all blocks.
+\\
+
+\Option{SaoEncodingRate} &
+%\ShortOption{\None} &
+\Default{0.75} &
+When >0 SAO early picture termination is enabled for luma and chroma.
+\\
+
+\Option{SaoEncodingRateChroma} &
+%\ShortOption{\None} &
+\Default{0.5} &
+The SAO early picture termination rate to use for chroma (when m_SaoEncodingRate is >0). If <=0, use results for luma.
+\\
+
 \Option{SAOLcuBoundary} &
 %\ShortOption{\None} &
@@ -1421,4 +1497,22 @@
 prediction only permits samples from intra blocks in the same slice as the
 current block to be used for intra prediction.
+\\
+
+\Option{FastUDIUseMPMEnabled} &
+%\ShortOption{\None} &
+\Default{true} &
+If enabled, adapt intra direction search, accounting for MPM
+\\
+
+\Option{FastMEForGenBLowDelayEnabled} &
+%\ShortOption{\None} &
+\Default{true} &
+If enabled use a fast ME for generalised B Low Delay slices
+\\
+
+\Option{UseBLambdaForNonKeyLowDelayPictures} &
+%\ShortOption{\None} &
+\Default{true} &
+Enables use of B-Lambda for non-key low-delay pictures
 \\
 
@@ -2514,31 +2608,7 @@
 \\
 
-HB_LAMBDA_FOR_LDC &
-on &
-use of B-style lambda for non-key pictures in low-delay mode
-\\
-
-GPB_SIMPLE &
-on &
-Fast estimation of generalized B in low-delay mode
-\\
-
-GPB_SIMPLE_UNI &
-on &
-Fast estimation of generalized B in low-delay mode for uni-direction
-\\
-
-FASTME_SMOOTHER_MV &
-on &
-Fast ME using smoother MV assumption
-\\
-
 ADAPT_SR_SCALE &
 on &
 division factor for adaptive search range
-\\
-
-CLIP_TO_709_RANGE &
-off &
 \\
 
@@ -2689,4 +2759,10 @@
 \\
 
+\Option{ClipOutputVideoToRec709Range} &
+%\ShortOption{\None} &
+\Default{0} &
+If 1 then clip output video to the Rec. 709 Range on saving when OutputBitDepth is less than InternalBitDepth.
+\\
+
 \end{OptionTableNoShorthand}
 
Index: branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 1287)
@@ -1008,4 +1008,5 @@
   ("MaxCuDQPDepth,-dqd",                              m_iMaxCuDQPDepth,                                     0, "max depth for a minimum CuDQP")
   ("MaxCUChromaQpAdjustmentDepth",                    m_diffCuChromaQpOffsetDepth,                         -1, "Maximum depth for CU chroma Qp adjustment - set less than 0 to disable")
+  ("FastDeltaQP",                                     m_bFastDeltaQP,                                   false, "Fast Delta QP Algorithm")
 
   ("CbQpOffset,-cbqpofs",                             m_cbQpOffset,                                         0, "Chroma Cb QP Offset")
@@ -2101,5 +2102,4 @@
 
   m_uiMaxTotalCUDepth = m_uiMaxCUDepth + uiAddCUDepth + getMaxCUDepthOffset(m_chromaFormatIDC, m_uiQuadtreeTULog2MinSize); // if minimum TU larger than 4x4, allow for additional part indices for 4:2:2 SubTUs.
-  uiAddCUDepth++;
   m_uiLog2DiffMaxMinCodingBlockSize = m_uiMaxCUDepth - 1;
 
@@ -2145,4 +2145,5 @@
 #define xConfirmPara(a,b) check_failed |= confirmPara(a,b)
 
+  xConfirmPara(m_pchBitstreamFile==NULL, "A bitstream file name must be specified (BitstreamFile)");
   const UInt maxBitDepth=(m_chromaFormatIDC==CHROMA_400) ? m_internalBitDepth[CHANNEL_TYPE_LUMA] : std::max(m_internalBitDepth[CHANNEL_TYPE_LUMA], m_internalBitDepth[CHANNEL_TYPE_CHROMA]);
   xConfirmPara(m_bitDepthConstraint<maxBitDepth, "The internalBitDepth must not be greater than the bitDepthConstraint value");
@@ -2541,4 +2542,5 @@
 #endif
   }
+  xConfirmPara( m_uiMaxCUDepth < 1,                                                         "MaxPartitionDepth must be greater than zero");
   xConfirmPara( (m_uiMaxCUWidth  >> m_uiMaxCUDepth) < 4,                                    "Minimum partition width size should be larger than or equal to 8");
   xConfirmPara( (m_uiMaxCUHeight >> m_uiMaxCUDepth) < 4,                                    "Minimum partition height size should be larger than or equal to 8");
Index: branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncCfg.h	(revision 1287)
@@ -247,4 +247,5 @@
   Int       m_iMaxCuDQPDepth;                                 ///< Max. depth for a minimum CuDQPSize (0:default)
   Int       m_diffCuChromaQpOffsetDepth;                      ///< If negative, then do not apply chroma qp offsets.
+  Bool      m_bFastDeltaQP;                                   ///< Fast Delta QP (false:default)
 
   Int       m_cbQpOffset;                                     ///< Chroma Cb QP Offset (0:default)
Index: branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/App/TAppEncoder/TAppEncTop.cpp	(revision 1287)
@@ -433,4 +433,5 @@
   //====== Tool list ========
   m_cTEncTop.setDeltaQpRD                                         ( m_uiDeltaQpRD  );
+  m_cTEncTop.setFastDeltaQp                                       ( m_bFastDeltaQP  );
   m_cTEncTop.setUseASR                                            ( m_bUseASR      );
   m_cTEncTop.setUseHADME                                          ( m_bUseHADME    );
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/CommonDef.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/CommonDef.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/CommonDef.h	(revision 1287)
@@ -73,7 +73,7 @@
 #if NH_MV
 #define NV_VERSION        "14.1"                ///< Current software version
-#define HM_VERSION        "16.5"                ///< 
-#else
-#define NV_VERSION        "16.5"                 ///< Current software version
+#define HM_VERSION        "16.6"                ///< 
+#else
+#define NV_VERSION        "16.6"                 ///< Current software version
 #endif
 // ====================================================================================================================
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPattern.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPattern.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPattern.cpp	(revision 1287)
@@ -113,5 +113,5 @@
 
 // TODO: move this function to TComPrediction.cpp.
-Void TComPrediction::initIntraPatternChType( TComTU &rTu, Bool& bAbove, Bool& bLeft, const ComponentID compID, const Bool bFilterRefSamples DEBUG_STRING_FN_DECLARE(sDebug))
+Void TComPrediction::initIntraPatternChType( TComTU &rTu, const ComponentID compID, const Bool bFilterRefSamples DEBUG_STRING_FN_DECLARE(sDebug))
 {
   const ChannelType chType    = toChannelType(compID);
@@ -151,7 +151,4 @@
   iNumIntraNeighbor  += isLeftAvailable      ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1)                    );
   iNumIntraNeighbor  += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, (bNeighborFlags + iLeftUnits - 1 - iTUHeightInUnits) );
-
-  bAbove = true;
-  bLeft  = true;
 
   const UInt         uiROIWidth  = uiTuWidth2+1;
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.cpp	(revision 1287)
@@ -216,5 +216,5 @@
 // Function for calculating DC value of the reference samples used in Intra prediction
 //NOTE: Bit-Limit - 25-bit source
-Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight, Bool bAbove, Bool bLeft )
+Pel TComPrediction::predIntraGetPredValDC( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight)
 {
   assert(iWidth > 0 && iHeight > 0);
@@ -222,35 +222,14 @@
   Pel pDcVal;
 
-  if (bAbove)
-  {
-    for (iInd = 0;iInd < iWidth;iInd++)
-    {
-      iSum += pSrc[iInd-iSrcStride];
-    }
-  }
-  if (bLeft)
-  {
-    for (iInd = 0;iInd < iHeight;iInd++)
-    {
-      iSum += pSrc[iInd*iSrcStride-1];
-    }
-  }
-
-  if (bAbove && bLeft)
-  {
-    pDcVal = (iSum + iWidth) / (iWidth + iHeight);
-  }
-  else if (bAbove)
-  {
-    pDcVal = (iSum + iWidth/2) / iWidth;
-  }
-  else if (bLeft)
-  {
-    pDcVal = (iSum + iHeight/2) / iHeight;
-  }
-  else
-  {
-    pDcVal = pSrc[-1]; // Default DC value already calculated and placed in the prediction array if no neighbors are available
-  }
+  for (iInd = 0;iInd < iWidth;iInd++)
+  {
+    iSum += pSrc[iInd-iSrcStride];
+  }
+  for (iInd = 0;iInd < iHeight;iInd++)
+  {
+    iSum += pSrc[iInd*iSrcStride-1];
+  }
+
+  pDcVal = (iSum + iWidth) / (iWidth + iHeight);
 
   return pDcVal;
@@ -287,6 +266,5 @@
                                           Pel* pTrueDst, Int dstStrideTrue,
                                           UInt uiWidth, UInt uiHeight, ChannelType channelType,
-                                          UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable
-                                  , const Bool bEnableEdgeFilters
+                                          UInt dirMode, const Bool bEnableEdgeFilters
                                   )
 {
@@ -301,5 +279,5 @@
   if (modeDC)
   {
-    const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height, blkAboveAvailable, blkLeftAvailable);
+    const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height);
 
     for (Int y=height;y>0;y--, pTrueDst+=dstStrideTrue)
@@ -332,5 +310,5 @@
     Pel  refLeft[2*MAX_CU_SIZE+1];
 
-    // Initialise the Main and Left reference array.
+    // Initialize the Main and Left reference array.
     if (intraPredAngle < 0)
     {
@@ -445,5 +423,5 @@
 }
 
-Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM )
+Void TComPrediction::predIntraAng( const ComponentID compID, UInt uiDirMode, Pel* piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM )
 {
   const ChannelType    channelType = toChannelType(compID);
@@ -519,7 +497,7 @@
       const Int channelsBitDepthForPrediction = rTu.getCU()->getSlice()->getSPS()->getBitDepth(channelType);
 #endif
-      xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, bAbove, bLeft, enableEdgeFilters );
-
-      if(( uiDirMode == DC_IDX ) && bAbove && bLeft )
+      xPredIntraAng( channelsBitDepthForPrediction, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType, uiDirMode, enableEdgeFilters );
+
+      if( uiDirMode == DC_IDX )
       {
         xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, channelType );
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComPrediction.h	(revision 1287)
@@ -98,6 +98,5 @@
   TComYuv m_cYuvDepthOnVsp;
 #endif
-
-  Void xPredIntraAng            ( Int bitDepth, const Pel* pSrc, Int srcStride, Pel* pDst, Int dstStride, UInt width, UInt height, ChannelType channelType, UInt dirMode, Bool blkAboveAvailable, Bool blkLeftAvailable, const Bool bEnableEdgeFilters );
+  Void xPredIntraAng            ( Int bitDepth, const Pel* pSrc, Int srcStride, Pel* pDst, Int dstStride, UInt width, UInt height, ChannelType channelType, UInt dirMode, const Bool bEnableEdgeFilters );
   Void xPredIntraPlanar         ( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height );
 
@@ -159,6 +158,7 @@
 
   // Angular Intra
-  Void predIntraAng               ( const ComponentID compID, UInt uiDirMode, Pel *piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, Bool bAbove, Bool bLeft, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM = false );
-
+  Void predIntraAng               ( const ComponentID compID, UInt uiDirMode, Pel *piOrg /* Will be null for decoding */, UInt uiOrgStride, Pel* piPred, UInt uiStride, TComTU &rTu, const Bool bUseFilteredPredSamples, const Bool bUseLosslessDPCM = false );
+
+  Pel  predIntraGetPredValDC      ( const Pel* pSrc, Int iSrcStride, UInt iWidth, UInt iHeight);
 #if NH_3D_DMM
   Void predIntraLumaDmm           ( TComDataCU* pcCU, UInt uiAbsPartIdx, DmmID dmmType, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight );
@@ -187,6 +187,4 @@
   /// set parameters from CU data for accessing intra data
   Void initIntraPatternChType ( TComTU &rTu,
-                              Bool&       bAbove,
-                              Bool&       bLeft,
                               const ComponentID compID, const Bool bFilterRefSamples
                               DEBUG_STRING_FN_DECLARE(sDebug)
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.cpp	(revision 1287)
@@ -56,7 +56,7 @@
 , m_iAssociatedIRAP               ( 0 )
 , m_iAssociatedIRAPType           ( NAL_UNIT_INVALID )
-, m_pcRPS                         ( 0 )
-, m_LocalRPS                      ( )
-, m_iBDidx                        ( 0 )
+, m_pRPS                          ( 0 )
+, m_localRPS                      ( )
+, m_rpsIdx                        ( 0 )
 , m_RefPicListModification        ( )
 , m_eNalUnitType                  ( NAL_UNIT_CODED_SLICE_IDR_W_RADL )
@@ -465,9 +465,9 @@
   Int i;
 
-  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
       pcRefPic->setIsLongTerm(0);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -478,9 +478,9 @@
   }
 
-  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
       pcRefPic->setIsLongTerm(0);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -491,9 +491,9 @@
   }
 
-  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
       pcRefPic->setIsLongTerm(1);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -503,7 +503,7 @@
     if(pcRefPic==NULL)
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
-    }
-    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i));
   }
 
@@ -620,9 +620,9 @@
   m_pocsInCurrRPSs.clear();
 #endif
-  for(i=0; i < m_pcRPS->getNumberOfNegativePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+  for(i=0; i < m_pRPS->getNumberOfNegativePictures(); i++)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
       pcRefPic->setIsLongTerm(0);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -636,9 +636,9 @@
   }
   
-  for(; i < m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pcRPS->getDeltaPOC(i));
+  for(; i < m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures(); i++)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetRefPic(rcListPic, getPOC()+m_pRPS->getDeltaPOC(i));
       pcRefPic->setIsLongTerm(0);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -652,9 +652,9 @@
   }
   
-  for(i = m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()+m_pcRPS->getNumberOfLongtermPictures()-1; i > m_pcRPS->getNumberOfNegativePictures()+m_pcRPS->getNumberOfPositivePictures()-1 ; i--)
-  {
-    if(m_pcRPS->getUsed(i))
-    {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
+  for(i = m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()+m_pRPS->getNumberOfLongtermPictures()-1; i > m_pRPS->getNumberOfNegativePictures()+m_pRPS->getNumberOfPositivePictures()-1 ; i--)
+  {
+    if(m_pRPS->getUsed(i))
+    {
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
       pcRefPic->setIsLongTerm(1);
       pcRefPic->getPicYuvRec()->extendPicBorder();
@@ -667,7 +667,7 @@
     if(pcRefPic==NULL) 
     {
-      pcRefPic = xGetLongTermRefPic(rcListPic, m_pcRPS->getPOC(i), m_pcRPS->getCheckLTMSBPresent(i));
-    }
-    pcRefPic->setCheckLTMSBPresent(m_pcRPS->getCheckLTMSBPresent(i));  
+      pcRefPic = xGetLongTermRefPic(rcListPic, m_pRPS->getPOC(i), m_pRPS->getCheckLTMSBPresent(i));
+    }
+    pcRefPic->setCheckLTMSBPresent(m_pRPS->getCheckLTMSBPresent(i));  
   }
 
@@ -798,7 +798,7 @@
     return 0;
   }
-  for(UInt i=0; i < m_pcRPS->getNumberOfNegativePictures()+ m_pcRPS->getNumberOfPositivePictures() + m_pcRPS->getNumberOfLongtermPictures(); i++)
-  {
-    if(m_pcRPS->getUsed(i))
+  for(UInt i=0; i < m_pRPS->getNumberOfNegativePictures()+ m_pRPS->getNumberOfPositivePictures() + m_pRPS->getNumberOfLongtermPictures(); i++)
+  {
+    if(m_pRPS->getUsed(i))
     {
       numRpsCurrTempList++;
@@ -1097,6 +1097,5 @@
   m_pcVPS                = pSrc->m_pcVPS;
 #endif
-  m_pcRPS                = pSrc->m_pcRPS;
-  m_iLastIDR             = pSrc->m_iLastIDR;
+  m_pRPS                = pSrc->m_pRPS;  m_iLastIDR             = pSrc->m_iLastIDR;
 
   m_pcPic                = pSrc->m_pcPic;
@@ -1687,5 +1686,7 @@
   Int nrOfNegativePictures = 0;
   Int nrOfPositivePictures = 0;
-  TComReferencePictureSet* pcRPS = this->getLocalRPS();
+  TComReferencePictureSet* pLocalRPS = this->getLocalRPS();
+  (*pLocalRPS)=TComReferencePictureSet();
+
   Bool irapIsInRPS = false; // Used when bEfficientFieldIRAPEnabled==true
 
@@ -1705,12 +1706,12 @@
         // This picture exists as a reference picture
         // and should be added to the explicit Reference Picture Set
-        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
-        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
+        pLocalRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
+        pLocalRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
         if (bEfficientFieldIRAPEnabled)
         {
-        pcRPS->setUsed(k, pcRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) ); 
-        }
-
-        if(pcRPS->getDeltaPOC(k) < 0)
+          pLocalRPS->setUsed(k, pLocalRPS->getUsed(k) && !(bUseRecoveryPoint && this->getPOC() > pocRandomAccess && this->getPOC() + pReferencePictureSet->getDeltaPOC(i) < pocRandomAccess) );
+        }
+
+        if(pLocalRPS->getDeltaPOC(k) < 0)
         {
           nrOfNegativePictures++;
@@ -1739,6 +1740,6 @@
       if(rpcPic->getPicSym()->getSlice(0)->getPOC() == this->getAssociatedIRAPPOC() && this->getAssociatedIRAPPOC() == this->getPOC()+1)
       {
-        pcRPS->setDeltaPOC(k, 1);
-        pcRPS->setUsed(k, true);
+        pLocalRPS->setDeltaPOC(k, 1);
+        pLocalRPS->setUsed(k, true);
         nrOfPositivePictures++;
         k ++;
@@ -1747,7 +1748,7 @@
     }
   }
-  pcRPS->setNumberOfNegativePictures(nrOfNegativePictures);
-  pcRPS->setNumberOfPositivePictures(nrOfPositivePictures);
-  pcRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
+  pLocalRPS->setNumberOfNegativePictures(nrOfNegativePictures);
+  pLocalRPS->setNumberOfPositivePictures(nrOfPositivePictures);
+  pLocalRPS->setNumberOfPictures(nrOfNegativePictures+nrOfPositivePictures);
   // This is a simplistic inter rps example. A smarter encoder will look for a better reference RPS to do the
   // inter RPS prediction with.  Here we just use the reference used by pReferencePictureSet.
@@ -1755,6 +1756,6 @@
   if (!pReferencePictureSet->getInterRPSPrediction() || useNewRPS )
   {
-    pcRPS->setInterRPSPrediction(false);
-    pcRPS->setNumRefIdc(0);
+    pLocalRPS->setInterRPSPrediction(false);
+    pLocalRPS->setNumRefIdc(0);
   }
   else
@@ -1769,9 +1770,9 @@
       Int deltaPOC = ((i != iRefPics)? pcRefRPS->getDeltaPOC(i) : 0);  // check if the reference abs POC is >= 0
       Int iRefIdc = 0;
-      for (j=0; j < pcRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
-      {
-        if ( (deltaPOC + deltaRPS) == pcRPS->getDeltaPOC(j))
-        {
-          if (pcRPS->getUsed(j))
+      for (j=0; j < pLocalRPS->getNumberOfPictures(); j++) // loop through the  pictures in the new RPS
+      {
+        if ( (deltaPOC + deltaRPS) == pLocalRPS->getDeltaPOC(j))
+        {
+          if (pLocalRPS->getUsed(j))
           {
             iRefIdc = 1;
@@ -1783,14 +1784,14 @@
         }
       }
-      pcRPS->setRefIdc(i, iRefIdc);
+      pLocalRPS->setRefIdc(i, iRefIdc);
       iNewIdc++;
     }
-    pcRPS->setInterRPSPrediction(true);
-    pcRPS->setNumRefIdc(iNewIdc);
-    pcRPS->setDeltaRPS(deltaRPS);
-    pcRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
-  }
-
-  this->setRPS(pcRPS);
+    pLocalRPS->setInterRPSPrediction(true);
+    pLocalRPS->setNumRefIdc(iNewIdc);
+    pLocalRPS->setDeltaRPS(deltaRPS);
+    pLocalRPS->setDeltaRIdxMinus1(pReferencePictureSet->getDeltaRIdxMinus1() + this->getSPS()->getRPSList()->getNumberOfReferencePictureSets() - this->getRPSidx());
+  }
+
+  this->setRPS(pLocalRPS);
   this->setRPSidx(-1);
 }
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibCommon/TComSlice.h	(revision 1287)
@@ -2479,7 +2479,7 @@
   Int                        m_iAssociatedIRAP;
   NalUnitType                m_iAssociatedIRAPType;
-  TComReferencePictureSet*   m_pcRPS;
-  TComReferencePictureSet    m_LocalRPS;
-  Int                        m_iBDidx;
+  const TComReferencePictureSet* m_pRPS;             //< pointer to RPS, either in the SPS or the local RPS in the same slice header
+  TComReferencePictureSet    m_localRPS;             //< RPS when present in slice header
+  Int                        m_rpsIdx;               //< index of used RPS in the SPS or -1 for local RPS in the slice header
   TComRefPicListModification m_RefPicListModification;
   NalUnitType                m_eNalUnitType;         ///< Nal unit type for the slice
@@ -2676,10 +2676,10 @@
   Void                        setSaoEnabledFlag(ChannelType chType, Bool s)          {m_saoEnabledFlag[chType] =s;                                   }
   Bool                        getSaoEnabledFlag(ChannelType chType) const            { return m_saoEnabledFlag[chType];                              }
-  Void                        setRPS( TComReferencePictureSet *pcRPS )               { m_pcRPS = pcRPS;                                              }
-  TComReferencePictureSet*    getRPS()                                               { return m_pcRPS;                                               }
-  TComReferencePictureSet*    getLocalRPS()                                          { return &m_LocalRPS;                                           }
-
-  Void                        setRPSidx( Int iBDidx )                                { m_iBDidx = iBDidx;                                            }
-  Int                         getRPSidx() const                                      { return m_iBDidx;                                              }
+  Void                        setRPS( const TComReferencePictureSet *pcRPS )         { m_pRPS = pcRPS;                                               }
+  const TComReferencePictureSet* getRPS()                                            { return m_pRPS;                                                }
+  TComReferencePictureSet*    getLocalRPS()                                          { return &m_localRPS;                                           }
+
+  Void                        setRPSidx( Int rpsIdx )                                { m_rpsIdx = rpsIdx;                                            }
+  Int                         getRPSidx() const                                      { return m_rpsIdx;                                              }
   TComRefPicListModification* getRefPicListModification()                            { return &m_RefPicListModification;                             }
   Void                        setLastIDR(Int iIDRPOC)                                { m_iLastIDR = iIDRPOC;                                         }
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCAVLC.cpp	(revision 1287)
@@ -2349,8 +2349,5 @@
 #endif
       TComReferencePictureSet* rps = pcSlice->getLocalRPS();
-      rps->setNumberOfNegativePictures(0);
-      rps->setNumberOfPositivePictures(0);
-      rps->setNumberOfLongtermPictures(0);
-      rps->setNumberOfPictures(0);
+      (*rps)=TComReferencePictureSet();
       pcSlice->setRPS(rps);
 #if NH_MV
@@ -2391,4 +2388,6 @@
       TComReferencePictureSet* rps;
       rps = pcSlice->getLocalRPS();
+      (*rps)=TComReferencePictureSet();
+
       pcSlice->setRPS(rps);
       READ_FLAG( uiCode, "short_term_ref_pic_set_sps_flag" );
@@ -2528,8 +2527,5 @@
         // In the case of BLA picture types, rps data is read from slice header but ignored
         rps = pcSlice->getLocalRPS();
-        rps->setNumberOfNegativePictures(0);
-        rps->setNumberOfPositivePictures(0);
-        rps->setNumberOfLongtermPictures(0);
-        rps->setNumberOfPictures(0);
+        (*rps)=TComReferencePictureSet();
         pcSlice->setRPS(rps);
       }
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibDecoder/TDecCu.cpp	(revision 1287)
@@ -85,10 +85,17 @@
 #endif
 
-  UInt uiNumPartitions;
   for ( UInt ui = 0; ui < m_uiMaxDepth-1; ui++ )
   {
-    uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
+    UInt uiNumPartitions = 1<<( ( m_uiMaxDepth - ui - 1 )<<1 );
     UInt uiWidth  = uiMaxWidth  >> ui;
     UInt uiHeight = uiMaxHeight >> ui;
+
+    // The following arrays (m_ppcYuvResi, m_ppcYuvReco and m_ppcCU) are only required for CU depths
+    // although data is allocated for all possible depths of the CU/TU tree except the last.
+    // Since the TU tree will always include at least one additional depth greater than the CU tree,
+    // there will be enough entries for these arrays.
+    // (Section 7.4.3.2: "The CVS shall not contain data that result in (Log2MinTrafoSize) MinTbLog2SizeY
+    //                    greater than or equal to MinCbLog2SizeY")
+    // TODO: tidy the array allocation given the above comment.
 
     m_ppcYuvResi[ui] = new TComYuv;    m_ppcYuvResi[ui]->create( uiWidth, uiHeight, chromaFormatIDC );
@@ -778,12 +785,12 @@
   {
     const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, VER_IDX, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
-    m_pcPrediction->initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
-    m_pcPrediction->predIntraAng( COMPONENT_Y,   VER_IDX, 0 /* Decoder does not have an original image */, 0, piReco, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+    m_pcPrediction->initIntraPatternChType( rTu, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
+    m_pcPrediction->predIntraAng( COMPONENT_Y,   VER_IDX, 0 /* Decoder does not have an original image */, 0, piReco, uiStride, rTu, bUseFilteredPredictions );
   }
   else if ( pcCU->getDISType(uiAbsPartIdx) == 1 )
   {
     const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, HOR_IDX, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
-    m_pcPrediction->initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
-    m_pcPrediction->predIntraAng( COMPONENT_Y,   HOR_IDX, 0 /* Decoder does not have an original image */, 0, piReco, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+    m_pcPrediction->initIntraPatternChType( rTu, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
+    m_pcPrediction->predIntraAng( COMPONENT_Y,   HOR_IDX, 0 /* Decoder does not have an original image */, 0, piReco, uiStride, rTu, bUseFilteredPredictions );
   }
   else if ( pcCU->getDISType(uiAbsPartIdx) == 2 )
@@ -1031,7 +1038,4 @@
 
   //===== init availability pattern =====
-  Bool  bAboveAvail = false;
-  Bool  bLeftAvail  = false;
-
   const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
 
@@ -1041,5 +1045,5 @@
 
   DEBUG_STRING_NEW(sTemp)
-  m_pcPrediction->initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
+  m_pcPrediction->initIntraPatternChType( rTu, compID, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
 
 
@@ -1053,5 +1057,5 @@
   {
 #endif
-  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+  m_pcPrediction->predIntraAng( compID,   uiChFinalMode, 0 /* Decoder does not have an original image */, 0, piPred, uiStride, rTu, bUseFilteredPredictions );
 #if NH_3D_DMM
   }
@@ -1269,7 +1273,5 @@
     TComTURecurse tuRecurseWithPU(tuRecurseCU, false, TComTU::DONT_SPLIT);
 
-    Bool bAboveAvail = false;
-    Bool bLeftAvail  = false;
-    m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
+    m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
 
     // get partition
@@ -1321,10 +1323,8 @@
       
       //===== init pattern for luma prediction =====
-      Bool bAboveAvail = false;
-      Bool bLeftAvail  = false;
       
-      m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilter  DEBUG_STRING_PASS_INTO(sTemp) );
+      m_pcPrediction->initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, bUseFilter  DEBUG_STRING_PASS_INTO(sTemp) );
       
-      m_pcPrediction->predIntraAng( COMPONENT_Y, uiLumaPredMode, NULL, uiStrideTU, piPredTU, uiStrideTU, tuRecurseWithPU, bAboveAvail, bLeftAvail, bUseFilter );
+      m_pcPrediction->predIntraAng( COMPONENT_Y, uiLumaPredMode, NULL, uiStrideTU, piPredTU, uiStrideTU, tuRecurseWithPU, bUseFilter );
       
       // copy for prediction of next part
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCfg.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCfg.h	(revision 1287)
@@ -257,4 +257,5 @@
   Int*      m_aidQP;
   UInt      m_uiDeltaQpRD;
+  Bool      m_bFastDeltaQP;
 
   Bool      m_bUseConstrainedIntraPred;
@@ -710,4 +711,5 @@
   Void      setdQPs                         ( Int*  p )     { m_aidQP       = p; }
   Void      setDeltaQpRD                    ( UInt  u )     {m_uiDeltaQpRD  = u; }
+  Void      setFastDeltaQp                  ( Bool  b )     {m_bFastDeltaQP = b; }
   Bool      getUseASR                       ()      { return m_bUseASR;     }
   Bool      getUseHADME                     ()      { return m_bUseHADME;   }
@@ -758,6 +760,7 @@
   Void setIntraSmoothingDisabledFlag               (Bool bValue) { m_intraSmoothingDisabledFlag=bValue; }
 
-  Int*      getdQPs                         ()      { return m_aidQP;       }
-  UInt      getDeltaQpRD                    ()      { return m_uiDeltaQpRD; }
+  Int*      getdQPs                         ()       { return m_aidQP;       }
+  UInt      getDeltaQpRD                    () const { return m_uiDeltaQpRD; }
+  Bool      getFastDeltaQp                  () const { return m_bFastDeltaQP; }
 
   //====== Slice ========
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.cpp	(revision 1287)
@@ -122,4 +122,5 @@
   m_stillToCodeChromaQpOffsetFlag  = false;
   m_cuChromaQpOffsetIdxPlus1       = 0;
+  m_bFastDeltaQP                   = false;
 
   // initialize partition order.
@@ -406,7 +407,7 @@
 */
 #if AMP_ENC_SPEEDUP
-Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize )
-#else
-Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth )
+Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug_), PartSize eParentPartSize )
+#else
+Void TEncCu::xCompressCU( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth )
 #endif
 {
@@ -415,4 +416,7 @@
   const TComPPS &pps=*(rpcTempCU->getSlice()->getPPS());
   const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
+  
+  // These are only used if getFastDeltaQp() is true
+  const UInt fastDeltaQPCuMaxSize    = Clip3(sps.getMaxCUHeight()>>sps.getLog2DiffMaxMinCodingBlockSize(), sps.getMaxCUHeight(), 32u);
 
 
@@ -437,8 +441,4 @@
   Bool    bTrySplitDQP  = true;
 #endif
-
-    // variable for Early CU determination
-  Bool    bSubBranch = true;
-
   // variable for Cbf fast mode PU decision
   Bool    doNotBlockPu = true;
@@ -453,9 +453,9 @@
 #endif
 #endif
-  Bool bBoundary = false;
-  UInt uiLPelX   = rpcBestCU->getCUPelX();
-  UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
-  UInt uiTPelY   = rpcBestCU->getCUPelY();
-  UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
+  const UInt uiLPelX   = rpcBestCU->getCUPelX();
+  const UInt uiRPelX   = uiLPelX + rpcBestCU->getWidth(0)  - 1;
+  const UInt uiTPelY   = rpcBestCU->getCUPelY();
+  const UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
+  const UInt uiWidth   = rpcBestCU->getWidth(0);
 
 #if H_MV_ENC_DEC_TRAC
@@ -515,7 +515,8 @@
 
   TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx());
-  // We need to split, so don't try these modes.
-  if ( ( uiRPelX < sps.getPicWidthInLumaSamples() ) &&
-       ( uiBPelY < sps.getPicHeightInLumaSamples() ) )
+
+  const Bool bBoundary = !( uiRPelX < sps.getPicWidthInLumaSamples() && uiBPelY < sps.getPicHeightInLumaSamples() );
+
+  if ( !bBoundary )
   {
 #if  H_3D_FAST_TEXTURE_ENCODING
@@ -1187,9 +1188,11 @@
     }
 
-    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
-    m_pcEntropyCoder->resetBits();
-    m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
-    rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
-    rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
+    if( rpcBestCU->getTotalCost()!=MAX_DOUBLE )
+    {
+      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
+      m_pcEntropyCoder->resetBits();
+      m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
+      rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
+      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
 #if NH_3D_VSO // M8
     if ( m_pcRdCost->getUseVSO() )    
@@ -1200,14 +1203,5 @@
 #endif
       rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
-    m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
-
-    // Early CU determination
-    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
-    {
-      bSubBranch = false;
-    }
-    else
-    {
-      bSubBranch = true;
+      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     }
 #if  H_3D_FAST_TEXTURE_ENCODING
@@ -1218,11 +1212,7 @@
 #endif
   }
-  else
-  {
-    bBoundary = true;
-  }
-
-  // copy orginal YUV samples to PCM buffer
-  if( rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
+
+  // copy original YUV samples to PCM buffer
+  if( rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isLosslessCoded(0) && (rpcBestCU->getIPCMFlag(0) == false))
   {
     xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
@@ -1258,18 +1248,18 @@
   }
 
-  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
-  {
-    const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
-
-    rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
-
+  const Bool bSubBranch = bBoundary || !( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isSkipped(0) );
+#if NH_3D_QTLPC
+  if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary) && bTrySplitDQP )
+#else
+  if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() && (!getFastDeltaQp() || uiWidth > fastDeltaQPCuMaxSize || bBoundary))
+#endif
+  {
     // further split
-#if NH_3D_QTLPC
-
-    if( bSubBranch && bTrySplitDQP && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() )
-#else
-    if( bSubBranch && uiDepth < sps.getLog2DiffMaxMinCodingBlockSize() )
-#endif
-    {
+    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
+    {
+      const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
+
+      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
+
 #if NH_3D_VSO // M9
       // reset Model
@@ -1310,5 +1300,5 @@
 #if AMP_ENC_SPEEDUP
           DEBUG_STRING_NEW(sChild)
-          if ( !rpcBestCU->isInter(0) )
+          if ( !(rpcBestCU->getTotalCost()!=MAX_DOUBLE && rpcBestCU->isInter(0)) )
           {
             xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth DEBUG_STRING_PASS_INTO(sChild), NUMBER_OF_PART_SIZES );
@@ -1366,9 +1356,8 @@
         }
 
-        UInt uiTargetPartIdx = 0;
         if ( hasResidual )
         {
           m_pcEntropyCoder->resetBits();
-          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
+          m_pcEntropyCoder->encodeQP( rpcTempCU, 0, false );
           rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
           rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
@@ -1383,10 +1372,10 @@
 
           Bool foundNonZeroCbf = false;
-          rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth, foundNonZeroCbf );
+          rpcTempCU->setQPSubCUs( rpcTempCU->getRefQP( 0 ), 0, uiDepth, foundNonZeroCbf );
           assert( foundNonZeroCbf );
         }
         else
         {
-          rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( uiTargetPartIdx ), 0, uiDepth ); // set QP to default QP
+          rpcTempCU->setQPSubParts( rpcTempCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP
         }
       }
@@ -1399,19 +1388,22 @@
       // This can be achieved by forcing the decision to be that of the rpcTempCU.
       // The exception is each slice / slice-segment must have at least one CTU.
-      const Bool isEndOfSlice        =    pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES
-                                       && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3)
-                                       && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr())
-                                       && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
-      const Bool isEndOfSliceSegment =    pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
-                                       && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3)
-                                       && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
-                                           // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice.
-      if(isEndOfSlice||isEndOfSliceSegment)
+      if (rpcBestCU->getTotalCost()!=MAX_DOUBLE)
       {
-        rpcBestCU->getTotalCost()=MAX_DOUBLE;
+        const Bool isEndOfSlice        =    pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES
+                                         && ((pcSlice->getSliceBits()+rpcBestCU->getTotalBits())>pcSlice->getSliceArgument()<<3)
+                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceCurStartCtuTsAddr())
+                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
+        const Bool isEndOfSliceSegment =    pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES
+                                         && ((pcSlice->getSliceSegmentBits()+rpcBestCU->getTotalBits()) > pcSlice->getSliceSegmentArgument()<<3)
+                                         && rpcBestCU->getCtuRsAddr() != pcPic->getPicSym()->getCtuTsToRsAddrMap(pcSlice->getSliceSegmentCurStartCtuTsAddr());
+                                             // Do not need to check slice condition for slice-segment since a slice-segment is a subset of a slice.
+        if(isEndOfSlice||isEndOfSliceSegment)
+        {
+          rpcBestCU->getTotalCost()=MAX_DOUBLE;
+        }
       }
 
       xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth DEBUG_STRING_PASS_INTO(sDebug) DEBUG_STRING_PASS_INTO(sTempDebug) DEBUG_STRING_PASS_INTO(false) ); // RD compare current larger prediction
-                                                                                       // with sub partitioned prediction.
+                                                                                                                                                       // with sub partitioned prediction.
     }
   }
@@ -1785,4 +1777,8 @@
 {
   assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
+  if(getFastDeltaQp())
+  {
+    return;   // never check merge in fast deltaqp mode
+  }
 #if NH_3D_MLC
   TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
@@ -2247,4 +2243,14 @@
   DEBUG_STRING_NEW(sTest)
 
+  if(getFastDeltaQp())
+  {
+    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
+    const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
+    if(ePartSize != SIZE_2Nx2N || rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
+    {
+      return; // only check necessary 2Nx2N Inter in fast deltaqp mode
+    }
+  }
+
   // prior to this, rpcTempCU will have just been reset using rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
 #if H_3D || NH_3D_ARP
@@ -2740,4 +2746,14 @@
   DEBUG_STRING_NEW(sTest)
 
+  if(getFastDeltaQp())
+  {
+    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
+    const UInt fastDeltaQPCuMaxSize = Clip3(sps.getMaxCUHeight()>>(sps.getLog2DiffMaxMinCodingBlockSize()), sps.getMaxCUHeight(), 32u);
+    if(rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxSize)
+    {
+      return; // only check necessary 2Nx2N Intra in fast deltaqp mode
+    }
+  }
+
   UInt uiDepth = rpcTempCU->getDepth( 0 );
 #if NH_3D_VSO // M5
@@ -2844,4 +2860,14 @@
 Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU )
 {
+  if(getFastDeltaQp())
+  {
+    const TComSPS &sps=*(rpcTempCU->getSlice()->getSPS());
+    const UInt fastDeltaQPCuMaxPCMSize = Clip3((UInt)1<<sps.getPCMLog2MinSize(), (UInt)1<<sps.getPCMLog2MaxSize(), 32u);
+    if (rpcTempCU->getWidth( 0 ) > fastDeltaQPCuMaxPCMSize)
+    {
+      return;   // only check necessary PCM in fast deltaqp mode
+    }
+  }
+  
   UInt uiDepth = rpcTempCU->getDepth( 0 );
 
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncCu.h	(revision 1287)
@@ -88,4 +88,5 @@
   //  Data : encoder control
   Bool                    m_bEncodeDQP;
+  Bool                    m_bFastDeltaQP;
   Bool                    m_stillToCodeChromaQpOffsetFlag; //indicates whether chroma QP offset flag needs to coded at this particular CU granularity.
   Int                     m_cuChromaQpOffsetIdxPlus1; // if 0, then cu_chroma_qp_offset_flag will be 0, otherwise cu_chroma_qp_offset_flag will be 1.
@@ -132,10 +133,12 @@
 #endif
 
+  Void setFastDeltaQp       ( Bool b)                 { m_bFastDeltaQP = b;         }
+
 protected:
   Void  finishCU            ( TComDataCU*  pcCU, UInt uiAbsPartIdx );
 #if AMP_ENC_SPEEDUP
-  Void  xCompressCU         ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug), PartSize eParentPartSize = NUMBER_OF_PART_SIZES );
-#else
-  Void  xCompressCU         ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth        );
+  Void  xCompressCU         ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth DEBUG_STRING_FN_DECLARE(sDebug), PartSize eParentPartSize = NUMBER_OF_PART_SIZES );
+#else
+  Void  xCompressCU         ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, const UInt uiDepth        );
 #endif
   Void  xEncodeCU           ( TComDataCU*  pcCU, UInt uiAbsPartIdx,           UInt uiDepth        );
@@ -181,4 +184,6 @@
   Void setdQPFlag           ( Bool b )                { m_bEncodeDQP = b;           }
 
+  Bool getFastDeltaQp       () const                  { return m_bFastDeltaQP;      }
+
   Bool getCodeChromaQpAdjFlag() { return m_stillToCodeChromaQpOffsetFlag; }
   Void setCodeChromaQpAdjFlag( Bool b ) { m_stillToCodeChromaQpOffsetFlag = b; }
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1287)
@@ -1264,5 +1264,4 @@
     pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcCfg->getEfficientFieldIRAPEnabled());
     m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
-    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
     if (!m_pcCfg->getEfficientFieldIRAPEnabled())
     {
@@ -1757,5 +1756,5 @@
       {
         m_pcSliceEncoder->precompressSlice( pcPic );
-        m_pcSliceEncoder->compressSlice   ( pcPic, false );
+        m_pcSliceEncoder->compressSlice   ( pcPic, false, false );
 
         const UInt curSliceSegmentEnd = pcSlice->getSliceSegmentCurEndCtuTsAddr();
@@ -2741,9 +2740,11 @@
 Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic)
 {
-  TComReferencePictureSet *rps = pcSlice->getRPS();
-  if(!rps->getNumberOfLongtermPictures())
+  if(pcSlice->getRPS()->getNumberOfLongtermPictures() == 0)
   {
     return;
   }
+  // we can only modify the local RPS!
+  assert (pcSlice->getRPSidx()==-1);
+  TComReferencePictureSet *rps = pcSlice->getLocalRPS();
 
   // Arrange long-term reference pictures in the correct order of LSB and MSB,
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 1287)
@@ -116,4 +116,18 @@
 
 TEncSearch::TEncSearch()
+: m_puhQTTempTrIdx(NULL)
+, m_pcQTTempTComYuv(NULL)
+, m_pcEncCfg (NULL)
+, m_pcTrQuant (NULL)
+, m_pcRdCost (NULL)
+, m_pcEntropyCoder (NULL)
+, m_iSearchRange (0)
+, m_bipredSearchRange (0)
+, m_iFastSearch (0)
+, m_pppcRDSbacCoder (NULL)
+, m_pcRDGoOnSbacCoder (NULL)
+, m_pTempPel (NULL)
+, m_puiDFilter (NULL)
+, m_isInitialized (false)
 {
   for (UInt ch=0; ch<MAX_NUM_COMPONENT; ch++)
@@ -134,17 +148,21 @@
     m_puhQTTempTransformSkipFlag[ch]               = NULL;
   }
-  m_puhQTTempTrIdx                                 = NULL;
-  m_pcQTTempTComYuv                                = NULL;
-  m_pcEncCfg                                       = NULL;
-  m_pcEntropyCoder                                 = NULL;
-  m_pTempPel                                       = NULL;
+
+  for (Int i=0; i<MAX_NUM_REF_LIST_ADAPT_SR; i++)
+  {
+    memset (m_aaiAdaptSR[i], 0, MAX_IDX_ADAPT_SR * sizeof (Int));
+  }
+  for (Int i=0; i<AMVP_MAX_NUM_CANDS+1; i++)
+  {
+    memset (m_auiMVPIdxCost[i], 0, (AMVP_MAX_NUM_CANDS+1) * sizeof (UInt) );
+  }
+
   setWpScalingDistParam( NULL, -1, REF_PIC_LIST_X );
 }
 
 
-
-
-TEncSearch::~TEncSearch()
+Void TEncSearch::destroy()
 {
+  assert (m_isInitialized);
   if ( m_pTempPel )
   {
@@ -197,4 +215,13 @@
 
   m_tmpYuvPred.destroy();
+  m_isInitialized = false;
+}
+
+TEncSearch::~TEncSearch()
+{
+  if (m_isInitialized)
+  {
+    destroy();
+  }
 }
 
@@ -216,4 +243,5 @@
                       )
 {
+  assert (!m_isInitialized);
   m_pcEncCfg             = pcEncCfg;
   m_pcTrQuant            = pcTrQuant;
@@ -296,4 +324,5 @@
   m_pcQTTempTransformSkipTComYuv.create( maxCUWidth, maxCUHeight, pcEncCfg->getChromaFormatIdc() );
   m_tmpYuvPred.create(MAX_CU_SIZE, MAX_CU_SIZE, pcEncCfg->getChromaFormatIdc());
+  m_isInitialized = true;
 }
 
@@ -1224,7 +1253,4 @@
 
   //===== init availability pattern =====
-  Bool  bAboveAvail = false;
-  Bool  bLeftAvail  = false;
-
   DEBUG_STRING_NEW(sTemp)
 
@@ -1235,5 +1261,5 @@
     const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(compID, uiChFinalMode, uiWidth, uiHeight, chFmt, sps.getSpsRangeExtension().getIntraSmoothingDisabledFlag());
 
-    initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, compID, bUseFilteredPredictions DEBUG_STRING_PASS_INTO(sDebug) );
+    initIntraPatternChType( rTu, compID, bUseFilteredPredictions DEBUG_STRING_PASS_INTO(sDebug) );
 
     //===== get prediction signal =====
@@ -1246,5 +1272,5 @@
     {
 #endif
-    predIntraAng( compID, uiChFinalMode, piOrg, uiStride, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+    predIntraAng( compID, uiChFinalMode, piOrg, uiStride, piPred, uiStride, rTu, bUseFilteredPredictions );
 #if NH_3D_DMM
     }
@@ -1575,4 +1601,7 @@
   checkTransformSkip           &= (!pcCU->getCUTransquantBypass(0));
 
+  assert (rTu.ProcessComponentSection(COMPONENT_Y));
+  const UInt totalAdjustedDepthChan   = rTu.GetTransformDepthTotalAdj(COMPONENT_Y);
+
   if ( m_pcEncCfg->getUseTransformSkipFast() )
   {
@@ -1609,11 +1638,8 @@
         }
 
-        if (rTu.ProcessComponentSection(COMPONENT_Y))
-        {
-          const UInt totalAdjustedDepthChan = rTu.GetTransformDepthTotalAdj(COMPONENT_Y);
-          pcCU->setTransformSkipSubParts ( modeId, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
-
-          xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, singleDistTmpLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sModeString), default0Save1Load2 );
-        }
+
+        pcCU->setTransformSkipSubParts ( modeId, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
+        xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, singleDistTmpLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sModeString), default0Save1Load2 );
+
         singleCbfTmpLuma = pcCU->getCbf( uiAbsPartIdx, COMPONENT_Y, uiTrDepth );
 
@@ -1669,17 +1695,10 @@
       }
 
-      if (rTu.ProcessComponentSection(COMPONENT_Y))
-      {
-        const UInt totalAdjustedDepthChan   = rTu.GetTransformDepthTotalAdj(COMPONENT_Y);
-        pcCU ->setTransformSkipSubParts ( bestModeId[COMPONENT_Y], COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
-      }
+      pcCU ->setTransformSkipSubParts ( bestModeId[COMPONENT_Y], COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
 
       if(bestModeId[COMPONENT_Y] == firstCheckId)
       {
         xLoadIntraResultQT(COMPONENT_Y, rTu );
-        if (rTu.ProcessComponentSection(COMPONENT_Y))
-        {
-          pcCU->setCbfSubParts  ( uiSingleCbfLuma << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, rTu.GetTransformDepthTotalAdj(COMPONENT_Y) );
-        }
+        pcCU->setCbfSubParts  ( uiSingleCbfLuma << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, rTu.GetTransformDepthTotalAdj(COMPONENT_Y) );
 
         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
@@ -1695,13 +1714,8 @@
       //----- code luma/chroma block with given intra prediction mode and store Cbf-----
       dSingleCost   = 0.0;
-
-      if (rTu.ProcessComponentSection(COMPONENT_Y))
-      {
-        const UInt totalAdjustedDepthChan   = rTu.GetTransformDepthTotalAdj(COMPONENT_Y);
-        pcCU ->setTransformSkipSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
-      }
 #if NH_3D_ENC_DEPTH
       xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug), zeroResiFlag );
 #else
+      pcCU ->setTransformSkipSubParts ( 0, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
       xIntraCodingTUBlock( pcOrgYuv, pcPredYuv, pcResiYuv, resiLumaSingle, false, uiSingleDistLuma, COMPONENT_Y, rTu DEBUG_STRING_PASS_INTO(sDebug));
 #endif
@@ -1835,5 +1849,4 @@
     pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiFullDepth );
     const TComRectangle &tuRect=rTu.getRect(COMPONENT_Y);
-    const UInt totalAdjustedDepthChan   = rTu.GetTransformDepthTotalAdj(COMPONENT_Y);
     pcCU->setCbfSubParts  ( uiSingleCbfLuma << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
     pcCU ->setTransformSkipSubParts  ( bestModeId[COMPONENT_Y], COMPONENT_Y, uiAbsPartIdx, totalAdjustedDepthChan );
@@ -1889,7 +1902,4 @@
   //===== reconstruction =====
 
-  Bool bAboveAvail = false;
-  Bool bLeftAvail  = false;
-
   TComTURecurse rTu(pcCU, 0);
   const ChromaFormat chFmt     = rTu.GetChromaFormat();
@@ -1898,12 +1908,12 @@
   {
     const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, VER_IDX, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
-    initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
-    predIntraAng( COMPONENT_Y, VER_IDX, 0, uiStride, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+    initIntraPatternChType( rTu, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
+    predIntraAng( COMPONENT_Y, VER_IDX, 0, uiStride, piPred, uiStride, rTu, bUseFilteredPredictions );
   }
   else if ( uiPredMode == 1 )
   {
     const Bool bUseFilteredPredictions=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, HOR_IDX, uiWidth, uiHeight, chFmt, pcCU->getSlice()->getSPS()->getSpsRangeExtension().getIntraSmoothingDisabledFlag());
-    initIntraPatternChType( rTu, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
-    predIntraAng( COMPONENT_Y, HOR_IDX, 0, uiStride, piPred, uiStride, rTu, bAboveAvail, bLeftAvail, bUseFilteredPredictions );
+    initIntraPatternChType( rTu, COMPONENT_Y, bUseFilteredPredictions  DEBUG_STRING_PASS_INTO(sTemp) );
+    predIntraAng( COMPONENT_Y, HOR_IDX, 0, uiStride, piPred, uiStride, rTu, bUseFilteredPredictions );
   }
   else if ( uiPredMode == 2 )
@@ -2019,7 +2029,5 @@
     TComTURecurse tuRecurseWithPU(tuRecurseCU, false, TComTU::DONT_SPLIT);
 
-    Bool bAboveAvail = false;
-    Bool bLeftAvail  = false;
-    initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
+    initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, false DEBUG_STRING_PASS_INTO(sTemp) );
 
     // get partition
@@ -2075,10 +2083,8 @@
       
       //===== init pattern for luma prediction =====
-      Bool bAboveAvail = false;
-      Bool bLeftAvail  = false;
       
-      initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, bUseFilter DEBUG_STRING_PASS_INTO(sTemp2) );
+      initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, bUseFilter DEBUG_STRING_PASS_INTO(sTemp2) );
       
-      predIntraAng( COMPONENT_Y, uiLumaPredMode, piOrgTU, uiStrideTU, piPredTU, uiStrideTU, tuRecurseWithPU, bAboveAvail, bLeftAvail, bUseFilter );
+      predIntraAng( COMPONENT_Y, uiLumaPredMode, piOrgTU, uiStrideTU, piPredTU, uiStrideTU, tuRecurseWithPU, bUseFilter );
       
       // copy for prediction of next part
@@ -2858,6 +2864,4 @@
   //{
     //===== init pattern for luma prediction =====
-    Bool bAboveAvail = false;
-    Bool bLeftAvail  = false;
     DEBUG_STRING_NEW(sTemp2)
 
@@ -2867,8 +2871,7 @@
     Int numModesForFullRD = m_pcEncCfg->getFastUDIUseMPMEnabled()?g_aucIntraModeNumFast_UseMPM[ uiWidthBit ] : g_aucIntraModeNumFast_NotUseMPM[ uiWidthBit ];
 
-    if (tuRecurseWithPU.ProcessComponentSection(COMPONENT_Y))
-    {
-      initIntraPatternChType( tuRecurseWithPU, bAboveAvail, bLeftAvail, COMPONENT_Y, true DEBUG_STRING_PASS_INTO(sTemp2) );
-    }
+    // this should always be true
+    assert (tuRecurseWithPU.ProcessComponentSection(COMPONENT_Y));
+    initIntraPatternChType( tuRecurseWithPU, COMPONENT_Y, true DEBUG_STRING_PASS_INTO(sTemp2) );
 #if NH_3D_ENC_DEPTH
     if( bOnlyIVP )
@@ -2917,5 +2920,5 @@
         const Bool bUseFilter=TComPrediction::filteringIntraReferenceSamples(COMPONENT_Y, uiMode, puRect.width, puRect.height, chFmt, sps.getSpsRangeExtension().getIntraSmoothingDisabledFlag());
 
-        predIntraAng( COMPONENT_Y, uiMode, piOrg, uiStride, piPred, uiStride, tuRecurseWithPU, bAboveAvail, bLeftAvail, bUseFilter, TComPrediction::UseDPCMForFirstPassIntraEstimation(tuRecurseWithPU, uiMode) );
+        predIntraAng( COMPONENT_Y, uiMode, piOrg, uiStride, piPred, uiStride, tuRecurseWithPU, bUseFilter, TComPrediction::UseDPCMForFirstPassIntraEstimation(tuRecurseWithPU, uiMode) );
 #if NH_3D_VSO // M34
         Dist uiSad;           
@@ -6366,5 +6369,5 @@
                   nonCoeffDist = m_pcRdCost->getDistPart( channelBitDepth, m_pcQTTempTComYuv[uiQTTempAccessLayer].getAddrPix( compID, tuCompRect.x0, tuCompRect.y0 ),
                                                           m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride( compID ), pcResi->getAddrPix( compID, tuCompRect.x0, tuCompRect.y0 ),
-                                                          pcResi->getStride(compID), tuCompRect.width, tuCompRect.height, compID); // initialized with zero residual destortion
+                                                          pcResi->getStride(compID), tuCompRect.width, tuCompRect.height, compID); // initialized with zero residual distortion
                 }
                 else
@@ -6388,5 +6391,5 @@
 #endif
                     nonCoeffDist = m_pcRdCost->getDistPart( channelBitDepth, m_pTempPel, tuCompRect.width, pcResi->getAddrPix( compID, tuCompRect.x0, tuCompRect.y0 ),
-                                                          pcResi->getStride(compID), tuCompRect.width, tuCompRect.height, compID); // initialized with zero residual destortion
+                                                          pcResi->getStride(compID), tuCompRect.width, tuCompRect.height, compID); // initialized with zero residual distortion
                     
                 }
@@ -6412,5 +6415,5 @@
               if((puiZeroDist != NULL) && isFirstMode)
               {
-                *puiZeroDist += nonCoeffDist; // initialized with zero residual destortion
+                *puiZeroDist += nonCoeffDist; // initialized with zero residual distortion
               }
 
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSearch.h	(revision 1287)
@@ -127,9 +127,10 @@
   TComMv          m_integerMv2Nx2N[NUM_REF_PIC_LIST_01][MAX_NUM_REF];
 
+  Bool            m_isInitialized;
 public:
   TEncSearch();
   virtual ~TEncSearch();
 
-  Void init(  TEncCfg*      pcEncCfg,
+  Void init(TEncCfg*      pcEncCfg,
             TComTrQuant*  pcTrQuant,
             Int           iSearchRange,
@@ -143,4 +144,6 @@
             TEncSbac***   pppcRDSbacCoder,
             TEncSbac*     pcRDGoOnSbacCoder );
+
+  Void destroy();
 
 protected:
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1287)
@@ -680,5 +680,5 @@
 
     // try compress
-    compressSlice   ( pcPic, true );
+    compressSlice   ( pcPic, true, m_pcCfg->getFastDeltaQp());
 
 #if NH_3D_VSO
@@ -751,5 +751,5 @@
 /** \param pcPic   picture class
  */
-Void TEncSlice::compressSlice( TComPic* pcPic, const Bool bCompressEntireSlice )
+Void TEncSlice::compressSlice( TComPic* pcPic, const Bool bCompressEntireSlice, const Bool bFastDeltaQP )
 {
   // if bCompressEntireSlice is true, then the entire slice (not slice segment) is compressed,
@@ -781,4 +781,6 @@
   TComBitCounter  tempBitCounter;
   const UInt      frameWidthInCtus = pcPic->getPicSym()->getFrameWidthInCtus();
+  
+  m_pcCuEncoder->setFastDeltaQp(bFastDeltaQP);
 
   //------------------------------------------------------------------------------
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.h	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncSlice.h	(revision 1287)
@@ -126,5 +126,5 @@
   // compress and encode slice
   Void    precompressSlice    ( TComPic* pcPic                                     );      ///< precompress slice for multi-loop slice-level QP opt.
-  Void    compressSlice       ( TComPic* pcPic, const Bool bCompressEntireSlice    );      ///< analysis stage of slice
+  Void    compressSlice       ( TComPic* pcPic, const Bool bCompressEntireSlice, const Bool bFastDeltaQP );      ///< analysis stage of slice
   Void    calCostSliceI       ( TComPic* pcPic );
   Void    encodeSlice         ( TComPic* pcPic, TComOutputBitstream* pcSubstreams, UInt &numBinsCoded );
Index: branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1286)
+++ branches/HTM-14.1-update-dev1/source/Lib/TLibEncoder/TEncTop.cpp	(revision 1287)
@@ -174,4 +174,5 @@
   m_cLoopFilter.        destroy();
   m_cRateCtrl.          destroy();
+  m_cSearch.            destroy();
   Int iDepth;
   for ( iDepth = 0; iDepth < m_maxTotalCUDepth+1; iDepth++ )
@@ -953,4 +954,5 @@
       hrd->setCpbSizeValueMinus1( i, j, 0, ( cpbSizeValue - 1 ) );
       hrd->setDuCpbSizeValueMinus1( i, j, 0, ( duCpbSizeValue - 1 ) );
+      hrd->setDuBitRateValueMinus1( i, j, 0, ( duBitRateValue - 1 ) );
       hrd->setCbrFlag( i, j, 0, false );
 
@@ -1323,8 +1325,6 @@
   }
 
-  TComReferencePictureSet *rps=slice->getLocalRPS();
-  (*rps) = *(slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
+  const TComReferencePictureSet *rps = (slice->getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
   slice->setRPS(rps);
-  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
 #if NH_MV
   }
