diff -c -p -r HEVC_HM11.0/source/Lib/TLibCommon/TComRom.cpp HEVC_Patched_1026/source/Lib/TLibCommon/TComRom.cpp
*** HEVC_HM11.0/source/Lib/TLibCommon/TComRom.cpp	2013-04-23 15:08:58.000000000 +0100
--- HEVC_Patched_1026/source/Lib/TLibCommon/TComRom.cpp	2013-08-09 10:34:47.000000000 +0100
*************** UInt g_sigLastScanCG32x32[ 64 ];
*** 342,358 ****
  const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24};
  const UInt g_uiGroupIdx[ 32 ]   = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
  
- // Rice parameters for absolute transform levels
- const UInt g_auiGoRiceRange[5] =
- {
-   7, 14, 26, 46, 78
- };
- 
- const UInt g_auiGoRicePrefixLen[5] =
- {
-   8, 7, 6, 5, 4
- };
- 
  Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight)
  {
    const UInt  uiNumScanPos  = UInt( iWidth * iWidth );
--- 342,347 ----
diff -c -p -r HEVC_HM11.0/source/Lib/TLibCommon/TComRom.h HEVC_Patched_1026/source/Lib/TLibCommon/TComRom.h
*** HEVC_HM11.0/source/Lib/TLibCommon/TComRom.h	2013-01-31 16:52:13.000000000 +0000
--- HEVC_Patched_1026/source/Lib/TLibCommon/TComRom.h	2013-08-09 10:34:47.000000000 +0100
*************** extern       UInt*  g_auiSigLastScan[ 3
*** 119,127 ****
  
  extern const UInt   g_uiGroupIdx[ 32 ];
  extern const UInt   g_uiMinInGroup[ 10 ];
- 
- extern const UInt   g_auiGoRiceRange[5];                  //!< maximum value coded with Rice codes
- extern const UInt   g_auiGoRicePrefixLen[5];              //!< prefix length for each maximum value
    
  extern const UInt   g_sigLastScan8x8[ 3 ][ 4 ];           //!< coefficient group scan order for 8x8 TUs
  extern       UInt   g_sigLastScanCG32x32[ 64 ];
--- 119,124 ----
diff -c -p -r HEVC_HM11.0/source/Lib/TLibCommon/TComTrQuant.cpp HEVC_Patched_1026/source/Lib/TLibCommon/TComTrQuant.cpp
*** HEVC_HM11.0/source/Lib/TLibCommon/TComTrQuant.cpp	2013-06-07 15:36:28.000000000 +0100
--- HEVC_Patched_1026/source/Lib/TLibCommon/TComTrQuant.cpp	2013-08-09 10:34:47.000000000 +0100
*************** Void TComTrQuant::xRateDistOptQuant
*** 1926,1932 ****
              {
                Int64 costUp   = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
                Int64 costDown = rdFactor * (   deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos] 
!               -   ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0 );
                
                if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
                {
--- 1926,1932 ----
              {
                Int64 costUp   = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
                Int64 costDown = rdFactor * (   deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos] 
!               -   ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0);
                
                if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
                {
*************** __inline UInt TComTrQuant::xGetCodedLeve
*** 2145,2151 ****
    for( Int uiAbsLevel  = uiMaxAbsLevel; uiAbsLevel >= uiMinAbsLevel ; uiAbsLevel-- )
    {
      Double dErr         = Double( lLevelDouble  - ( uiAbsLevel << iQBits ) );
!     Double dCurrCost    = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx );
      dCurrCost          += dCurrCostSig;
  
      if( dCurrCost < rd64CodedCost )
--- 2145,2151 ----
    for( Int uiAbsLevel  = uiMaxAbsLevel; uiAbsLevel >= uiMinAbsLevel ; uiAbsLevel-- )
    {
      Double dErr         = Double( lLevelDouble  - ( uiAbsLevel << iQBits ) );
!     Double dCurrCost    = dErr * dErr * dTemp + xGetICost(xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx ));
      dCurrCost          += dCurrCostSig;
  
      if( dCurrCost < rd64CodedCost )
*************** __inline UInt TComTrQuant::xGetCodedLeve
*** 2166,2180 ****
   * \param ui16AbsGoRice Rice parameter for coeff_abs_level_minus3
   * \returns cost of given absolute transform level
   */
! __inline Double TComTrQuant::xGetICRateCost  ( UInt                            uiAbsLevel,
!                                                UShort                          ui16CtxNumOne,
!                                                UShort                          ui16CtxNumAbs,
!                                                UShort                          ui16AbsGoRice
!                                             ,  UInt                            c1Idx,
!                                                UInt                            c2Idx
!                                                ) const
  {
!   Double iRate = xGetIEPRate();
    UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
  
    if ( uiAbsLevel >= baseLevel )
--- 2166,2180 ----
   * \param ui16AbsGoRice Rice parameter for coeff_abs_level_minus3
   * \returns cost of given absolute transform level
   */
! __inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
!                                         UShort                          ui16CtxNumOne,
!                                         UShort                          ui16CtxNumAbs,
!                                         UShort                          ui16AbsGoRice
!                                      ,  UInt                            c1Idx,
!                                         UInt                            c2Idx
!                                         ) const
  {
!   Int iRate = Int(xGetIEPRate());
    UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
  
    if ( uiAbsLevel >= baseLevel )
*************** __inline Double TComTrQuant::xGetICRateC
*** 2218,2285 ****
    }
    else
    {
!     assert (0);
!   }
!   return xGetICost( iRate );
! }
! 
! __inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
!                                        UShort                          ui16CtxNumOne,
!                                        UShort                          ui16CtxNumAbs,
!                                        UShort                          ui16AbsGoRice
!                                      , UInt                            c1Idx,
!                                        UInt                            c2Idx
!                                        ) const
! {
!   Int iRate = 0;
!   UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
! 
!   if ( uiAbsLevel >= baseLevel )
!   {
!     UInt uiSymbol     = uiAbsLevel - baseLevel;
!     UInt uiMaxVlc     = g_auiGoRiceRange[ ui16AbsGoRice ];
!     Bool bExpGolomb   = ( uiSymbol > uiMaxVlc );
! 
!     if( bExpGolomb )
!     {
!       uiAbsLevel  = uiSymbol - uiMaxVlc;
!       Int iEGS    = 1;  for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 );
!       iRate      += iEGS << 15;
!       uiSymbol    = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) );
!     }
! 
!     UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1;
!     UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice;
! 
!     iRate += ui16NumBins << 15;
! 
!     if (c1Idx < C1FLAG_NUMBER)
!     {
!       iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
! 
!       if (c2Idx < C2FLAG_NUMBER)
!       {
!         iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ];
!       }
!     }
!   }
!   else
!   if( uiAbsLevel == 0 )
!   {
!     return 0;
!   }
!   else if( uiAbsLevel == 1 )
!   {
!     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 0 ];
!   }
!   else if( uiAbsLevel == 2 )
!   {
!     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
!     iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 0 ];
!   }
!   else
!   {
!     assert(0);
    }
    return iRate;
  }
--- 2218,2224 ----
    }
    else
    {
!     iRate = 0;
    }
    return iRate;
  }
diff -c -p -r HEVC_HM11.0/source/Lib/TLibCommon/TComTrQuant.h HEVC_Patched_1026/source/Lib/TLibCommon/TComTrQuant.h
*** HEVC_HM11.0/source/Lib/TLibCommon/TComTrQuant.h	2013-08-09 09:53:44.000000000 +0100
--- HEVC_Patched_1026/source/Lib/TLibCommon/TComTrQuant.h	2013-08-09 10:34:47.000000000 +0100
*************** __inline UInt              xGetCodedLeve
*** 271,283 ****
                                               Int                             iQBits,
                                               Double                          dTemp,
                                               Bool                            bLast        ) const;
-   __inline Double xGetICRateCost   ( UInt                            uiAbsLevel,
-                                      UShort                          ui16CtxNumOne,
-                                      UShort                          ui16CtxNumAbs,
-                                      UShort                          ui16AbsGoRice 
-                                    , UInt                            c1Idx,
-                                      UInt                            c2Idx
-                                      ) const;
  __inline Int xGetICRate  ( UInt                            uiAbsLevel,
                             UShort                          ui16CtxNumOne,
                             UShort                          ui16CtxNumAbs,
--- 271,276 ----
