Changeset 595 in SHVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
2 Feb 2014, 06:01:53 (11 years ago)
Author:
seregin
Message:

merge with SHM-5.0-dev branch

Location:
trunk
Files:
43 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/Lib/TLibEncoder/AnnexBwrite.h

    r313 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/NALwrite.cpp

    r588 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/NALwrite.h

    r313 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/SEIwrite.cpp

    r588 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    8787    fprintf( g_hTrace, "=========== Tone Mapping Info SEI message ===========\n");
    8888    break;
     89  case SEI::SOP_DESCRIPTION:
     90    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
     91    break;
     92  case SEI::SCALABLE_NESTING:
     93    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
     94    break;
     95#if SVC_EXTENSION
    8996#if LAYERS_NOT_PRESENT_SEI
    9097  case SEI::LAYERS_NOT_PRESENT:
     
    9299    break;
    93100#endif
    94   case SEI::SOP_DESCRIPTION:
    95     fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
    96     break;
    97101#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    98102  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
     
    105109      break;
    106110#endif
    107   case SEI::SCALABLE_NESTING:
    108     fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    109     break;
     111#endif //SVC_EXTENSION
    110112  default:
    111113    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
     
    155157    xWriteSEIToneMappingInfo(*static_cast<const SEIToneMappingInfo*>(&sei));
    156158    break;
     159  case SEI::SOP_DESCRIPTION:
     160    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
     161    break;
     162  case SEI::SCALABLE_NESTING:
     163    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
     164    break;
     165#if SVC_EXTENSION
    157166#if LAYERS_NOT_PRESENT_SEI
    158167  case SEI::LAYERS_NOT_PRESENT:
     
    160169    break;
    161170#endif
    162   case SEI::SOP_DESCRIPTION:
    163     xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
    164     break;
    165171#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    166172  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
     
    173179     break;
    174180#endif
    175   case SEI::SCALABLE_NESTING:
    176     xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
    177     break;
     181#endif //SVC_EXTENSION
    178182  default:
    179183    assert(!"Unhandled SEI message");
     
    337341  if( !hrd->getSubPicCpbParamsPresentFlag() )
    338342  {
    339     WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
     343    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
     344  }
     345  if( sei.m_rapCpbParamsPresentFlag )
     346  {
     347    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
     348    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
    340349  }
    341350  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
    342351  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
    343   if( sei.m_rapCpbParamsPresentFlag )
    344   {
    345     WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
    346     WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
    347   }
    348352  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    349353  {
     
    546550}
    547551
    548 #if LAYERS_NOT_PRESENT_SEI
    549 Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
    550 {
    551   WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
    552   for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
    553   {
    554     WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
    555   }
    556   xWriteByteAlign();
    557 }
    558 #endif
    559 
    560552Void SEIWriter::xWriteSEISOPDescription(const SEISOPDescription& sei)
    561553{
     
    578570  xWriteByteAlign();
    579571}
     572
     573Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
     574{
     575  WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
     576  WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
     577  if (sei.m_nestingOpFlag)
     578  {
     579    WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
     580    WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
     581    for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
     582    {
     583      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
     584      WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
     585      WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
     586    }
     587  }
     588  else
     589  {
     590    WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
     591    if (!sei.m_allLayersFlag)
     592    {
     593      WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
     594      WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
     595      for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
     596      {
     597        WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
     598      }
     599    }
     600  }
     601 
     602  // byte alignment
     603  while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
     604  {
     605    WRITE_FLAG( 0, "nesting_zero_bit" );
     606  }
     607
     608  // write nested SEI messages
     609  for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
     610  {
     611    writeSEImessage(bs, *(*it), sps);
     612  }
     613}
     614
     615Void SEIWriter::xWriteByteAlign()
     616{
     617  if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
     618  {
     619    WRITE_FLAG( 1, "bit_equal_to_one" );
     620    while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
     621    {
     622      WRITE_FLAG( 0, "bit_equal_to_zero" );
     623    }
     624  }
     625};
     626
     627#if SVC_EXTENSION
     628#if LAYERS_NOT_PRESENT_SEI
     629Void SEIWriter::xWriteSEILayersNotPresent(const SEILayersNotPresent& sei)
     630{
     631  WRITE_UVLC( sei.m_activeVpsId,           "lp_sei_active_vps_id" );
     632  for (UInt i = 0; i < sei.m_vpsMaxLayers; i++)
     633  {
     634    WRITE_FLAG( sei.m_layerNotPresentFlag[i], "layer_not_present_flag"   );
     635  }
     636  xWriteByteAlign();
     637}
     638#endif
    580639
    581640#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     
    634693}
    635694#endif
    636 Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
    637 {
    638   WRITE_FLAG( sei.m_bitStreamSubsetFlag,             "bitstream_subset_flag"         );
    639   WRITE_FLAG( sei.m_nestingOpFlag,                   "nesting_op_flag      "         );
    640   if (sei.m_nestingOpFlag)
    641   {
    642     WRITE_FLAG( sei.m_defaultOpFlag,                 "default_op_flag"               );
    643     WRITE_UVLC( sei.m_nestingNumOpsMinus1,           "nesting_num_ops"               );
    644     for (UInt i = (sei.m_defaultOpFlag ? 1 : 0); i <= sei.m_nestingNumOpsMinus1; i++)
    645     {
    646       WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
    647       WRITE_CODE( sei.m_nestingMaxTemporalIdPlus1[i], 3,  "nesting_max_temporal_id"       );
    648       WRITE_UVLC( sei.m_nestingOpIdx[i],                  "nesting_op_idx"                );
    649     }
    650   }
    651   else
    652   {
    653     WRITE_FLAG( sei.m_allLayersFlag,                      "all_layers_flag"               );
    654     if (!sei.m_allLayersFlag)
    655     {
    656       WRITE_CODE( sei.m_nestingNoOpMaxTemporalIdPlus1, 3, "nesting_no_op_max_temporal_id" );
    657       WRITE_UVLC( sei.m_nestingNumLayersMinus1,           "nesting_num_layers"            );
    658       for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++)
    659       {
    660         WRITE_CODE( sei.m_nestingLayerId[i], 6,           "nesting_layer_id"              );
    661       }
    662     }
    663   }
    664  
    665   // byte alignment
    666   while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
    667   {
    668     WRITE_FLAG( 0, "nesting_zero_bit" );
    669   }
    670 
    671   // write nested SEI messages
    672   for (SEIMessages::const_iterator it = sei.m_nestedSEIs.begin(); it != sei.m_nestedSEIs.end(); it++)
    673   {
    674     writeSEImessage(bs, *(*it), sps);
    675   }
    676 }
    677 
    678 Void SEIWriter::xWriteByteAlign()
    679 {
    680   if( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0)
    681   {
    682     WRITE_FLAG( 1, "bit_equal_to_one" );
    683     while( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
    684     {
    685       WRITE_FLAG( 0, "bit_equal_to_zero" );
    686     }
    687   }
    688 };
     695#endif //SVC_EXTENSION
    689696
    690697//! \}
  • trunk/source/Lib/TLibEncoder/SEIwrite.h

    r588 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    6464  Void xWriteSEIGradualDecodingRefreshInfo(const SEIGradualDecodingRefreshInfo &sei);
    6565  Void xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei);
     66  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
     67  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
     68  Void xWriteByteAlign();
     69#if SVC_EXTENSION
    6670#if LAYERS_NOT_PRESENT_SEI
    6771  Void xWriteSEILayersNotPresent(const SEILayersNotPresent& sei);
    6872#endif
    69   Void xWriteSEISOPDescription(const SEISOPDescription& sei);
    7073#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    7174  Void xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei);
     
    7477  Void xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei);
    7578#endif
    76   Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
    77   Void xWriteByteAlign();
     79#endif //SVC_EXTENSION
    7880};
    7981
  • trunk/source/Lib/TLibEncoder/SyntaxElementWriter.cpp

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/SyntaxElementWriter.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncBinCoder.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    579579  }
    580580  WRITE_FLAG( pcSPS->getTMVPFlagsPresent()  ? 1 : 0,           "sps_temporal_mvp_enable_flag" );
     581
    581582  WRITE_FLAG( pcSPS->getUseStrongIntraSmoothing(),             "sps_strong_intra_smoothing_enable_flag" );
    582583
     
    17331734         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );         
    17341735#if AUXILIARY_PICTURES
    1735          if (pcSlice->getChromaFormatIdc() != CHROMA_400)
    1736          {
    1737 #endif
    1738 #if HM_CLEANUP_SAO
     1736         if (pcSlice->getChromaFormatIdc() != CHROMA_400)         
     1737#endif
    17391738         WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
    1740 #else
    1741          {
    1742            SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1743            WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    1744          }
    1745 #endif
    1746 #if AUXILIARY_PICTURES
    1747          }
    1748 #endif
    17491739      }
    17501740    }   
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    8888  UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
    8989  Void  codeVPS                 ( TComVPS* pcVPS );
    90 #if VPS_EXTNS
    91   Void  codeVPSExtension        ( TComVPS* pcVPS );
    92 #endif
    93 
    94 #if VPS_VUI
    95   Void codeVPSVUI               (TComVPS *vps);
    96 #endif
    97 #if REPN_FORMAT_IN_VPS
    98   Void  codeRepFormat           ( RepFormat *repFormat );
    99 #endif
    100 #if VPS_DPB_SIZE_TABLE
    101   Void  codeVpsDpbSizeTable      (TComVPS *vps);
    102 #endif
    10390  Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
    10491  Void  codeSPS                 ( TComSPS* pcSPS );
    105 #if SPS_EXTENSION
    106   Void codeSPSExtension         ( TComSPS* pcSPS );
    107 #endif
    10892  Void  codePPS                 ( TComPPS* pcPPS );
    10993  Void  codeSliceHeader         ( TComSlice* pcSlice );
     
    116100 
    117101  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
    118 #if HM_CLEANUP_SAO
    119102  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
    120 #else
    121   Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
    122   Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
    123   Void codeSaoMerge  ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    124   Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    125   Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
    126 #endif
    127103  Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
    128104  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    165141  Void codeDFSvlc       ( Int   iCode, const Char *pSymbolName );
    166142
     143#if SPS_EXTENSION
     144  Void codeSPSExtension         ( TComSPS* pcSPS );
     145#if VPS_EXTNS
     146  Void  codeVPSExtension        ( TComVPS* pcVPS );
     147#endif
     148#if VPS_VUI
     149  Void codeVPSVUI               (TComVPS *vps);
     150#endif
     151#if REPN_FORMAT_IN_VPS
     152  Void  codeRepFormat           ( RepFormat *repFormat );
     153#endif
     154#if VPS_DPB_SIZE_TABLE
     155  Void  codeVpsDpbSizeTable      (TComVPS *vps);
     156#endif
     157#endif //SVC_EXTENSION
     158
    167159};
    168160
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    9191
    9292std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry);     //input
    93 
    94 #if REPN_FORMAT_IN_VPS
    95 struct RepFormatCfg
    96 {
    97   Int   m_chromaFormatIdc;
    98   Bool  m_separateColourPlaneFlag;
    99   Int   m_picWidthInLumaSamples;
    100   Int   m_picHeightInLumaSamples;
    101   Int   m_bitDepthLuma;
    102   Int   m_bitDepthChroma;
    103   RepFormatCfg()
    104     : m_chromaFormatIdc         (CHROMA_420)
    105     , m_separateColourPlaneFlag (0)
    106     , m_picWidthInLumaSamples   (352)
    107     , m_picHeightInLumaSamples  (288)
    108     , m_bitDepthLuma            (8)
    109     , m_bitDepthChroma          (8)
    110   {}
    111 };
    112 std::istringstream &operator>>(std::istringstream &in, RepFormatCfg &repFormatCfg);
    113 #endif
    114 
    11593//! \ingroup TLibEncoder
    11694//! \{
     
    162140  Int       m_maxTempLayer;                      ///< Max temporal layer
    163141  Bool m_useAMP;
    164 #if VPS_EXTN_DIRECT_REF_LAYERS
    165   Int       m_numDirectRefLayers;
    166   Int       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
    167 
    168   Int       m_numActiveRefLayers;
    169   Int       m_predLayerId[MAX_VPS_LAYER_ID_PLUS1];
    170   Int       m_numSamplePredRefLayers;
    171   Int       m_samplePredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
    172   Int       m_numMotionPredRefLayers;
    173   Int       m_motionPredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
    174   Bool      m_samplePredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
    175   Bool      m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
    176 #endif
    177 #if N0120_MAX_TID_REF_CFG
    178   Int       m_maxTidIlRefPicsPlus1;
    179 #endif
    180142  //======= Transform =============
    181143  UInt      m_uiQuadtreeTULog2MaxSize;
     
    194156  Int       m_maxNumOffsetsPerPic;
    195157  Bool      m_saoLcuBoundary;
    196 #if !HM_CLEANUP_SAO
    197   Bool      m_saoLcuBasedOptimization;
    198 #endif
    199   //====== Lossless ========
    200   Bool      m_useLossless;
    201158  //====== Motion search ========
    202159  Int       m_iFastSearch;                      //  0:Full search  1:Diamond  2:PMVFAST
     
    210167  Int       m_chromaCbQpOffset;                 //  Chroma Cb QP Offset (0:default)
    211168  Int       m_chromaCrQpOffset;                 //  Chroma Cr Qp Offset (0:default)
    212 #if AUXILIARY_PICTURES
    213   ChromaFormat m_chromaFormatIDC;
    214 #endif
    215169
    216170#if ADAPTIVE_QP_SELECTION
     
    222176 
    223177  //====== Tool list ========
    224   Bool      m_bUseSBACRD;
    225178  Bool      m_bUseASR;
    226179  Bool      m_bUseHADME;
     
    233186  Bool      m_bUseCbfFastMode;
    234187  Bool      m_useEarlySkipDetection;
    235 #if FAST_INTRA_SHVC
    236   Bool      m_useFastIntraScalable;
    237 #endif
    238188  Bool      m_useTransformSkip;
    239189  Bool      m_useTransformSkipFast;
     
    305255  Int       m_gradualDecodingRefreshInfoEnabled;
    306256  Int       m_decodingUnitInfoSEIEnabled;
    307 #if LAYERS_NOT_PRESENT_SEI
    308   Int       m_layersNotPresentSEIEnabled;
    309 #endif
    310257  Int       m_SOPDescriptionSEIEnabled;
    311258  Int       m_scalableNestingSEIEnabled;
    312 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    313   Bool      m_interLayerConstrainedTileSetsSEIEnabled;
    314   UInt      m_ilNumSetsInMessage;
    315   Bool      m_skippedTileSetPresentFlag;
    316   UInt      m_topLeftTileIndex[1024];
    317   UInt      m_bottomRightTileIndex[1024];
    318   UInt      m_ilcIdc[1024];
    319 #endif
    320259  //====== Weighted Prediction ========
    321260  Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
     
    335274  Bool      m_RCForceIntraQP;
    336275  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    337   Bool      m_CUTransquantBypassFlagValue;                    ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.
     276  Bool      m_CUTransquantBypassFlagForce;                    ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true.
    338277#if SVC_EXTENSION
    339   static TComVPS                    m_cVPS;
     278  static TComVPS             m_cVPS;
    340279#else
    341280  TComVPS                    m_cVPS;
     
    391330  Bool      m_crossLayerBLAFlag;
    392331#endif
    393 #endif
     332#if VPS_EXTN_DIRECT_REF_LAYERS
     333  Int       m_numDirectRefLayers;
     334  Int       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
     335
     336  Int       m_numActiveRefLayers;
     337  Int       m_predLayerId[MAX_VPS_LAYER_ID_PLUS1];
     338  Int       m_numSamplePredRefLayers;
     339  Int       m_samplePredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
     340  Int       m_numMotionPredRefLayers;
     341  Int       m_motionPredRefLayerId[MAX_VPS_LAYER_ID_PLUS1];
     342  Bool      m_samplePredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
     343  Bool      m_motionPredEnabledFlag[MAX_VPS_LAYER_ID_PLUS1];
     344#endif
     345#if N0120_MAX_TID_REF_CFG
     346  Int       m_maxTidIlRefPicsPlus1;
     347#endif
     348#if AUXILIARY_PICTURES
     349  ChromaFormat m_chromaFormatIDC;
     350#endif
     351#if FAST_INTRA_SHVC
     352  Bool      m_useFastIntraScalable;
     353#endif
     354#if LAYERS_NOT_PRESENT_SEI
     355  Int       m_layersNotPresentSEIEnabled;
     356#endif
     357#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     358  Bool      m_interLayerConstrainedTileSetsSEIEnabled;
     359  UInt      m_ilNumSetsInMessage;
     360  Bool      m_skippedTileSetPresentFlag;
     361  UInt      m_topLeftTileIndex[1024];
     362  UInt      m_bottomRightTileIndex[1024];
     363  UInt      m_ilcIdc[1024];
     364#endif
     365#endif //SVC_EXTENSION
    394366
    395367public:
     
    437409  Bool      getMaxTempLayer                 ()                              { return m_maxTempLayer;              }
    438410  Void      setMaxTempLayer                 ( Int maxTempLayer )            { m_maxTempLayer = maxTempLayer;      }
    439 #if VPS_EXTN_DIRECT_REF_LAYERS
    440   Int       getNumDirectRefLayers           ()                              { return m_numDirectRefLayers;      }
    441   Void      setNumDirectRefLayers           (Int num)                       { m_numDirectRefLayers = num;       }
    442 
    443   Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
    444   Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
    445 
    446   Int       getNumActiveRefLayers           ()                              { return m_numActiveRefLayers;      }
    447   Void      setNumActiveRefLayers           (Int num)                       { m_numActiveRefLayers = num;       }
    448 
    449   Int       getPredLayerId                  (Int i)                         { return m_predLayerId[i];          }
    450   Void      setPredLayerId                  (Int i, Int refLayerId)         { m_predLayerId[i] = refLayerId;    }
    451 
    452   Int       getNumSamplePredRefLayers       ()                              { return m_numSamplePredRefLayers;  }
    453   Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
    454 
    455   Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
    456   Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
    457 
    458   Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
    459   Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
    460 
    461   Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
    462   Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
    463 
    464   Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
    465   Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
    466 
    467   Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
    468   Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
    469 #endif
    470 #if N0120_MAX_TID_REF_CFG
    471   Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
    472   Void      setMaxTidIlRefPicsPlus1         (Int num)                       { m_maxTidIlRefPicsPlus1 = num;  }
    473 #endif
    474411  //======== Transform =============
    475412  Void      setQuadtreeTULog2MaxSize        ( UInt  u )      { m_uiQuadtreeTULog2MaxSize = u; }
     
    508445  Void      setQPAdaptationRange            ( Int   i )      { m_iQPAdaptationRange = i; }
    509446 
    510   //====== Lossless ========
    511   Void      setUseLossless                  (Bool    b  )        { m_useLossless = b;  }
    512447  //====== Sequence ========
    513448  Int       getFrameRate                    ()      { return  m_iFrameRate; }
     
    552487  Bool      getUseAdaptiveQP                ()      { return  m_bUseAdaptiveQP; }
    553488  Int       getQPAdaptationRange            ()      { return  m_iQPAdaptationRange; }
    554   //====== Lossless ========
    555   Bool      getUseLossless                  ()      { return  m_useLossless;  }
    556489 
    557490  //==== Tool list ========
    558   Void      setUseSBACRD                    ( Bool  b )     { m_bUseSBACRD  = b; }
    559491  Void      setUseASR                       ( Bool  b )     { m_bUseASR     = b; }
    560492  Void      setUseHADME                     ( Bool  b )     { m_bUseHADME   = b; }
     
    567499  Void      setUseCbfFastMode            ( Bool  b )     { m_bUseCbfFastMode = b; }
    568500  Void      setUseEarlySkipDetection        ( Bool  b )     { m_useEarlySkipDetection = b; }
    569 #if FAST_INTRA_SHVC
    570   Void      setUseFastIntraScalable         ( Bool  b )     { m_useFastIntraScalable = b; }
    571 #endif
    572501  Void      setUseConstrainedIntraPred      ( Bool  b )     { m_bUseConstrainedIntraPred = b; }
    573502  Void      setPCMInputBitDepthFlag         ( Bool  b )     { m_bPCMInputBitDepthFlag = b; }
     
    578507  Void      setdQPs                         ( Int*  p )     { m_aidQP       = p; }
    579508  Void      setDeltaQpRD                    ( UInt  u )     {m_uiDeltaQpRD  = u; }
    580   Bool      getUseSBACRD                    ()      { return m_bUseSBACRD;  }
    581509  Bool      getUseASR                       ()      { return m_bUseASR;     }
    582510  Bool      getUseHADME                     ()      { return m_bUseHADME;   }
     
    589517  Bool      getUseCbfFastMode           ()      { return m_bUseCbfFastMode; }
    590518  Bool      getUseEarlySkipDetection        ()      { return m_useEarlySkipDetection; }
    591 #if FAST_INTRA_SHVC
    592   Bool      getUseFastIntraScalable         ()      { return m_useFastIntraScalable; }
    593 #endif
    594519  Bool      getUseConstrainedIntraPred      ()      { return m_bUseConstrainedIntraPred; }
    595520  Bool      getPCMInputBitDepthFlag         ()      { return m_bPCMInputBitDepthFlag;   }
     
    625550  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
    626551  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
    627 #if !HM_CLEANUP_SAO
    628   Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
    629   Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
    630 #endif
    631552  Void  setLFCrossTileBoundaryFlag               ( Bool   val  )       { m_loopFilterAcrossTilesEnabledFlag = val; }
    632553  Bool  getLFCrossTileBoundaryFlag               ()                    { return m_loopFilterAcrossTilesEnabledFlag;   }
     
    748669  Void  setDecodingUnitInfoSEIEnabled(Int b)                { m_decodingUnitInfoSEIEnabled = b;    }
    749670  Int   getDecodingUnitInfoSEIEnabled()                     { return m_decodingUnitInfoSEIEnabled; }
    750 #if LAYERS_NOT_PRESENT_SEI
    751   Void  setLayersNotPresentSEIEnabled(Int b)             { m_layersNotPresentSEIEnabled = b; }
    752   Int   getLayersNotPresentSEIEnabled()                  { return m_layersNotPresentSEIEnabled; }
    753 #endif
    754671  Void  setSOPDescriptionSEIEnabled(Int b)                { m_SOPDescriptionSEIEnabled = b; }
    755672  Int   getSOPDescriptionSEIEnabled()                     { return m_SOPDescriptionSEIEnabled; }
    756673  Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
    757674  Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
    758 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    759   Void  setInterLayerConstrainedTileSetsSEIEnabled(Bool b) { m_interLayerConstrainedTileSetsSEIEnabled = b; }
    760   Bool  getInterLayerConstrainedTileSetsSEIEnabled()       { return m_interLayerConstrainedTileSetsSEIEnabled; }
    761   Void  setIlNumSetsInMessage(UInt b)                      { m_ilNumSetsInMessage = b; }
    762   Int   getIlNumSetsInMessage()                            { return m_ilNumSetsInMessage; }
    763   Void  setSkippedTileSetPresentFlag(Bool b)               { m_skippedTileSetPresentFlag = b; }
    764   Bool  getSkippedTileSetPresentFlag()                     { return m_skippedTileSetPresentFlag; }
    765   Void  setTopLeftTileIndex(UInt *b)
    766   {
    767     for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
    768     {
    769       m_topLeftTileIndex[i] = b[i];
    770     }
    771   }
    772   UInt  getTopLeftTileIndex(UInt b)                        { return m_topLeftTileIndex[b]; }
    773   Void  setBottomRightTileIndex(UInt *b)
    774   {
    775     for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
    776     {
    777       m_bottomRightTileIndex[i] = b[i];
    778     }
    779   }
    780   UInt  getBottomRightTileIndex(UInt b)                    { return m_bottomRightTileIndex[b]; }
    781   Void  setIlcIdc(UInt *b)
    782   {
    783     for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
    784     {
    785       m_ilcIdc[i] = b[i];
    786     }
    787   }
    788   UInt  getIlcIdc(UInt b)                                  { return m_ilcIdc[b]; }
    789 #endif
    790675  Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
    791676  Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
     
    820705  Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
    821706  Void      setTransquantBypassEnableFlag(Bool flag)  { m_TransquantBypassEnableFlag = flag; }
    822   Bool      getCUTransquantBypassFlagValue()          { return m_CUTransquantBypassFlagValue; }
    823   Void      setCUTransquantBypassFlagValue(Bool flag) { m_CUTransquantBypassFlagValue = flag; }
     707  Bool      getCUTransquantBypassFlagForceValue()          { return m_CUTransquantBypassFlagForce; }
     708  Void      setCUTransquantBypassFlagForceValue(Bool flag) { m_CUTransquantBypassFlagForce = flag; }
    824709  Void setVPS(TComVPS *p) { m_cVPS = *p; }
    825710  TComVPS *getVPS() { return &m_cVPS; }
     
    934819  Void      setCrossLayerBLAFlag(Bool b) { m_crossLayerBLAFlag = b;    }
    935820#endif
     821#if FAST_INTRA_SHVC
     822  Bool      getUseFastIntraScalable         ()      { return m_useFastIntraScalable; }
     823  Void      setUseFastIntraScalable         ( Bool  b )     { m_useFastIntraScalable = b; }
     824#endif
     825#if VPS_EXTN_DIRECT_REF_LAYERS
     826  Int       getNumDirectRefLayers           ()                              { return m_numDirectRefLayers;      }
     827  Void      setNumDirectRefLayers           (Int num)                       { m_numDirectRefLayers = num;       }
     828
     829  Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
     830  Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
     831
     832  Int       getNumActiveRefLayers           ()                              { return m_numActiveRefLayers;      }
     833  Void      setNumActiveRefLayers           (Int num)                       { m_numActiveRefLayers = num;       }
     834
     835  Int       getPredLayerId                  (Int i)                         { return m_predLayerId[i];          }
     836  Void      setPredLayerId                  (Int i, Int refLayerId)         { m_predLayerId[i] = refLayerId;    }
     837
     838  Int       getNumSamplePredRefLayers       ()                              { return m_numSamplePredRefLayers;  }
     839  Void      setNumSamplePredRefLayers       (Int num)                       { m_numSamplePredRefLayers = num;   }
     840
     841  Int       getSamplePredRefLayerId         (Int i)                         { return m_samplePredRefLayerId[i];       }
     842  Void      setSamplePredRefLayerId         (Int i, Int refLayerId)         { m_samplePredRefLayerId[i] = refLayerId; }
     843
     844  Int       getNumMotionPredRefLayers       ()                              { return m_numMotionPredRefLayers;  }
     845  Void      setNumMotionPredRefLayers       (Int num)                       { m_numMotionPredRefLayers = num;   }
     846
     847  Int       getMotionPredRefLayerId         (Int i)                         { return m_motionPredRefLayerId[i];       }
     848  Void      setMotionPredRefLayerId         (Int i, Int refLayerId)         { m_motionPredRefLayerId[i] = refLayerId; }
     849
     850  Bool      getSamplePredEnabledFlag        (Int i)                         { return m_samplePredEnabledFlag[i];  }
     851  Void      setSamplePredEnabledFlag        (Int i,Bool flag)               { m_samplePredEnabledFlag[i] = flag;  }
     852
     853  Bool      getMotionPredEnabledFlag        (Int i)                         { return m_motionPredEnabledFlag[i];  }
     854  Void      setMotionPredEnabledFlag        (Int i,Bool flag)               { m_motionPredEnabledFlag[i] = flag;  }
     855#endif
     856#if N0120_MAX_TID_REF_CFG
     857  Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
     858  Void      setMaxTidIlRefPicsPlus1         (Int num)                       { m_maxTidIlRefPicsPlus1 = num;  }
     859#endif
     860#if LAYERS_NOT_PRESENT_SEI
     861  Void  setLayersNotPresentSEIEnabled(Int b)             { m_layersNotPresentSEIEnabled = b; }
     862  Int   getLayersNotPresentSEIEnabled()                  { return m_layersNotPresentSEIEnabled; }
     863#endif
     864#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     865  Void  setInterLayerConstrainedTileSetsSEIEnabled(Bool b) { m_interLayerConstrainedTileSetsSEIEnabled = b; }
     866  Bool  getInterLayerConstrainedTileSetsSEIEnabled()       { return m_interLayerConstrainedTileSetsSEIEnabled; }
     867  Void  setIlNumSetsInMessage(UInt b)                      { m_ilNumSetsInMessage = b; }
     868  Int   getIlNumSetsInMessage()                            { return m_ilNumSetsInMessage; }
     869  Void  setSkippedTileSetPresentFlag(Bool b)               { m_skippedTileSetPresentFlag = b; }
     870  Bool  getSkippedTileSetPresentFlag()                     { return m_skippedTileSetPresentFlag; }
     871  Void  setTopLeftTileIndex(UInt *b)
     872  {
     873    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     874    {
     875      m_topLeftTileIndex[i] = b[i];
     876    }
     877  }
     878  UInt  getTopLeftTileIndex(UInt b)                        { return m_topLeftTileIndex[b]; }
     879  Void  setBottomRightTileIndex(UInt *b)
     880  {
     881    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     882    {
     883      m_bottomRightTileIndex[i] = b[i];
     884    }
     885  }
     886  UInt  getBottomRightTileIndex(UInt b)                    { return m_bottomRightTileIndex[b]; }
     887  Void  setIlcIdc(UInt *b)
     888  {
     889    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     890    {
     891      m_ilcIdc[i] = b[i];
     892    }
     893  }
     894  UInt  getIlcIdc(UInt b)                                  { return m_ilcIdc[b]; }
     895#endif
    936896#endif
    937897};
    938898
     899#if SVC_EXTENSION
     900#if REPN_FORMAT_IN_VPS
     901struct RepFormatCfg
     902{
     903  Int   m_chromaFormatIdc;
     904  Bool  m_separateColourPlaneFlag;
     905  Int   m_picWidthInLumaSamples;
     906  Int   m_picHeightInLumaSamples;
     907  Int   m_bitDepthLuma;
     908  Int   m_bitDepthChroma;
     909  RepFormatCfg()
     910    : m_chromaFormatIdc         (CHROMA_420)
     911    , m_separateColourPlaneFlag (0)
     912    , m_picWidthInLumaSamples   (352)
     913    , m_picHeightInLumaSamples  (288)
     914    , m_bitDepthLuma            (8)
     915    , m_bitDepthChroma          (8)
     916  {}
     917};
     918std::istringstream &operator>>(std::istringstream &in, RepFormatCfg &repFormatCfg);
     919#endif
     920#endif //SVC_EXTENSION
     921
    939922//! \}
    940923
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    223223  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
    224224 
    225   m_bUseSBACRD        = pcEncTop->getUseSBACRD();
    226225  m_pcRateCtrl        = pcEncTop->getRateCtrl();
    227226}
     
    394393  Int iMaxQP;
    395394  Bool isAddLowestQP = false;
    396 #if REPN_FORMAT_IN_VPS
    397   Int lowestQP = -rpcTempCU->getSlice()->getQpBDOffsetY();
    398 #else
    399   Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
    400 #endif
    401395
    402396  if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     
    409403    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    410404    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
    411 #endif
    412     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    413     {
    414       isAddLowestQP = true;
    415       iMinQP = iMinQP - 1;
    416     }
     405#endif   
    417406  }
    418407  else
     
    426415    iMinQP = m_pcRateCtrl->getRCQP();
    427416    iMaxQP = m_pcRateCtrl->getRCQP();
     417  }
     418
     419  // transquant-bypass (TQB) processing loop variable initialisation ---
     420
     421  const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels.
     422
     423  if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) )
     424  {
     425    isAddLowestQP = true; // mark that the first iteration is to cost TQB mode.
     426    iMinQP = iMinQP - 1;  // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
     427    if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
     428    {
     429      iMaxQP = iMinQP;
     430    }
    428431  }
    429432
     
    443446    if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange())
    444447    {
    445       rpcTempCU->initEstData( uiDepth, iBaseQP );
     448      Int iQP = iBaseQP;
     449      const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     450
     451      if( bIsLosslessMode )
     452      {
     453        iQP = lowestQP;
     454      }
     455
     456      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    446457     
    447458      xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true );
     
    466477    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    467478    {
    468       if (isAddLowestQP && (iQP == iMinQP))
     479      const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     480
     481      if (bIsLosslessMode)
    469482      {
    470483        iQP = lowestQP;
    471484      }
    472485
    473       rpcTempCU->initEstData( uiDepth, iQP );
     486      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    474487
    475488      // do inter modes, SKIP and 2Nx2N
     
    483496        if(m_pcEncCfg->getUseEarlySkipDetection())
    484497        {
    485           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
     498          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
     499          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
    486500        }
    487501        // SKIP
    488502        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    489         rpcTempCU->initEstData( uiDepth, iQP );
     503        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    490504       
    491505#if (ENCODER_FAST_MODE == 2)
     
    496510        {
    497511          // 2Nx2N, NxN
    498           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
     512          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
     513          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    499514          if(m_pcEncCfg->getUseCbfFastMode())
    500515          {
     
    507522      }
    508523
    509       if (isAddLowestQP && (iQP == lowestQP))
     524      if (bIsLosslessMode)
    510525      {
    511526        iQP = iMinQP;
     
    517532      for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    518533      {
    519         if (isAddLowestQP && (iQP == iMinQP))
     534        const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     535
     536        if (bIsLosslessMode)
    520537        {
    521538          iQP = lowestQP;
    522539        }
    523         rpcTempCU->initEstData( uiDepth, iQP );
     540        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    524541
    525542        // do inter modes, NxN, 2NxN, and Nx2N
     
    536553            {
    537554              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    538               rpcTempCU->initEstData( uiDepth, iQP );
     555              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    539556            }
    540557          }
     
    544561          {
    545562            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N  );
    546             rpcTempCU->initEstData( uiDepth, iQP );
     563            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    547564            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_Nx2N )
    548565            {
     
    553570          {
    554571            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
    555             rpcTempCU->initEstData( uiDepth, iQP );
     572            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    556573            if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxN)
    557574            {
     
    581598              {
    582599                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
    583                 rpcTempCU->initEstData( uiDepth, iQP );
     600                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    584601                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
    585602                {
     
    590607              {
    591608                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    592                 rpcTempCU->initEstData( uiDepth, iQP );
     609                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    593610                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
    594611                {
     
    603620              {
    604621                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
    605                 rpcTempCU->initEstData( uiDepth, iQP );
     622                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    606623                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU )
    607624                {
     
    612629              {
    613630                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
    614                 rpcTempCU->initEstData( uiDepth, iQP );
     631                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    615632                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD )
    616633                {
     
    627644              {
    628645                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    629                 rpcTempCU->initEstData( uiDepth, iQP );
     646                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    630647                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
    631648                {
     
    636653              {
    637654                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
    638                 rpcTempCU->initEstData( uiDepth, iQP );
     655                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    639656              }
    640657            }
     
    645662              {
    646663                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
    647                 rpcTempCU->initEstData( uiDepth, iQP );
     664                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    648665                if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )
    649666                {
     
    654671              {
    655672                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
    656                 rpcTempCU->initEstData( uiDepth, iQP );
     673                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    657674              }
    658675            }
     
    661678#else
    662679            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
    663             rpcTempCU->initEstData( uiDepth, iQP );
     680            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    664681            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    665             rpcTempCU->initEstData( uiDepth, iQP );
     682            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    666683            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    667             rpcTempCU->initEstData( uiDepth, iQP );
     684            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    668685
    669686            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
    670             rpcTempCU->initEstData( uiDepth, iQP );
     687            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    671688
    672689#endif
     
    691708          {
    692709            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
    693             rpcTempCU->initEstData( uiDepth, iQP );
     710          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    694711            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    695712            {
     
    697714              {
    698715                xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
    699                 rpcTempCU->initEstData( uiDepth, iQP );
     716              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    700717              }
    701718            }
     
    712729          {
    713730            xCheckIntraPCM (rpcBestCU, rpcTempCU);
    714             rpcTempCU->initEstData( uiDepth, iQP );
     731            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    715732          }
    716733        }
     
    725742        { 
    726743           xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer));
    727            rpcTempCU->initEstData( uiDepth, iQP );
     744           rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    728745        }
    729746      }
    730747#endif
    731748
    732         if (isAddLowestQP && (iQP == lowestQP))
     749        if (bIsLosslessMode)
    733750        {
    734751          iQP = iMinQP;
     
    740757    m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
    741758    rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    742     if(m_pcEncCfg->getUseSBACRD())
    743     {
    744759      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    745     }
    746760    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    747761
     
    778792    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    779793    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
    780 #endif
    781     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    782     {
    783       isAddLowestQP = true;
    784       iMinQP = iMinQP - 1;     
    785     }
     794#endif   
    786795  }
    787796  else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     
    810819    iMaxQP = m_pcRateCtrl->getRCQP();
    811820  }
     821
     822  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
     823    {
     824    iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here.
     825    }
     826
    812827  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    813828  {
    814     if (isAddLowestQP && (iQP == iMinQP))
    815     {
    816       iQP = lowestQP;
    817     }
    818     rpcTempCU->initEstData( uiDepth, iQP );
     829    const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
     830    rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    819831
    820832    // further split
     
    837849#endif
    838850        {
    839           if( m_bUseSBACRD )
     851          if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    840852          {
    841             if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    842             {
    843               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    844             }
    845             else
    846             {
    847               m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    848             }
     853            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     854          }
     855          else
     856          {
     857            m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    849858          }
    850859
     
    878887
    879888        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    880         if(m_pcEncCfg->getUseSBACRD())
    881         {
    882           rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    883         }
     889        rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    884890      }
    885891      rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    913919          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
    914920          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    915           if(m_pcEncCfg->getUseSBACRD())
    916           {
    917             rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    918           }
     921          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    919922          rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    920923#endif
     
    930933      }
    931934
    932       if( m_bUseSBACRD )
    933       {
    934         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    935       }
     935      m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     936
    936937      Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
    937938                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
     
    944945      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
    945946    }                                                                                  // with sub partitioned prediction.
    946     if (isAddLowestQP && (iQP == lowestQP))
    947     {
    948       iQP = iMinQP;
    949     }
    950947  }
    951948
     
    13341331  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS];
    13351332  Int numValidMergeCand = 0;
     1333  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
    13361334
    13371335  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
     
    13411339  UChar uhDepth = rpcTempCU->getDepth( 0 );
    13421340  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    1343   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
    13441341  rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    13451342
     
    13851382          // set MC parameters
    13861383          rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
    1387           rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(),     0, uhDepth );
     1384          rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag,     0, uhDepth );
    13881385          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    13891386          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
     
    14151412          xCheckDQP( rpcTempCU );
    14161413          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    1417           rpcTempCU->initEstData( uhDepth, orgQP );
     1414          rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    14181415         
    14191416          if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
     
    14781475  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
    14791476  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    1480   rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(),      0, uhDepth );
    14811477 
    14821478#if AMP_MRG
     
    15091505  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
    15101506  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    1511   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
    15121507 
    15131508  Bool bSeparateLumaChroma = true; // choose estimation mode
     
    15391534  setdQPFlag( bCodeDQP );
    15401535 
    1541   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     1536  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    15421537 
    15431538  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    1544   if(m_pcEncCfg->getUseSBACRD())
    1545   {
    1546     rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1547   }
     1539  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    15481540  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    15491541 
     
    15701562  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    15711563  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
    1572   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
    15731564
    15741565  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
    15751566
    1576   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     1567  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    15771568
    15781569  m_pcEntropyCoder->resetBits();
     
    15861577  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
    15871578
    1588   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     1579  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    15891580
    15901581  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    1591   if(m_pcEncCfg->getUseSBACRD())
    1592   {
    1593     rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1594   }
     1582  rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    15951583  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    15961584
     
    16271615    pcCU  = NULL;
    16281616
    1629     if( m_bUseSBACRD )  // store temp best CI for next CU coding
    1630       m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
     1617    // store temp best CI for next CU coding
     1618    m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
    16311619  }
    16321620}
     
    16441632      m_pcEntropyCoder->encodeQP( pcCU, 0, false );
    16451633      pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    1646       if(m_pcEncCfg->getUseSBACRD())
    1647       {
    1648         pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1649       }
     1634      pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    16501635      pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() );
    16511636#endif
     
    17951780}
    17961781
     1782/** Collect ARL statistics from one LCU
     1783 * \param pcCU
     1784 */
     1785Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU )
     1786{
     1787  Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to datatype and quantization output
     1788  UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output
     1789
     1790  TCoeff* pCoeffY = rpcCU->getCoeffY();
     1791  Int* pArlCoeffY = rpcCU->getArlCoeffY();
     1792
     1793  UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
     1794  UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
     1795
     1796  memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
     1797  memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
     1798
     1799  // Collect stats to cSum[][] and numSamples[][]
     1800  for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ )
     1801  {
     1802    UInt uiTrIdx = rpcCU->getTransformIdx(i);
     1803
     1804    if(rpcCU->getPredictionMode(i) == MODE_INTER)
     1805    if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) )
     1806    {
     1807      xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
     1808    }//Note that only InterY is processed. QP rounding is based on InterY data only.
     1809   
     1810    pCoeffY  += uiMinNumCoeffInCU;
     1811    pArlCoeffY  += uiMinNumCoeffInCU;
     1812  }
     1813
     1814  for(Int u=1; u<LEVEL_RANGE;u++)
     1815  {
     1816    m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
     1817    m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
     1818  }
     1819  m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
     1820  m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
     1821}
     1822#endif
     1823
     1824#if SVC_EXTENSION
    17971825#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    17981826Bool TEncCu::xCheckTileSetConstraint( TComDataCU*& rpcCU )
     
    18611889#endif
    18621890
    1863 /** Collect ARL statistics from one LCU
    1864  * \param pcCU
    1865  */
    1866 Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU )
    1867 {
    1868   Double cSum[ LEVEL_RANGE + 1 ];     //: the sum of DCT coefficients corresponding to datatype and quantization output
    1869   UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output
    1870 
    1871   TCoeff* pCoeffY = rpcCU->getCoeffY();
    1872   Int* pArlCoeffY = rpcCU->getArlCoeffY();
    1873 
    1874   UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth;
    1875   UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
    1876 
    1877   memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) );
    1878   memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) );
    1879 
    1880   // Collect stats to cSum[][] and numSamples[][]
    1881   for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ )
    1882   {
    1883     UInt uiTrIdx = rpcCU->getTransformIdx(i);
    1884 
    1885     if(rpcCU->getPredictionMode(i) == MODE_INTER)
    1886     if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) )
    1887     {
    1888       xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
    1889     }//Note that only InterY is processed. QP rounding is based on InterY data only.
    1890    
    1891     pCoeffY  += uiMinNumCoeffInCU;
    1892     pArlCoeffY  += uiMinNumCoeffInCU;
    1893   }
    1894 
    1895   for(Int u=1; u<LEVEL_RANGE;u++)
    1896   {
    1897     m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
    1898     m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
    1899   }
    1900   m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ;
    1901   m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ;
    1902 }
    1903 #endif
    1904 
    19051891#if (ENCODER_FAST_MODE)
    19061892Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId)
     
    19131899  rpcTempCU->setPartSizeSubParts  ( SIZE_2Nx2N,  0, uhDepth );  //2Nx2N
    19141900  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    1915   rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
     1901  rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagForceValue(), 0, uhDepth );
    19161902  Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId );
    19171903  if(!exitILR)
     
    19261912}
    19271913#endif
     1914#endif //SVC_EXTENSION
    19281915//! \}
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    8989  TComRdCost*             m_pcRdCost;
    9090 
    91 #if SVC_EXTENSION
    92   TEncTop**               m_ppcTEncTop;
    93 #endif
    94  
    9591  TEncEntropy*            m_pcEntropyCoder;
    9692  TEncCavlc*              m_pcCavlcCoder;
     
    10197  TEncSbac***             m_pppcRDSbacCoder;
    10298  TEncSbac*               m_pcRDGoOnSbacCoder;
    103   Bool                    m_bUseSBACRD;
    10499  TEncRateCtrl*           m_pcRateCtrl;
    105100
     101#if SVC_EXTENSION
     102  TEncTop**               m_ppcTEncTop;
    106103#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    107104  Bool                    m_disableILP;
    108105#endif
     106#endif //SVC_EXTENSION
    109107public:
    110108  /// copy parameters from encoder class
     
    148146#endif
    149147  Void  xCheckRDCostIntra   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize  );
    150 #if ENCODER_FAST_MODE
    151   Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId);
    152 #endif
    153148  Void  xCheckDQP           ( TComDataCU*  pcCU );
    154149 
     
    167162#endif
    168163
    169 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    170   Bool xCheckTileSetConstraint( TComDataCU*& rpcCU );
    171   Void xVerifyTileSetConstraint( TComDataCU*& rpcCU );
    172 #endif
    173 
    174164#if AMP_ENC_SPEEDUP
    175165#if AMP_MRG
     
    180170#endif
    181171
     172  Void  xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv );
     173
    182174#if SVC_EXTENSION
    183175  TEncTop*   getLayerEnc(UInt LayerId)  {return m_ppcTEncTop[LayerId]; }
    184 #endif
    185 
    186   Void  xFillPCMBuffer     ( TComDataCU*& pCU, TComYuv* pOrgYuv );
     176#if ENCODER_FAST_MODE
     177  Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId);
     178#endif
     179#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     180  Bool xCheckTileSetConstraint( TComDataCU*& rpcCU );
     181  Void xVerifyTileSetConstraint( TComDataCU*& rpcCU );
     182#endif
     183#endif //SVC_EXTENSION
    187184};
    188185
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5151Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
    5252{
    53 #if !HM_CLEANUP_SAO
    54   if (pcSlice->getSPS()->getUseSAO())
    55   {
    56     SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    57     pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
    58     {
    59       pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
    60     }
    61   }
    62 #endif
    6353  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
    6454  return;
     
    639629}
    640630
    641 #if !HM_CLEANUP_SAO
    642 /** Encode SAO Offset
    643  * \param  saoLcuParam SAO LCU paramters
    644  */
    645 Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
    646 {
    647   UInt uiSymbol;
    648   Int i;
    649 
    650   uiSymbol = saoLcuParam->typeIdx + 1;
    651   if (compIdx!=2)
    652   {
    653     m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
    654   }
    655   if (uiSymbol)
    656   {
    657     if (saoLcuParam->typeIdx < 4 && compIdx != 2)
    658     {
    659       saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
    660     }
    661     Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
    662     Int offsetTh = 1 << min(bitDepth - 5,5);
    663     if( saoLcuParam->typeIdx == SAO_BO )
    664     {
    665       for( i=0; i< saoLcuParam->length; i++)
    666       {
    667         UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
    668         m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
    669       } 
    670       for( i=0; i< saoLcuParam->length; i++)
    671       {
    672         if (saoLcuParam->offset[i] != 0)
    673         {
    674           UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
    675           m_pcEntropyCoderIf->codeSAOSign(sign);
    676         }
    677       }
    678       uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
    679       m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
    680     }
    681     else if( saoLcuParam->typeIdx < 4 )
    682     {
    683       m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
    684       m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
    685       m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
    686       m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
    687       if (compIdx!=2)
    688       {
    689         uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
    690         m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
    691       }
    692     }
    693   }
    694 }
    695 
    696 /** Encode SAO unit interleaving
    697 * \param  rx
    698 * \param  ry
    699 * \param  pSaoParam
    700 * \param  pcCU
    701 * \param  iCUAddrInSlice
    702 * \param  iCUAddrUpInSlice
    703 * \param  bLFCrossSliceBoundaryFlag
    704  */
    705 Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
    706 {
    707   if (saoFlag)
    708   {
    709     if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
    710     {
    711       m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
    712     }
    713     else
    714     {
    715       saoLcuParam->mergeLeftFlag = 0;
    716     }
    717     if (saoLcuParam->mergeLeftFlag == 0)
    718     {
    719       if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
    720       {
    721         m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
    722       }
    723       else
    724       {
    725         saoLcuParam->mergeUpFlag = 0;
    726       }
    727       if (!saoLcuParam->mergeUpFlag)
    728       {
    729         encodeSaoOffset(saoLcuParam, compIdx);
    730       }
    731     }
    732   }
    733 }
    734 
    735 #endif
    736 
    737631Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
    738632{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    105105  virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    106106  virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0;
    107 #if HM_CLEANUP_SAO
    108107  virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
    109 #else
    110   virtual Void codeSAOSign          ( UInt code   ) = 0;
    111   virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
    112   virtual Void codeSaoMerge    ( UInt   uiCode  ) = 0;
    113   virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    114   virtual Void codeSaoUflc         ( UInt uiLength, UInt   uiCode ) = 0;
    115 #endif
    116108  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    117109 
     
    192184 
    193185  Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
    194 #if HM_CLEANUP_SAO
    195186  Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
    196 #else
    197   Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
    198   Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
    199 #endif
    200187  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
    201188
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    9696  xResetNonNestedSEIPresentFlags();
    9797  xResetNestedSEIPresentFlags();
     98#if FIX1172
     99  m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP;
     100  m_associatedIRAPPOC  = 0;
     101#endif
    98102#if SVC_UPSAMPLING
    99103  m_pcPredSearch        = NULL;
     
    167171}
    168172
    169 #if LAYERS_NOT_PRESENT_SEI
    170 SEILayersNotPresent* TEncGOP::xCreateSEILayersNotPresent ()
    171 {
    172   UInt i = 0;
    173   SEILayersNotPresent *seiLayersNotPresent = new SEILayersNotPresent();
    174   seiLayersNotPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId();
    175   seiLayersNotPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers();
    176   for ( ; i < seiLayersNotPresent->m_vpsMaxLayers; i++)
    177   {
    178     seiLayersNotPresent->m_layerNotPresentFlag[i] = true;
    179   }
    180   for ( ; i < MAX_LAYERS; i++)
    181   {
    182     seiLayersNotPresent->m_layerNotPresentFlag[i] = false;
    183   }
    184   return seiLayersNotPresent;
    185 }
    186 #endif
    187173
    188174SEIFramePacking* TEncGOP::xCreateSEIFramePacking()
     
    307293}
    308294
    309 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    310 SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets()
    311 {
    312   SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets();
    313   seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false;
    314   seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false;
    315   if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag)
    316   {
    317     seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1;
    318     if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1)
    319     {
    320       seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag();
    321     }
    322     else
    323     {
    324       seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false;
    325     }
    326     seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0;
    327     for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
    328     {
    329       seiInterLayerConstrainedTileSets->m_ilctsId[i] = i;
    330       seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0;
    331       for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++)
    332       {
    333         seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j]     = m_pcCfg->getTopLeftTileIndex(i);
    334         seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i);
    335       }
    336       seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i);
    337       if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag)
    338       {
    339         seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false;
    340       }
    341     }
    342   }
    343 
    344   return seiInterLayerConstrainedTileSets;
    345 }
    346 #endif
    347 
    348295Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
    349296{
     
    362309    m_activeParameterSetSEIPresentInAU = true;
    363310  }
    364 
    365 #if LAYERS_NOT_PRESENT_SEI
    366   if(m_pcCfg->getLayersNotPresentSEIEnabled())
    367   {
    368     SEILayersNotPresent *sei = xCreateSEILayersNotPresent ();
    369     m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    370     m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
    371     writeRBSPTrailingBits(nalu.m_Bitstream);
    372     accessUnit.push_back(new NALUnitEBSP(nalu));
    373     delete sei;
    374   }
    375 #endif
    376311
    377312  if(m_pcCfg->getFramePackingArrangementSEIEnabled())
     
    408343    delete sei;
    409344  }
     345
     346#if SVC_EXTENSION
     347#if LAYERS_NOT_PRESENT_SEI
     348  if(m_pcCfg->getLayersNotPresentSEIEnabled())
     349  {
     350    SEILayersNotPresent *sei = xCreateSEILayersNotPresent ();
     351    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     352    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     353    writeRBSPTrailingBits(nalu.m_Bitstream);
     354    accessUnit.push_back(new NALUnitEBSP(nalu));
     355    delete sei;
     356  }
     357#endif
     358
    410359#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    411360  if(m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled())
     
    421370  }
    422371#endif
     372#endif //SVC_EXTENSION
    423373}
    424374
     
    547497#endif
    548498
    549     if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     499    if( getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
    550500    {
    551501      m_iLastIDR = pocCurr;
     
    554504    accessUnitsInGOP.push_back(AccessUnit());
    555505    AccessUnit& accessUnit = accessUnitsInGOP.back();
    556     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField );
     506    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField);
    557507
    558508    //  Slice data initialization
     
    571521    pcSlice->getPic()->setField(isField);
    572522
     523#if SVC_EXTENSION
    573524#if POC_RESET_FLAG
    574525    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
     
    636587#endif
    637588#if O0149_CROSS_LAYER_BLA_FLAG
    638     if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
     589    if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
    639590    {
    640591      pcSlice->setCrossLayerBLAFlag(m_pcEncTop->getCrossLayerBLAFlag());
     
    693644    }
    694645#endif
     646#endif //SVC_EXTENSION
    695647
    696648    pcSlice->setLastIDR(m_iLastIDR);
     
    760712        pcSlice->setDefaultScalingList ();
    761713      }
    762 
    763714      pcSlice->getScalingList()->checkDcOfMatrix();
    764715      m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList());
     
    782733      pcSlice->setSliceType(P_SLICE);
    783734    }
     735    if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='I')
     736    {
     737      pcSlice->setSliceType(I_SLICE);
     738    }
     739
    784740    // Set the nal unit type
    785     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
     741    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField));
    786742#if SVC_EXTENSION
    787743    if (m_layerId > 0)
     
    953909    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
    954910    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
     911#if FIX1172
     912    if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     913      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     914      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     915      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     916      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     917      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )  // IRAP picture
     918    {
     919      m_associatedIRAPType = pcSlice->getNalUnitType();
     920      m_associatedIRAPPOC = pocCurr;
     921    }
     922    pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
     923    pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
     924#endif
    955925
    956926    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
     
    960930    pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
    961931
    962     if(pcSlice->getTLayer() > 0)
     932    if(pcSlice->getTLayer() > 0
     933      &&  !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N     // Check if not a leading picture
     934          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
     935          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N
     936          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R )
     937        )
    963938    {
    964939      if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
     
    16331608
    16341609    // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
    1635 #if HM_CLEANUP_SAO
    16361610    if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() )
    16371611    {
    16381612      m_pcSAO->getPreDBFStatistics(pcPic);
    16391613    }
    1640 #else
    1641     if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() )
    1642     {
    1643       m_pcSAO->resetStats();
    1644       m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic );
    1645     }
    1646 #endif   
    16471614    //-- Loop filter
    16481615    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     
    16541621    m_pcLoopFilter->loopFilterPic( pcPic );
    16551622
    1656 #if !HM_CLEANUP_SAO   
    1657     pcSlice = pcPic->getSlice(0);
    1658     if(pcSlice->getSPS()->getUseSAO())
    1659     {
    1660       std::vector<Bool> LFCrossSliceBoundaryFlag;
    1661       for(Int s=0; s< uiNumSlices; s++)
    1662       {
    1663         LFCrossSliceBoundaryFlag.push_back(  ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) );
    1664       }
    1665       m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1);
    1666       pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary);
    1667     }
    1668 
    1669 
    1670     pcSlice = pcPic->getSlice(0);
    1671 
    1672     if(pcSlice->getSPS()->getUseSAO())
    1673     {
    1674       m_pcSAO->createPicSaoInfo(pcPic);
    1675     }
    1676 #endif
    16771623    /////////////////////////////////////////////////////////////////////////////////////////////////// File writing
    16781624    // Set entropy coder
     
    17921738        {
    17931739          SOPcurrPOC += deltaPOC;
    1794           SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR);
     1740          SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR, isField);
    17951741          SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId;
    17961742          SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j);
     
    22572203              m_pcEntropyCoder->resetEntropy();
    22582204              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
    2259 #if HM_CLEANUP_SAO
    22602205              Bool sliceEnabled[NUM_SAO_COMPONENTS];
    22612206              m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice);
     
    22762221                pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]);
    22772222              }
    2278 #else
    2279               m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
    2280               SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam();
    2281 
    2282 #if SAO_ENCODING_CHOICE
    2283               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdas()[TEXT_LUMA], pcPic->getSlice(0)->getLambdas()[TEXT_CHROMA], pcPic->getSlice(0)->getDepth());
    2284 #else
    2285               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
    2286 #endif
    2287               m_pcSAO->endSaoEnc();
    2288               m_pcSAO->PCMLFDisableProcess(pcPic);
    2289 #endif
    22902223            }
    2291 #if !HM_CLEANUP_SAO         
    2292 #if SAO_RDO
    2293             m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    2294 #endif
    2295 #endif
    22962224            processingState = ENCODE_SLICE;
    2297 #if !HM_CLEANUP_SAO
    2298 #if HIGHER_LAYER_IRAP_SKIP_FLAG
    2299             if ( ( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) )
    2300             {
    2301               pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]=0;
    2302               pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[1]=0;
    2303             }
    2304 #endif
    2305             for(Int s=0; s< uiNumSlices; s++)
    2306             {
    2307               if (pcSlice->getSPS()->getUseSAO())
    2308               {
    2309                 pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false);
    2310               }
    2311             }
    2312 #endif
    23132225          }
    23142226          break;
     
    23212233        }
    23222234      } // end iteration over slices
    2323 #if !HM_CLEANUP_SAO   
    2324       if(pcSlice->getSPS()->getUseSAO())
    2325       {
    2326         if(pcSlice->getSPS()->getUseSAO())
    2327         {
    2328           m_pcSAO->destroyPicSaoInfo();
    2329         }
    2330         pcPic->destroyNonDBFilterInfo();
    2331       }
    2332 #endif
    23332235      pcPic->compressMotion();
    23342236     
     
    24022304
    24032305      //In case of field coding, compute the interlaced PSNR for both fields
    2404       if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     2306    if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) && (pcPic->getPOC()%m_iGopSize != 1))
    24052307      {
    24062308        //get complementary top field
     
    24142316        xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
    24152317      }
     2318    else if (isField && pcPic->getPOC()!= 0 && (pcPic->getPOC()%m_iGopSize == 0))
     2319    {
     2320      //get complementary bottom field
     2321      TComPic* pcPicBottom;
     2322      TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     2323      while ((*iterPic)->getPOC() != pcPic->getPOC()+1)
     2324      {
     2325        iterPic ++;
     2326      }
     2327      pcPicBottom = *(iterPic);
     2328      xCalculateInterlacedAddPSNR(pcPic, pcPicBottom, pcPic->getPicYuvRec(), pcPicBottom->getPicYuvRec(), accessUnit, dEncTime );
     2329    }
    24162330
    24172331      if (digestStr)
     
    27172631  m_pcEntropyCoder->resetEntropy    ();
    27182632  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    2719 #if !HM_CLEANUP_SAO
    2720   pcSlice = pcPic->getSlice(0);
    2721   if(pcSlice->getSPS()->getUseSAO())
    2722   {
    2723     std::vector<Bool> LFCrossSliceBoundaryFlag(1, true);
    2724     std::vector<Int>  sliceStartAddress;
    2725     sliceStartAddress.push_back(0);
    2726     sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU());
    2727     pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag);
    2728   }
    2729  
    2730   if( pcSlice->getSPS()->getUseSAO())
    2731   {
    2732     pcPic->destroyNonDBFilterInfo();
    2733   }
    2734 #endif
    27352633  m_pcEntropyCoder->resetEntropy    ();
    27362634  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
     
    33033201 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
    33043202 */
    3305 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR)
     3203NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR, Bool isField)
    33063204{
    33073205  if (pocCurr == 0)
     
    33093207    return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    33103208  }
    3311   if (pocCurr % m_pcCfg->getIntraPeriod() == 0)
     3209  if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
    33123210  {
    33133211    if (m_pcCfg->getDecodingRefreshType() == 1)
     
    35323430  return seiStartPos;
    35333431}
    3534 
    3535 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    3536 Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym)
    3537 {
    3538   Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU();
    3539 
    3540   for (Int i = 0; i < numCUs; i++)
    3541   {
    3542     picSym->setTileSetIdxMap(i, -1, 0, false);
    3543   }
    3544 
    3545   for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
    3546   {
    3547     TComTile* topLeftTile     = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i));
    3548     TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i));
    3549     Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1;
    3550     Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU();
    3551     Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1;
    3552     Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU();
    3553     assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU);
    3554     for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++)
    3555     {
    3556       for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++)
    3557       {
    3558         picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false);
    3559       }
    3560     }
    3561   }
    3562  
    3563   if (m_pcCfg->getSkippedTileSetPresentFlag())
    3564   {
    3565     Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage();
    3566     for (Int i = 0; i < numCUs; i++)
    3567     {
    3568       if (picSym->getTileSetIdxMap(i) < 0)
    3569       {
    3570         picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true);
    3571       }
    3572     }
    3573   }
    3574 }
    3575 #endif
    35763432
    35773433Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
     
    36983554  free(rowSAD);
    36993555}
     3556#if SVC_EXTENSION
     3557#if LAYERS_NOT_PRESENT_SEI
     3558SEILayersNotPresent* TEncGOP::xCreateSEILayersNotPresent ()
     3559{
     3560  UInt i = 0;
     3561  SEILayersNotPresent *seiLayersNotPresent = new SEILayersNotPresent();
     3562  seiLayersNotPresent->m_activeVpsId = m_pcCfg->getVPS()->getVPSId();
     3563  seiLayersNotPresent->m_vpsMaxLayers = m_pcCfg->getVPS()->getMaxLayers();
     3564  for ( ; i < seiLayersNotPresent->m_vpsMaxLayers; i++)
     3565  {
     3566    seiLayersNotPresent->m_layerNotPresentFlag[i] = true;
     3567  }
     3568  for ( ; i < MAX_LAYERS; i++)
     3569  {
     3570    seiLayersNotPresent->m_layerNotPresentFlag[i] = false;
     3571  }
     3572  return seiLayersNotPresent;
     3573}
     3574#endif
     3575
     3576#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3577SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets()
     3578{
     3579  SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets();
     3580  seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false;
     3581  seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false;
     3582  if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag)
     3583  {
     3584    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1;
     3585    if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1)
     3586    {
     3587      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag();
     3588    }
     3589    else
     3590    {
     3591      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false;
     3592    }
     3593    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0;
     3594    for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
     3595    {
     3596      seiInterLayerConstrainedTileSets->m_ilctsId[i] = i;
     3597      seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0;
     3598      for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++)
     3599      {
     3600        seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j]     = m_pcCfg->getTopLeftTileIndex(i);
     3601        seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i);
     3602      }
     3603      seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i);
     3604      if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag)
     3605      {
     3606        seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false;
     3607      }
     3608    }
     3609  }
     3610
     3611  return seiInterLayerConstrainedTileSets;
     3612}
     3613
     3614Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym)
     3615{
     3616  Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU();
     3617
     3618  for (Int i = 0; i < numCUs; i++)
     3619  {
     3620    picSym->setTileSetIdxMap(i, -1, 0, false);
     3621  }
     3622
     3623  for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
     3624  {
     3625    TComTile* topLeftTile     = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i));
     3626    TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i));
     3627    Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1;
     3628    Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU();
     3629    Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1;
     3630    Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU();
     3631    assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU);
     3632    for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++)
     3633    {
     3634      for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++)
     3635      {
     3636        picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false);
     3637      }
     3638    }
     3639  }
     3640 
     3641  if (m_pcCfg->getSkippedTileSetPresentFlag())
     3642  {
     3643    Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage();
     3644    for (Int i = 0; i < numCUs; i++)
     3645    {
     3646      if (picSym->getTileSetIdxMap(i) < 0)
     3647      {
     3648        picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true);
     3649      }
     3650    }
     3651  }
     3652}
     3653#endif
     3654#endif //SVC_EXTENSION
     3655
    37003656//! \}
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    8383  Bool                    m_bFirst;
    8484 
    85 #if SVC_EXTENSION
    86   UInt                    m_layerId;     
    87 #endif
    88 
    8985  //  Access channel
    9086  TEncTop*                m_pcEncTop;
     
    9288  TEncSlice*              m_pcSliceEncoder;
    9389  TComList<TComPic*>*     m_pcListPic;
    94  
    95 #if SVC_EXTENSION
    96   TEncTop**               m_ppcTEncTop;
    97 #if SVC_UPSAMPLING
    98   TEncSearch*             m_pcPredSearch;                       ///< encoder search class
    99 #endif 
    100 #endif
    10190 
    10291  TEncEntropy*            m_pcEntropyCoder;
     
    120109  std::vector<Int>        m_storedStartCUAddrForEncodingSlice;
    121110  std::vector<Int>        m_storedStartCUAddrForEncodingSliceSegment;
     111#if FIX1172
     112  NalUnitType             m_associatedIRAPType;
     113  Int                     m_associatedIRAPPOC;
     114#endif
    122115
    123116  std::vector<Int> m_vRVM_RP;
     
    132125  Bool                    m_nestedBufferingPeriodSEIPresentInAU;
    133126  Bool                    m_nestedPictureTimingSEIPresentInAU;
     127
     128#if SVC_EXTENSION
     129  UInt                    m_layerId;     
     130  TEncTop**               m_ppcTEncTop;
     131#if SVC_UPSAMPLING
     132  TEncSearch*             m_pcPredSearch;                       ///< encoder search class
     133#endif 
     134#endif
     135 
    134136public:
    135137  TEncGOP();
     
    162164 
    163165  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
    164   NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
     166  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField );
    165167  Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& );
    166168protected:
     
    181183
    182184  SEIActiveParameterSets* xCreateSEIActiveParameterSets (TComSPS *sps);
    183 #if LAYERS_NOT_PRESENT_SEI
    184   SEILayersNotPresent*    xCreateSEILayersNotPresent ();
    185 #endif
    186185  SEIFramePacking*        xCreateSEIFramePacking();
    187186  SEIDisplayOrientation*  xCreateSEIDisplayOrientation();
    188187
    189188  SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
    190 
    191 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    192   SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets();
    193 #endif
    194189
    195190  Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
     
    206201    m_nestedPictureTimingSEIPresentInAU      = false;
    207202  }
     203  Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
     204
     205#if SVC_EXTENSION
     206#if LAYERS_NOT_PRESENT_SEI
     207  SEILayersNotPresent*    xCreateSEILayersNotPresent ();
     208#endif
    208209#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    209210  Void xBuildTileSetsMap(TComPicSym* picSym);
    210 #endif
    211   Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
     211  SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets();
     212#endif
     213#endif //SVC_EXTENSION
    212214};// END CLASS DEFINITION TEncGOP
    213215
  • trunk/source/Lib/TLibEncoder/TEncPic.cpp

    r494 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncPic.h

    r494 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncPreanalyzer.cpp

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncPreanalyzer.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    4646
    4747
    48 #if HM_CLEANUP_SAO
    49 
    5048/** rounding with IBDI
    5149 * \param  x
     
    259257  TComPicYuv* orgYuv= pPic->getPicYuvOrg();
    260258  TComPicYuv* resYuv= pPic->getPicYuvRec();
    261   m_labmda[SAO_Y]= lambdas[0]; m_labmda[SAO_Cb]= lambdas[1]; m_labmda[SAO_Cr]= lambdas[2];
     259  m_lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2];
    262260  TComPicYuv* srcYuv = m_tempPicYuv;
    263261  resYuv->copyToPic(srcYuv);
     
    509507          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
    510508          {
    511             quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );
     509            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );
    512510          }
    513511        }
     
    523521        for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++)
    524522        {         
    525           costBOClasses[classIdx]= m_labmda[compIdx];
     523          costBOClasses[classIdx]= m_lambda[compIdx];
    526524          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
    527525          {
    528             quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh );
     526            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh );
    529527          }
    530528        }
     
    572570{
    573571  Double minCost, cost;
    574   Int rate, minRate;
     572  Int rate;
     573  UInt previousWrittenBits;
    575574  Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS];
    576575  SAOOffset testOffset[NUM_SAO_COMPONENTS];
     
    592591  m_pcRDGoOnSbacCoder->resetBits();
    593592  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
    594   minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    595593  modeDist[compIdx] = 0;
    596   minCost= m_labmda[compIdx]*((Double)minRate);
     594  minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());
    597595  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
    598596  if(sliceEnabled[compIdx])
     
    617615      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
    618616      rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    619       cost = (Double)dist[compIdx] + m_labmda[compIdx]*((Double)rate);
     617      cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate);
    620618      if(cost < minCost)
    621619      {
    622620        minCost = cost;
    623         minRate = rate;
    624621        modeDist[compIdx] = dist[compIdx];
    625622        modeParam[compIdx]= testOffset[compIdx];
     
    632629
    633630  //------ chroma --------//
    634   assert(m_labmda[SAO_Cb] == m_labmda[SAO_Cr]);
    635   Double chromaLambda = m_labmda[SAO_Cb];
    636631  //"off" case as initial cost
     632  cost = 0;
     633  previousWrittenBits = 0;
    637634  m_pcRDGoOnSbacCoder->resetBits();
    638   modeParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
    639   m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, modeParam[SAO_Cb], sliceEnabled[SAO_Cb]);
    640   modeParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
    641   m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, modeParam[SAO_Cr], sliceEnabled[SAO_Cr]);
    642   minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    643   modeDist[SAO_Cb] = modeDist[SAO_Cr]= 0;
    644   minCost= chromaLambda*((Double)minRate);
     635  for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++)
     636  {
     637    modeParam[component].modeIdc = SAO_MODE_OFF;
     638    modeDist [component] = 0;
     639
     640    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component]);
     641
     642    const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     643    cost += m_lambda[component] * (currentWrittenBits - previousWrittenBits);
     644    previousWrittenBits = currentWrittenBits;
     645  }
     646
     647  minCost = cost;
    645648
    646649  //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function
     
    648651  for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
    649652  {
     653    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     654    m_pcRDGoOnSbacCoder->resetBits();
     655    previousWrittenBits = 0;
     656    cost = 0;
     657
    650658    for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
    651659    {
     
    663671      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
    664672      dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
    665     }
    666 
    667     //get rate
    668     m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
    669     m_pcRDGoOnSbacCoder->resetBits();
    670     m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, testOffset[SAO_Cb], sliceEnabled[SAO_Cb]);
    671     m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, testOffset[SAO_Cr], sliceEnabled[SAO_Cr]);
    672     rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
    673 
    674     cost = (Double)(dist[SAO_Cb]+ dist[SAO_Cr]) + chromaLambda*((Double)rate);
     673
     674      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     675
     676      const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     677      cost += dist[compIdx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits));
     678      previousWrittenBits = currentWrittenBits;
     679    }
     680
    675681    if(cost < minCost)
    676682    {
    677683      minCost = cost;
    678       minRate = rate;
    679       modeDist[SAO_Cb] = dist[SAO_Cb];
    680       modeDist[SAO_Cr] = dist[SAO_Cr];
    681       modeParam[SAO_Cb]= testOffset[SAO_Cb];
    682       modeParam[SAO_Cr]= testOffset[SAO_Cr];
     684      for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     685      {
     686        modeDist [compIdx] = dist      [compIdx];
     687        modeParam[compIdx] = testOffset[compIdx];
     688      }
    683689    }
    684690  }
     
    686692
    687693  //----- re-gen rate & normalized cost----//
    688   modeNormCost  = (Double)modeDist[SAO_Y]/m_labmda[SAO_Y];
    689   modeNormCost += (Double)(modeDist[SAO_Cb]+ modeDist[SAO_Cr])/chromaLambda;
     694  modeNormCost = 0;
     695  for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++)
     696  {
     697    modeNormCost += (Double)modeDist[component] / m_lambda[component];
     698  }
    690699  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
    691700  m_pcRDGoOnSbacCoder->resetBits();
     
    724733        //offsets have been reconstructed. Don't call inversed quantization function.
    725734        normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))
    726                        /m_labmda[compIdx]
     735                       /m_lambda[compIdx]
    727736                    );
    728737      }
     
    13041313}
    13051314
    1306 #else
    1307 
    1308 
    1309 
    1310 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    1311 {
    1312   m_pcEntropyCoder = NULL;
    1313   m_pppcRDSbacCoder = NULL;
    1314   m_pcRDGoOnSbacCoder = NULL;
    1315   m_pppcBinCoderCABAC = NULL;           
    1316   m_iCount = NULL;     
    1317   m_iOffset = NULL;     
    1318   m_iOffsetOrg = NULL; 
    1319   m_iRate = NULL;       
    1320   m_iDist = NULL;       
    1321   m_dCost = NULL;       
    1322   m_dCostPartBest = NULL;
    1323   m_iDistOrg = NULL;     
    1324   m_iTypePartBest = NULL;
    1325 #if SAO_ENCODING_CHOICE_CHROMA
    1326   m_depthSaoRate[0][0] = 0;
    1327   m_depthSaoRate[0][1] = 0;
    1328   m_depthSaoRate[0][2] = 0;
    1329   m_depthSaoRate[0][3] = 0;
    1330   m_depthSaoRate[1][0] = 0;
    1331   m_depthSaoRate[1][1] = 0;
    1332   m_depthSaoRate[1][2] = 0;
    1333   m_depthSaoRate[1][3] = 0;
    1334 #endif
    1335 }
    1336 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
    1337 {
    1338 
    1339 }
    1340 // ====================================================================================================================
    1341 // Constants
    1342 // ====================================================================================================================
    1343 
    1344 
    1345 // ====================================================================================================================
    1346 // Tables
    1347 // ====================================================================================================================
    1348 
    1349 inline Double xRoundIbdi2(Int bitDepth, Double x)
    1350 {
    1351   return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));
    1352 }
    1353 
    1354 /** rounding with IBDI
    1355  * \param  x
    1356  */
    1357 inline Double xRoundIbdi(Int bitDepth, Double x)
    1358 {
    1359   return (bitDepth > 8 ? xRoundIbdi2(bitDepth, (x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
    1360 }
    1361 
    1362 
    1363 
    1364 /** process SAO for one partition
    1365  * \param  *psQTPart, iPartIdx, dLambda
    1366  */
    1367 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr)
    1368 {
    1369   Int iTypeIdx;
    1370   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    1371   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    1372 
    1373   Int64 iEstDist;
    1374   Int iClassIdx;
    1375   Int uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT((yCbCr == 0 ? g_bitDepthY : g_bitDepthC)-8);
    1376   UInt uiDepth = pOnePart->PartLevel;
    1377 
    1378   m_iDistOrg [iPartIdx] =  0;
    1379 
    1380   Double  bestRDCostTableBo = MAX_DOUBLE;
    1381   Int     bestClassTableBo    = 0;
    1382   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    1383   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    1384 
    1385   Int addr;
    1386   Int allowMergeLeft;
    1387   Int allowMergeUp;
    1388   Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
    1389   SaoLcuParam  saoLcuParamRdo;
    1390 
    1391   for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
    1392   {
    1393     if( m_bUseSBACRD )
    1394     {
    1395       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    1396       m_pcRDGoOnSbacCoder->resetBits();
    1397     }
    1398     else
    1399     {
    1400       m_pcEntropyCoder->resetEntropy();
    1401       m_pcEntropyCoder->resetBits();
    1402     }
    1403 
    1404     iEstDist = 0;
    1405 
    1406     if (iTypeIdx == -1)
    1407     {     
    1408       for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
    1409       {
    1410         for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
    1411         {
    1412           addr = ry * frameWidthInCU + rx;         
    1413 
    1414           // get bits for iTypeIdx = -1
    1415           allowMergeLeft = 1;
    1416           allowMergeUp   = 1;
    1417           if (rx != 0)
    1418           {
    1419             // check tile id and slice id
    1420             if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    1421             {
    1422               allowMergeLeft = 0;
    1423             }
    1424           }
    1425           if (ry!=0)
    1426           {
    1427             if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    1428             {
    1429               allowMergeUp = 0;
    1430             }
    1431           }
    1432 
    1433           // reset
    1434           resetSaoUnit(&saoLcuParamRdo);
    1435 
    1436           // set merge flag
    1437           saoLcuParamRdo.mergeUpFlag   = 1;
    1438           saoLcuParamRdo.mergeLeftFlag = 1;
    1439 
    1440           if (ry == pOnePart->StartCUY)
    1441           {
    1442             saoLcuParamRdo.mergeUpFlag = 0;
    1443           }
    1444          
    1445           if (rx == pOnePart->StartCUX)
    1446           {
    1447             saoLcuParamRdo.mergeLeftFlag = 0;
    1448           }
    1449 
    1450           m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
    1451 
    1452         }
    1453       }
    1454     }
    1455 
    1456     if (iTypeIdx>=0)
    1457     {
    1458       iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo);
    1459       if( iTypeIdx == SAO_BO )
    1460       {
    1461         // Estimate Best Position
    1462         Double currentRDCost = 0.0;
    1463 
    1464         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    1465         {
    1466           currentRDCost = 0.0;
    1467           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    1468           {
    1469             currentRDCost += currentRdCostTableBo[uj];
    1470           }
    1471 
    1472           if( currentRDCost < bestRDCostTableBo)
    1473           {
    1474             bestRDCostTableBo = currentRDCost;
    1475             bestClassTableBo  = i;
    1476           }
    1477         }
    1478 
    1479         // Re code all Offsets
    1480         // Code Center
    1481         for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
    1482         {
    1483           iEstDist += currentDistortionTableBo[iClassIdx];
    1484         }
    1485       }
    1486 
    1487       for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
    1488       {
    1489         for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
    1490         {
    1491           addr = ry * frameWidthInCU + rx;         
    1492 
    1493           // get bits for iTypeIdx = -1
    1494           allowMergeLeft = 1;
    1495           allowMergeUp   = 1;
    1496           if (rx != 0)
    1497           {
    1498             // check tile id and slice id
    1499             if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    1500             {
    1501               allowMergeLeft = 0;
    1502             }
    1503           }
    1504           if (ry!=0)
    1505           {
    1506             if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    1507             {
    1508               allowMergeUp = 0;
    1509             }
    1510           }
    1511 
    1512           // reset
    1513           resetSaoUnit(&saoLcuParamRdo);
    1514          
    1515           // set merge flag
    1516           saoLcuParamRdo.mergeUpFlag   = 1;
    1517           saoLcuParamRdo.mergeLeftFlag = 1;
    1518 
    1519           if (ry == pOnePart->StartCUY)
    1520           {
    1521             saoLcuParamRdo.mergeUpFlag = 0;
    1522           }
    1523          
    1524           if (rx == pOnePart->StartCUX)
    1525           {
    1526             saoLcuParamRdo.mergeLeftFlag = 0;
    1527           }
    1528 
    1529           // set type and offsets
    1530           saoLcuParamRdo.typeIdx = iTypeIdx;
    1531           saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0;
    1532           saoLcuParamRdo.length = m_iNumClass[iTypeIdx];
    1533           for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++)
    1534           {
    1535             saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1];
    1536           }
    1537 
    1538           m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
    1539 
    1540         }
    1541       }
    1542 
    1543       m_iDist[iPartIdx][iTypeIdx] = iEstDist;
    1544       m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
    1545 
    1546       m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
    1547 
    1548       if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
    1549       {
    1550         m_iDistOrg [iPartIdx] = 0;
    1551         m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
    1552         m_iTypePartBest[iPartIdx] = iTypeIdx;
    1553         if( m_bUseSBACRD )
    1554           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    1555       }
    1556     }
    1557     else
    1558     {
    1559       if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
    1560       {
    1561         m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
    1562         m_iTypePartBest[iPartIdx] = -1;
    1563         if( m_bUseSBACRD )
    1564         {
    1565           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    1566         }
    1567       }
    1568     }
    1569   }
    1570 
    1571   pOnePart->bProcessed = true;
    1572   pOnePart->bSplit     = false;
    1573   pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
    1574   pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
    1575   pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
    1576   pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
    1577   if (pOnePart->iBestType != -1)
    1578   {
    1579     //     pOnePart->bEnableFlag =  1;
    1580     pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
    1581     Int minIndex = 0;
    1582     if( pOnePart->iBestType == SAO_BO )
    1583     {
    1584       pOnePart->subTypeIdx = bestClassTableBo;
    1585       minIndex = pOnePart->subTypeIdx;
    1586     }
    1587     for (Int i=0; i< pOnePart->iLength ; i++)
    1588     {
    1589       pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
    1590     }
    1591 
    1592   }
    1593   else
    1594   {
    1595     //     pOnePart->bEnableFlag = 0;
    1596     pOnePart->iLength     = 0;
    1597   }
    1598 }
    1599 
    1600 /** Run partition tree disable
    1601  */
    1602 Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
    1603 {
    1604   SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
    1605   pOnePart->bSplit      = false;
    1606   pOnePart->iLength     =  0;
    1607   pOnePart->iBestType   = -1;
    1608 
    1609   if (pOnePart->PartLevel < m_uiMaxSplitLevel)
    1610   {
    1611     for (Int i=0; i<NUM_DOWN_PART; i++)
    1612     {
    1613       disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    1614     }
    1615   }
    1616 }
    1617 
    1618 /** Run quadtree decision function
    1619  * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
    1620  */
    1621 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr)
    1622 {
    1623   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    1624 
    1625   UInt uiDepth = pOnePart->PartLevel;
    1626   UInt uhNextDepth = uiDepth+1;
    1627 
    1628   if (iPartIdx == 0)
    1629   {
    1630     dCostFinal = 0;
    1631   }
    1632 
    1633   //SAO for this part
    1634   if(!pOnePart->bProcessed)
    1635   {
    1636     rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr);
    1637   }
    1638 
    1639   //SAO for sub 4 parts
    1640   if (pOnePart->PartLevel < iMaxLevel)
    1641   {
    1642     Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
    1643     Double      dCostSplit    = dLambda;
    1644 
    1645     for (Int i=0; i< NUM_DOWN_PART ;i++)
    1646     {
    1647       if( m_bUseSBACRD ) 
    1648       {
    1649         if ( 0 == i) //initialize RD with previous depth buffer
    1650         {
    1651           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    1652         }
    1653         else
    1654         {
    1655           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    1656         }
    1657       } 
    1658       runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr);
    1659       dCostSplit += dCostFinal;
    1660       if( m_bUseSBACRD )
    1661       {
    1662         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
    1663       }
    1664     }
    1665 
    1666     if(dCostSplit < dCostNotSplit)
    1667     {
    1668       dCostFinal = dCostSplit;
    1669       pOnePart->bSplit      = true;
    1670       pOnePart->iLength     =  0;
    1671       pOnePart->iBestType   = -1;
    1672       if( m_bUseSBACRD )
    1673       {
    1674         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    1675       }
    1676     }
    1677     else
    1678     {
    1679       dCostFinal = dCostNotSplit;
    1680       pOnePart->bSplit = false;
    1681       for (Int i=0; i<NUM_DOWN_PART; i++)
    1682       {
    1683         disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    1684       }
    1685       if( m_bUseSBACRD )
    1686       {
    1687         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    1688       }
    1689     }
    1690   }
    1691   else
    1692   {
    1693     dCostFinal = pOnePart->dMinCost;
    1694   }
    1695 }
    1696 
    1697 /** delete allocated memory of TEncSampleAdaptiveOffset class.
    1698  */
    1699 Void TEncSampleAdaptiveOffset::destroyEncBuffer()
    1700 {
    1701   for (Int i=0;i<m_iNumTotalParts;i++)
    1702   {
    1703     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    1704     {
    1705       if (m_iCount [i][j])
    1706       {
    1707         delete [] m_iCount [i][j];
    1708       }
    1709       if (m_iOffset[i][j])
    1710       {
    1711         delete [] m_iOffset[i][j];
    1712       }
    1713       if (m_iOffsetOrg[i][j])
    1714       {
    1715         delete [] m_iOffsetOrg[i][j];
    1716       }
    1717     }
    1718     if (m_iRate[i])
    1719     {
    1720       delete [] m_iRate[i];
    1721     }
    1722     if (m_iDist[i])
    1723     {
    1724       delete [] m_iDist[i];
    1725     }
    1726     if (m_dCost[i])
    1727     {
    1728       delete [] m_dCost[i];
    1729     }
    1730     if (m_iCount [i])
    1731     {
    1732       delete [] m_iCount [i];
    1733     }
    1734     if (m_iOffset[i])
    1735     {
    1736       delete [] m_iOffset[i];
    1737     }
    1738     if (m_iOffsetOrg[i])
    1739     {
    1740       delete [] m_iOffsetOrg[i];
    1741     }
    1742 
    1743   }
    1744   if (m_iDistOrg)
    1745   {
    1746     delete [] m_iDistOrg ; m_iDistOrg = NULL;
    1747   }
    1748   if (m_dCostPartBest)
    1749   {
    1750     delete [] m_dCostPartBest ; m_dCostPartBest = NULL;
    1751   }
    1752   if (m_iTypePartBest)
    1753   {
    1754     delete [] m_iTypePartBest ; m_iTypePartBest = NULL;
    1755   }
    1756   if (m_iRate)
    1757   {
    1758     delete [] m_iRate ; m_iRate = NULL;
    1759   }
    1760   if (m_iDist)
    1761   {
    1762     delete [] m_iDist ; m_iDist = NULL;
    1763   }
    1764   if (m_dCost)
    1765   {
    1766     delete [] m_dCost ; m_dCost = NULL;
    1767   }
    1768   if (m_iCount)
    1769   {
    1770     delete [] m_iCount  ; m_iCount = NULL;
    1771   }
    1772   if (m_iOffset)
    1773   {
    1774     delete [] m_iOffset ; m_iOffset = NULL;
    1775   }
    1776   if (m_iOffsetOrg)
    1777   {
    1778     delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
    1779   }
    1780   Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
    1781 
    1782   for (Int i=0;i<numLcu;i++)
    1783   {
    1784     for (Int j=0;j<3;j++)
    1785     {
    1786       for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
    1787       {
    1788         if (m_count_PreDblk [i][j][k])
    1789         {
    1790           delete [] m_count_PreDblk [i][j][k];
    1791         }
    1792         if (m_offsetOrg_PreDblk[i][j][k])
    1793         {
    1794           delete [] m_offsetOrg_PreDblk[i][j][k];
    1795         }
    1796       }
    1797       if (m_count_PreDblk [i][j])
    1798       {
    1799         delete [] m_count_PreDblk [i][j];
    1800       }
    1801       if (m_offsetOrg_PreDblk[i][j])
    1802       {
    1803         delete [] m_offsetOrg_PreDblk[i][j];
    1804       }
    1805     }
    1806     if (m_count_PreDblk [i])
    1807     {
    1808       delete [] m_count_PreDblk [i];
    1809     }
    1810     if (m_offsetOrg_PreDblk[i])
    1811     {
    1812       delete [] m_offsetOrg_PreDblk[i];
    1813     }
    1814   }
    1815   if (m_count_PreDblk)
    1816   {
    1817     delete [] m_count_PreDblk  ; m_count_PreDblk = NULL;
    1818   }
    1819   if (m_offsetOrg_PreDblk)
    1820   {
    1821     delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL;
    1822   }
    1823 
    1824   Int iMaxDepth = 4;
    1825   Int iDepth;
    1826   for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    1827   {
    1828     for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    1829     {
    1830       delete m_pppcRDSbacCoder[iDepth][iCIIdx];
    1831       delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
    1832     }
    1833   }
    1834 
    1835   for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    1836   {
    1837     delete [] m_pppcRDSbacCoder[iDepth];
    1838     delete [] m_pppcBinCoderCABAC[iDepth];
    1839   }
    1840 
    1841   delete [] m_pppcRDSbacCoder;
    1842   delete [] m_pppcBinCoderCABAC;
    1843 }
    1844 
    1845 /** create Encoder Buffer for SAO
    1846  * \param
    1847  */
    1848 Void TEncSampleAdaptiveOffset::createEncBuffer()
    1849 {
    1850   m_iDistOrg = new Int64 [m_iNumTotalParts];
    1851   m_dCostPartBest = new Double [m_iNumTotalParts];
    1852   m_iTypePartBest = new Int [m_iNumTotalParts];
    1853 
    1854   m_iRate = new Int64* [m_iNumTotalParts];
    1855   m_iDist = new Int64* [m_iNumTotalParts];
    1856   m_dCost = new Double*[m_iNumTotalParts];
    1857 
    1858   m_iCount  = new Int64 **[m_iNumTotalParts];
    1859   m_iOffset = new Int64 **[m_iNumTotalParts];
    1860   m_iOffsetOrg = new Int64 **[m_iNumTotalParts];
    1861 
    1862   for (Int i=0;i<m_iNumTotalParts;i++)
    1863   {
    1864     m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
    1865     m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
    1866     m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
    1867 
    1868     m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
    1869     m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    1870     m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    1871 
    1872     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    1873     {
    1874       m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    1875       m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    1876       m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
    1877     }
    1878   }
    1879   Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
    1880   m_count_PreDblk  = new Int64 ***[numLcu];
    1881   m_offsetOrg_PreDblk = new Int64 ***[numLcu];
    1882   for (Int i=0; i<numLcu; i++)
    1883   {
    1884     m_count_PreDblk[i]  = new Int64 **[3];
    1885     m_offsetOrg_PreDblk[i] = new Int64 **[3];
    1886 
    1887     for (Int j=0;j<3;j++)
    1888     {
    1889       m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
    1890       m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
    1891 
    1892       for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
    1893       {
    1894         m_count_PreDblk [i][j][k]   = new Int64 [MAX_NUM_SAO_CLASS];
    1895         m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS];
    1896       }
    1897     }
    1898   }
    1899 
    1900   Int iMaxDepth = 4;
    1901   m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1];
    1902 #if FAST_BIT_EST
    1903   m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1];
    1904 #else
    1905   m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1];
    1906 #endif
    1907 
    1908   for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    1909   {
    1910     m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
    1911 #if FAST_BIT_EST
    1912     m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
    1913 #else
    1914     m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
    1915 #endif
    1916     for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    1917     {
    1918       m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
    1919 #if FAST_BIT_EST
    1920       m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
    1921 #else
    1922       m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
    1923 #endif
    1924       m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
    1925     }
    1926   }
    1927 }
    1928 
    1929 /** Start SAO encoder
    1930  * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
    1931  */
    1932 Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
    1933 {
    1934     m_bUseSBACRD = true;
    1935   m_pcPic = pcPic;
    1936   m_pcEntropyCoder = pcEntropyCoder;
    1937 
    1938   m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
    1939   m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0));
    1940   m_pcEntropyCoder->resetEntropy();
    1941   m_pcEntropyCoder->resetBits();
    1942 
    1943   if( m_bUseSBACRD )
    1944   {
    1945     m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
    1946     m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
    1947   }
    1948 }
    1949 
    1950 /** End SAO encoder
    1951  */
    1952 Void TEncSampleAdaptiveOffset::endSaoEnc()
    1953 {
    1954   m_pcPic = NULL;
    1955   m_pcEntropyCoder = NULL;
    1956 }
    1957 
    1958 inline Int xSign(Int x)
    1959 {
    1960   return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31)));
    1961 }
    1962 
    1963 /** Calculate SAO statistics for non-cross-slice or non-cross-tile processing
    1964  * \param  pRecStart to-be-filtered block buffer pointer
    1965  * \param  pOrgStart original block buffer pointer
    1966  * \param  stride picture buffer stride
    1967  * \param  ppStat statistics buffer
    1968  * \param  ppCount counter buffer
    1969  * \param  width block width
    1970  * \param  height block height
    1971  * \param  pbBorderAvail availabilities of block border pixels
    1972  */
    1973 Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr)
    1974 {
    1975   Int64 *stats, *count;
    1976   Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1;
    1977   Pel *pOrg, *pRec;
    1978   UInt edgeType;
    1979   Int x, y;
    1980   Pel *pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    1981 
    1982   //--------- Band offset-----------//
    1983   stats = ppStats[SAO_BO];
    1984   count = ppCount[SAO_BO];
    1985   pOrg   = pOrgStart;
    1986   pRec   = pRecStart;
    1987   for (y=0; y< height; y++)
    1988   {
    1989     for (x=0; x< width; x++)
    1990     {
    1991       classIdx = pTableBo[pRec[x]];
    1992       if (classIdx)
    1993       {
    1994         stats[classIdx] += (pOrg[x] - pRec[x]);
    1995         count[classIdx] ++;
    1996       }
    1997     }
    1998     pOrg += stride;
    1999     pRec += stride;
    2000   }
    2001   //---------- Edge offset 0--------------//
    2002   stats = ppStats[SAO_EO_0];
    2003   count = ppCount[SAO_EO_0];
    2004   pOrg   = pOrgStart;
    2005   pRec   = pRecStart;
    2006 
    2007 
    2008   startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    2009   endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
    2010   for (y=0; y< height; y++)
    2011   {
    2012     signLeft = xSign(pRec[startX] - pRec[startX-1]);
    2013     for (x=startX; x< endX; x++)
    2014     {
    2015       signRight =  xSign(pRec[x] - pRec[x+1]);
    2016       edgeType =  signRight + signLeft + 2;
    2017       signLeft  = -signRight;
    2018 
    2019       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2020       count[m_auiEoTable[edgeType]] ++;
    2021     }
    2022     pRec  += stride;
    2023     pOrg += stride;
    2024   }
    2025 
    2026   //---------- Edge offset 1--------------//
    2027   stats = ppStats[SAO_EO_1];
    2028   count = ppCount[SAO_EO_1];
    2029   pOrg   = pOrgStart;
    2030   pRec   = pRecStart;
    2031 
    2032   startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
    2033   endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
    2034   if (!pbBorderAvail[SGU_T])
    2035   {
    2036     pRec  += stride;
    2037     pOrg  += stride;
    2038   }
    2039 
    2040   for (x=0; x< width; x++)
    2041   {
    2042     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
    2043   }
    2044   for (y=startY; y<endY; y++)
    2045   {
    2046     for (x=0; x< width; x++)
    2047     {
    2048       signDown     =  xSign(pRec[x] - pRec[x+stride]);
    2049       edgeType    =  signDown + m_iUpBuff1[x] + 2;
    2050       m_iUpBuff1[x] = -signDown;
    2051 
    2052       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2053       count[m_auiEoTable[edgeType]] ++;
    2054     }
    2055     pOrg += stride;
    2056     pRec += stride;
    2057   }
    2058   //---------- Edge offset 2--------------//
    2059   stats = ppStats[SAO_EO_2];
    2060   count = ppCount[SAO_EO_2];
    2061   pOrg   = pOrgStart;
    2062   pRec   = pRecStart;
    2063 
    2064   posShift= stride + 1;
    2065 
    2066   startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
    2067   endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
    2068 
    2069   //prepare 2nd line upper sign
    2070   pRec += stride;
    2071   for (x=startX; x< endX+1; x++)
    2072   {
    2073     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
    2074   }
    2075 
    2076   //1st line
    2077   pRec -= stride;
    2078   if(pbBorderAvail[SGU_TL])
    2079   {
    2080     x= 0;
    2081     edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    2082     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2083     count[m_auiEoTable[edgeType]] ++;
    2084   }
    2085   if(pbBorderAvail[SGU_T])
    2086   {
    2087     for(x= 1; x< endX; x++)
    2088     {
    2089       edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    2090       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2091       count[m_auiEoTable[edgeType]] ++;
    2092     }
    2093   }
    2094   pRec   += stride;
    2095   pOrg   += stride;
    2096 
    2097   //middle lines
    2098   for (y= 1; y< height-1; y++)
    2099   {
    2100     for (x=startX; x<endX; x++)
    2101     {
    2102       signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
    2103       edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    2104       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2105       count[m_auiEoTable[edgeType]] ++;
    2106 
    2107       m_iUpBufft[x+1] = -signDown1;
    2108     }
    2109     m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
    2110 
    2111     ipSwap     = m_iUpBuff1;
    2112     m_iUpBuff1 = m_iUpBufft;
    2113     m_iUpBufft = ipSwap;
    2114 
    2115     pRec  += stride;
    2116     pOrg  += stride;
    2117   }
    2118 
    2119   //last line
    2120   if(pbBorderAvail[SGU_B])
    2121   {
    2122     for(x= startX; x< width-1; x++)
    2123     {
    2124       edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    2125       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2126       count[m_auiEoTable[edgeType]] ++;
    2127     }
    2128   }
    2129   if(pbBorderAvail[SGU_BR])
    2130   {
    2131     x= width -1;
    2132     edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    2133     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2134     count[m_auiEoTable[edgeType]] ++;
    2135   }
    2136 
    2137   //---------- Edge offset 3--------------//
    2138 
    2139   stats = ppStats[SAO_EO_3];
    2140   count = ppCount[SAO_EO_3];
    2141   pOrg   = pOrgStart;
    2142   pRec   = pRecStart;
    2143 
    2144   posShift     = stride - 1;
    2145   startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    2146   endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
    2147 
    2148   //prepare 2nd line upper sign
    2149   pRec += stride;
    2150   for (x=startX-1; x< endX; x++)
    2151   {
    2152     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
    2153   }
    2154 
    2155 
    2156   //first line
    2157   pRec -= stride;
    2158   if(pbBorderAvail[SGU_T])
    2159   {
    2160     for(x= startX; x< width -1; x++)
    2161     {
    2162       edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    2163       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2164       count[m_auiEoTable[edgeType]] ++;
    2165     }
    2166   }
    2167   if(pbBorderAvail[SGU_TR])
    2168   {
    2169     x= width-1;
    2170     edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    2171     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2172     count[m_auiEoTable[edgeType]] ++;
    2173   }
    2174   pRec  += stride;
    2175   pOrg  += stride;
    2176 
    2177   //middle lines
    2178   for (y= 1; y< height-1; y++)
    2179   {
    2180     for(x= startX; x< endX; x++)
    2181     {
    2182       signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
    2183       edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    2184 
    2185       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2186       count[m_auiEoTable[edgeType]] ++;
    2187       m_iUpBuff1[x-1] = -signDown1;
    2188 
    2189     }
    2190     m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
    2191 
    2192     pRec  += stride;
    2193     pOrg  += stride;
    2194   }
    2195 
    2196   //last line
    2197   if(pbBorderAvail[SGU_BL])
    2198   {
    2199     x= 0;
    2200     edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    2201     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2202     count[m_auiEoTable[edgeType]] ++;
    2203 
    2204   }
    2205   if(pbBorderAvail[SGU_B])
    2206   {
    2207     for(x= 1; x< endX; x++)
    2208     {
    2209       edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    2210       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    2211       count[m_auiEoTable[edgeType]] ++;
    2212     }
    2213   }
    2214 }
    2215 
    2216 /** Calculate SAO statistics for current LCU
    2217  * \param  iAddr,  iPartIdx,  iYCbCr
    2218  */
    2219 Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr)
    2220 {
    2221   if(!m_bUseNIF)
    2222   {
    2223     calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr);
    2224   }
    2225   else
    2226   {
    2227     Int64** ppStats = m_iOffsetOrg[iPartIdx];
    2228     Int64** ppCount = m_iCount    [iPartIdx];
    2229 
    2230     //parameters
    2231     Int  isChroma = (iYCbCr != 0)? 1:0;
    2232     Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
    2233     Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr);
    2234     Pel* pPicRec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
    2235 
    2236     std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
    2237 
    2238     //variables
    2239     UInt  xPos, yPos, width, height;
    2240     Bool* pbBorderAvail;
    2241     UInt  posOffset;
    2242 
    2243     for(Int i=0; i< vFilterBlocks.size(); i++)
    2244     {
    2245       xPos        = vFilterBlocks[i].posX   >> isChroma;
    2246       yPos        = vFilterBlocks[i].posY   >> isChroma;
    2247       width       = vFilterBlocks[i].width  >> isChroma;
    2248       height      = vFilterBlocks[i].height >> isChroma;
    2249       pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
    2250 
    2251       posOffset = (yPos* stride) + xPos;
    2252 
    2253       calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail, iYCbCr);
    2254     }
    2255   }
    2256 
    2257 }
    2258 
    2259 /** Calculate SAO statistics for current LCU without non-crossing slice
    2260  * \param  iAddr,  iPartIdx,  iYCbCr
    2261  */
    2262 Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr)
    2263 {
    2264   Int x,y;
    2265   TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
    2266   TComSPS *pTmpSPS =  m_pcPic->getSlice(0)->getSPS();
    2267 
    2268   Pel* pOrg;
    2269   Pel* pRec;
    2270   Int iStride;
    2271   Int iLcuHeight = pTmpSPS->getMaxCUHeight();
    2272   Int iLcuWidth  = pTmpSPS->getMaxCUWidth();
    2273   UInt uiLPelX   = pTmpCu->getCUPelX();
    2274   UInt uiTPelY   = pTmpCu->getCUPelY();
    2275   UInt uiRPelX;
    2276   UInt uiBPelY;
    2277   Int64* iStats;
    2278   Int64* iCount;
    2279   Int iClassIdx;
    2280   Int iPicWidthTmp;
    2281   Int iPicHeightTmp;
    2282   Int iStartX;
    2283   Int iStartY;
    2284   Int iEndX;
    2285   Int iEndY;
    2286   Pel* pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    2287 
    2288   Int iIsChroma = (iYCbCr!=0)? 1:0;
    2289   Int numSkipLine = iIsChroma? 2:4;
    2290   if (m_saoLcuBasedOptimization == 0)
    2291   {
    2292     numSkipLine = 0;
    2293   }
    2294 
    2295   Int numSkipLineRight = iIsChroma? 3:5;
    2296   if (m_saoLcuBasedOptimization == 0)
    2297   {
    2298     numSkipLineRight = 0;
    2299   }
    2300 
    2301   iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
    2302   iPicHeightTmp = m_iPicHeight >> iIsChroma;
    2303   iLcuWidth     = iLcuWidth    >> iIsChroma;
    2304   iLcuHeight    = iLcuHeight   >> iIsChroma;
    2305   uiLPelX       = uiLPelX      >> iIsChroma;
    2306   uiTPelY       = uiTPelY      >> iIsChroma;
    2307   uiRPelX       = uiLPelX + iLcuWidth  ;
    2308   uiBPelY       = uiTPelY + iLcuHeight ;
    2309   uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
    2310   uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
    2311   iLcuWidth     = uiRPelX - uiLPelX;
    2312   iLcuHeight    = uiBPelY - uiTPelY;
    2313 
    2314   iStride    =  (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride();
    2315 
    2316 //if(iSaoType == BO_0 || iSaoType == BO_1)
    2317   {
    2318     if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    2319     {
    2320       numSkipLine = iIsChroma? 1:3;
    2321       numSkipLineRight = iIsChroma? 2:4;
    2322     }
    2323     iStats = m_iOffsetOrg[iPartIdx][SAO_BO];
    2324     iCount = m_iCount    [iPartIdx][SAO_BO];
    2325 
    2326     pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    2327     pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    2328 
    2329     iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
    2330     iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine;
    2331     for (y=0; y<iEndY; y++)
    2332     {
    2333       for (x=0; x<iEndX; x++)
    2334       {
    2335         iClassIdx = pTableBo[pRec[x]];
    2336         if (iClassIdx)
    2337         {
    2338           iStats[iClassIdx] += (pOrg[x] - pRec[x]);
    2339           iCount[iClassIdx] ++;
    2340         }
    2341       }
    2342       pOrg += iStride;
    2343       pRec += iStride;
    2344     }
    2345 
    2346   }
    2347   Int iSignLeft;
    2348   Int iSignRight;
    2349   Int iSignDown;
    2350   Int iSignDown1;
    2351   Int iSignDown2;
    2352 
    2353   UInt uiEdgeType;
    2354 
    2355 //if (iSaoType == EO_0  || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3)
    2356   {
    2357   //if (iSaoType == EO_0)
    2358     {
    2359       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    2360       {
    2361         numSkipLine = iIsChroma? 1:3;
    2362         numSkipLineRight = iIsChroma? 3:5;
    2363       }
    2364       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0];
    2365       iCount = m_iCount    [iPartIdx][SAO_EO_0];
    2366 
    2367       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    2368       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    2369 
    2370       iStartX = (uiLPelX == 0) ? 1 : 0;
    2371       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    2372       for (y=0; y<iLcuHeight-numSkipLine; y++)
    2373       {
    2374         iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]);
    2375         for (x=iStartX; x< iEndX; x++)
    2376         {
    2377           iSignRight =  xSign(pRec[x] - pRec[x+1]);
    2378           uiEdgeType =  iSignRight + iSignLeft + 2;
    2379           iSignLeft  = -iSignRight;
    2380 
    2381           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2382           iCount[m_auiEoTable[uiEdgeType]] ++;
    2383         }
    2384         pOrg += iStride;
    2385         pRec += iStride;
    2386       }
    2387     }
    2388 
    2389   //if (iSaoType == EO_1)
    2390     {
    2391       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    2392       {
    2393         numSkipLine = iIsChroma? 2:4;
    2394         numSkipLineRight = iIsChroma? 2:4;
    2395       }
    2396       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1];
    2397       iCount = m_iCount    [iPartIdx][SAO_EO_1];
    2398 
    2399       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    2400       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    2401 
    2402       iStartY = (uiTPelY == 0) ? 1 : 0;
    2403       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
    2404       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    2405       if (uiTPelY == 0)
    2406       {
    2407         pOrg += iStride;
    2408         pRec += iStride;
    2409       }
    2410 
    2411       for (x=0; x< iLcuWidth; x++)
    2412       {
    2413         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]);
    2414       }
    2415       for (y=iStartY; y<iEndY; y++)
    2416       {
    2417         for (x=0; x<iEndX; x++)
    2418         {
    2419           iSignDown     =  xSign(pRec[x] - pRec[x+iStride]);
    2420           uiEdgeType    =  iSignDown + m_iUpBuff1[x] + 2;
    2421           m_iUpBuff1[x] = -iSignDown;
    2422 
    2423           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2424           iCount[m_auiEoTable[uiEdgeType]] ++;
    2425         }
    2426         pOrg += iStride;
    2427         pRec += iStride;
    2428       }
    2429     }
    2430   //if (iSaoType == EO_2)
    2431     {
    2432       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    2433       {
    2434         numSkipLine = iIsChroma? 2:4;
    2435         numSkipLineRight = iIsChroma? 3:5;
    2436       }
    2437       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2];
    2438       iCount = m_iCount    [iPartIdx][SAO_EO_2];
    2439 
    2440       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    2441       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    2442 
    2443       iStartX = (uiLPelX == 0) ? 1 : 0;
    2444       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    2445 
    2446       iStartY = (uiTPelY == 0) ? 1 : 0;
    2447       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    2448       if (uiTPelY == 0)
    2449       {
    2450         pOrg += iStride;
    2451         pRec += iStride;
    2452       }
    2453 
    2454       for (x=iStartX; x<iEndX; x++)
    2455       {
    2456         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]);
    2457       }
    2458       for (y=iStartY; y<iEndY; y++)
    2459       {
    2460         iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]);
    2461         for (x=iStartX; x<iEndX; x++)
    2462         {
    2463           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
    2464           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    2465           m_iUpBufft[x+1] = -iSignDown1;
    2466           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2467           iCount[m_auiEoTable[uiEdgeType]] ++;
    2468         }
    2469         m_iUpBufft[iStartX] = iSignDown2;
    2470         ipSwap     = m_iUpBuff1;
    2471         m_iUpBuff1 = m_iUpBufft;
    2472         m_iUpBufft = ipSwap;
    2473 
    2474         pRec += iStride;
    2475         pOrg += iStride;
    2476       }
    2477     }
    2478   //if (iSaoType == EO_3  )
    2479     {
    2480       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    2481       {
    2482         numSkipLine = iIsChroma? 2:4;
    2483         numSkipLineRight = iIsChroma? 3:5;
    2484       }
    2485       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3];
    2486       iCount = m_iCount    [iPartIdx][SAO_EO_3];
    2487 
    2488       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    2489       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    2490 
    2491       iStartX = (uiLPelX == 0) ? 1 : 0;
    2492       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    2493 
    2494       iStartY = (uiTPelY == 0) ? 1 : 0;
    2495       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    2496       if (iStartY == 1)
    2497       {
    2498         pOrg += iStride;
    2499         pRec += iStride;
    2500       }
    2501 
    2502       for (x=iStartX-1; x<iEndX; x++)
    2503       {
    2504         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]);
    2505       }
    2506 
    2507       for (y=iStartY; y<iEndY; y++)
    2508       {
    2509         for (x=iStartX; x<iEndX; x++)
    2510         {
    2511           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
    2512           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    2513           m_iUpBuff1[x-1] = -iSignDown1;
    2514           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2515           iCount[m_auiEoTable[uiEdgeType]] ++;
    2516         }
    2517         m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
    2518 
    2519         pRec += iStride;
    2520         pOrg += iStride;
    2521       }
    2522     }
    2523   }
    2524 }
    2525 
    2526 
    2527 Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic )
    2528 {
    2529   Int addr, yCbCr;
    2530   Int x,y;
    2531   TComSPS *pTmpSPS =  pcPic->getSlice(0)->getSPS();
    2532 
    2533   Pel* pOrg;
    2534   Pel* pRec;
    2535   Int stride;
    2536   Int lcuHeight = pTmpSPS->getMaxCUHeight();
    2537   Int lcuWidth  = pTmpSPS->getMaxCUWidth();
    2538   UInt rPelX;
    2539   UInt bPelY;
    2540   Int64* stats;
    2541   Int64* count;
    2542   Int classIdx;
    2543   Int picWidthTmp = 0;
    2544   Int picHeightTmp = 0;
    2545   Int startX;
    2546   Int startY;
    2547   Int endX;
    2548   Int endY;
    2549   Int firstX, firstY;
    2550 
    2551   Int idxY;
    2552   Int idxX;
    2553   Int frameHeightInCU = m_iNumCuInHeight;
    2554   Int frameWidthInCU  = m_iNumCuInWidth;
    2555   Int j, k;
    2556 
    2557   Int isChroma;
    2558   Int numSkipLine, numSkipLineRight;
    2559 
    2560   UInt lPelX, tPelY;
    2561   TComDataCU *pTmpCu;
    2562   Pel* pTableBo;
    2563 
    2564   for (idxY = 0; idxY< frameHeightInCU; idxY++)
    2565   {
    2566     for (idxX = 0; idxX< frameWidthInCU; idxX++)
    2567     {
    2568       lcuHeight = pTmpSPS->getMaxCUHeight();
    2569       lcuWidth  = pTmpSPS->getMaxCUWidth();
    2570       addr     = idxX  + frameWidthInCU*idxY;
    2571       pTmpCu = pcPic->getCU(addr);
    2572       lPelX   = pTmpCu->getCUPelX();
    2573       tPelY   = pTmpCu->getCUPelY();
    2574       for( yCbCr = 0; yCbCr < 3; yCbCr++ )
    2575       {
    2576         isChroma = (yCbCr!=0)? 1:0;
    2577 
    2578         for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
    2579         {
    2580           for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
    2581           {
    2582             m_count_PreDblk    [addr][yCbCr][j][k] = 0;
    2583             m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0;
    2584           } 
    2585         }
    2586         if( yCbCr == 0 )
    2587         {
    2588           picWidthTmp  = m_iPicWidth;
    2589           picHeightTmp = m_iPicHeight;
    2590         }
    2591         else if( yCbCr == 1 )
    2592         {
    2593           picWidthTmp  = m_iPicWidth  >> isChroma;
    2594           picHeightTmp = m_iPicHeight >> isChroma;
    2595           lcuWidth     = lcuWidth    >> isChroma;
    2596           lcuHeight    = lcuHeight   >> isChroma;
    2597           lPelX       = lPelX      >> isChroma;
    2598           tPelY       = tPelY      >> isChroma;
    2599         }
    2600         rPelX       = lPelX + lcuWidth  ;
    2601         bPelY       = tPelY + lcuHeight ;
    2602         rPelX       = rPelX > picWidthTmp  ? picWidthTmp  : rPelX;
    2603         bPelY       = bPelY > picHeightTmp ? picHeightTmp : bPelY;
    2604         lcuWidth     = rPelX - lPelX;
    2605         lcuHeight    = bPelY - tPelY;
    2606 
    2607         stride    =  (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride();
    2608         pTableBo = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    2609 
    2610         //if(iSaoType == BO)
    2611 
    2612         numSkipLine = isChroma? 1:3;
    2613         numSkipLineRight = isChroma? 2:4;
    2614 
    2615         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO];
    2616         count = m_count_PreDblk[addr][yCbCr][SAO_BO];
    2617 
    2618         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    2619         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    2620 
    2621         startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
    2622         startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
    2623 
    2624         for (y=0; y<lcuHeight; y++)
    2625         {
    2626           for (x=0; x<lcuWidth; x++)
    2627           {
    2628             if( x < startX && y < startY )
    2629               continue;
    2630 
    2631             classIdx = pTableBo[pRec[x]];
    2632             if (classIdx)
    2633             {
    2634               stats[classIdx] += (pOrg[x] - pRec[x]);
    2635               count[classIdx] ++;
    2636             }
    2637           }
    2638           pOrg += stride;
    2639           pRec += stride;
    2640         }
    2641 
    2642         Int signLeft;
    2643         Int signRight;
    2644         Int signDown;
    2645         Int signDown1;
    2646         Int signDown2;
    2647 
    2648         UInt uiEdgeType;
    2649 
    2650         //if (iSaoType == EO_0)
    2651 
    2652         numSkipLine = isChroma? 1:3;
    2653         numSkipLineRight = isChroma? 3:5;
    2654 
    2655         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0];
    2656         count = m_count_PreDblk[addr][yCbCr][SAO_EO_0];
    2657 
    2658         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    2659         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    2660 
    2661         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    2662         startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
    2663         firstX   = (lPelX == 0) ? 1 : 0;
    2664         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    2665 
    2666         for (y=0; y<lcuHeight; y++)
    2667         {
    2668           signLeft = xSign(pRec[firstX] - pRec[firstX-1]);
    2669           for (x=firstX; x< endX; x++)
    2670           {
    2671             signRight =  xSign(pRec[x] - pRec[x+1]);
    2672             uiEdgeType =  signRight + signLeft + 2;
    2673             signLeft  = -signRight;
    2674 
    2675             if( x < startX && y < startY )
    2676               continue;
    2677 
    2678             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2679             count[m_auiEoTable[uiEdgeType]] ++;
    2680           }
    2681           pOrg += stride;
    2682           pRec += stride;
    2683         }
    2684 
    2685         //if (iSaoType == EO_1)
    2686 
    2687         numSkipLine = isChroma? 2:4;
    2688         numSkipLineRight = isChroma? 2:4;
    2689 
    2690         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1];
    2691         count = m_count_PreDblk[addr][yCbCr][SAO_EO_1];
    2692 
    2693         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    2694         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    2695 
    2696         startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
    2697         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    2698         firstY = (tPelY == 0) ? 1 : 0;
    2699         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    2700         if (firstY == 1)
    2701         {
    2702           pOrg += stride;
    2703           pRec += stride;
    2704         }
    2705 
    2706         for (x=0; x< lcuWidth; x++)
    2707         {
    2708           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
    2709         }
    2710         for (y=firstY; y<endY; y++)
    2711         {
    2712           for (x=0; x<lcuWidth; x++)
    2713           {
    2714             signDown     =  xSign(pRec[x] - pRec[x+stride]);
    2715             uiEdgeType    =  signDown + m_iUpBuff1[x] + 2;
    2716             m_iUpBuff1[x] = -signDown;
    2717 
    2718             if( x < startX && y < startY )
    2719               continue;
    2720 
    2721             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2722             count[m_auiEoTable[uiEdgeType]] ++;
    2723           }
    2724           pOrg += stride;
    2725           pRec += stride;
    2726         }
    2727 
    2728         //if (iSaoType == EO_2)
    2729 
    2730         numSkipLine = isChroma? 2:4;
    2731         numSkipLineRight = isChroma? 3:5;
    2732 
    2733         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2];
    2734         count = m_count_PreDblk[addr][yCbCr][SAO_EO_2];
    2735 
    2736         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    2737         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    2738 
    2739         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    2740         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    2741         firstX   = (lPelX == 0) ? 1 : 0;
    2742         firstY = (tPelY == 0) ? 1 : 0;
    2743         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    2744         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    2745         if (firstY == 1)
    2746         {
    2747           pOrg += stride;
    2748           pRec += stride;
    2749         }
    2750 
    2751         for (x=firstX; x<endX; x++)
    2752         {
    2753           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]);
    2754         }
    2755         for (y=firstY; y<endY; y++)
    2756         {
    2757           signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]);
    2758           for (x=firstX; x<endX; x++)
    2759           {
    2760             signDown1      =  xSign(pRec[x] - pRec[x+stride+1]) ;
    2761             uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    2762             m_iUpBufft[x+1] = -signDown1;
    2763 
    2764             if( x < startX && y < startY )
    2765               continue;
    2766 
    2767             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2768             count[m_auiEoTable[uiEdgeType]] ++;
    2769           }
    2770           m_iUpBufft[firstX] = signDown2;
    2771           ipSwap     = m_iUpBuff1;
    2772           m_iUpBuff1 = m_iUpBufft;
    2773           m_iUpBufft = ipSwap;
    2774 
    2775           pRec += stride;
    2776           pOrg += stride;
    2777         }
    2778 
    2779         //if (iSaoType == EO_3)
    2780 
    2781         numSkipLine = isChroma? 2:4;
    2782         numSkipLineRight = isChroma? 3:5;
    2783 
    2784         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3];
    2785         count = m_count_PreDblk[addr][yCbCr][SAO_EO_3];
    2786 
    2787         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    2788         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    2789 
    2790         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    2791         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    2792         firstX   = (lPelX == 0) ? 1 : 0;
    2793         firstY = (tPelY == 0) ? 1 : 0;
    2794         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    2795         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    2796         if (firstY == 1)
    2797         {
    2798           pOrg += stride;
    2799           pRec += stride;
    2800         }
    2801 
    2802         for (x=firstX-1; x<endX; x++)
    2803         {
    2804           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]);
    2805         }
    2806 
    2807         for (y=firstY; y<endY; y++)
    2808         {
    2809           for (x=firstX; x<endX; x++)
    2810           {
    2811             signDown1      =  xSign(pRec[x] - pRec[x+stride-1]) ;
    2812             uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    2813             m_iUpBuff1[x-1] = -signDown1;
    2814 
    2815             if( x < startX && y < startY )
    2816               continue;
    2817 
    2818             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    2819             count[m_auiEoTable[uiEdgeType]] ++;
    2820           }
    2821           m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
    2822 
    2823           pRec += stride;
    2824           pOrg += stride;
    2825         }
    2826       }
    2827     }
    2828   }
    2829 }
    2830 
    2831 
    2832 /** get SAO statistics
    2833  * \param  *psQTPart,  iYCbCr
    2834  */
    2835 Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr)
    2836 {
    2837   Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx;
    2838   Int i;
    2839   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    2840   Int LcuIdxX;
    2841   Int LcuIdxY;
    2842   Int iAddr;
    2843   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    2844   Int iDownPartIdx;
    2845   Int iPartStart;
    2846   Int iPartEnd;
    2847   SAOQTPart*  pOnePart;
    2848 
    2849   if (m_uiMaxSplitLevel == 0)
    2850   {
    2851     iPartIdx = 0;
    2852     pOnePart = &(psQTPart[iPartIdx]);
    2853     for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
    2854     {
    2855       for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
    2856       {
    2857         iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    2858         calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
    2859       }
    2860     }
    2861   }
    2862   else
    2863   {
    2864     for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++)
    2865     {
    2866       pOnePart = &(psQTPart[iPartIdx]);
    2867       for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
    2868       {
    2869         for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
    2870         {
    2871           iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    2872           calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
    2873         }
    2874       }
    2875     }
    2876     for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- )
    2877     {
    2878       iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0;
    2879       iPartEnd   = m_aiNumCulPartsLevel[iLevelIdx];
    2880 
    2881       for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++)
    2882       {
    2883         pOnePart = &(psQTPart[iPartIdx]);
    2884         for (i=0; i< NUM_DOWN_PART; i++)
    2885         {
    2886           iDownPartIdx = pOnePart->DownPartsIdx[i];
    2887           for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++)
    2888           {
    2889             for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++)
    2890             {
    2891               m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx];
    2892               m_iCount [iPartIdx][iTypeIdx][iClassIdx]    += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx];
    2893             }
    2894           }
    2895         }
    2896       }
    2897     }
    2898   }
    2899 }
    2900 
    2901 /** reset offset statistics
    2902  * \param
    2903  */
    2904 Void TEncSampleAdaptiveOffset::resetStats()
    2905 {
    2906   for (Int i=0;i<m_iNumTotalParts;i++)
    2907   {
    2908     m_dCostPartBest[i] = MAX_DOUBLE;
    2909     m_iTypePartBest[i] = -1;
    2910     m_iDistOrg[i] = 0;
    2911     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    2912     {
    2913       m_iDist[i][j] = 0;
    2914       m_iRate[i][j] = 0;
    2915       m_dCost[i][j] = 0;
    2916       for (Int k=0;k<MAX_NUM_SAO_CLASS;k++)
    2917       {
    2918         m_iCount [i][j][k] = 0;
    2919         m_iOffset[i][j][k] = 0;
    2920         m_iOffsetOrg[i][j][k] = 0;
    2921       } 
    2922     }
    2923   }
    2924 }
    2925 
    2926 /** Sample adaptive offset process
    2927  * \param pcSaoParam
    2928  * \param dLambdaLuma
    2929  * \param dLambdaChroma
    2930  */
    2931 #if SAO_ENCODING_CHOICE
    2932 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth)
    2933 #else
    2934 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
    2935 #endif
    2936 {
    2937   if(m_bUseNIF)
    2938   {
    2939     m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
    2940   }
    2941 
    2942   m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0);
    2943   m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0);
    2944   m_iOffsetThY = 1 << min(g_bitDepthY - 5, 5);
    2945   m_iOffsetThC = 1 << min(g_bitDepthC - 5, 5);
    2946   resetSAOParam(pcSaoParam);
    2947   if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary )
    2948   {
    2949     resetStats();
    2950   }
    2951   Double dCostFinal = 0;
    2952   if ( m_saoLcuBasedOptimization)
    2953   {
    2954 #if SAO_ENCODING_CHOICE
    2955     rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth);
    2956 #else
    2957     rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma);
    2958 #endif
    2959   }
    2960   else
    2961   {
    2962     pcSaoParam->bSaoFlag[0] = 1;
    2963     pcSaoParam->bSaoFlag[1] = 0;
    2964     dCostFinal = 0;
    2965     Double lambdaRdo =  dLambdaLuma;
    2966     resetStats();
    2967     getSaoStats(pcSaoParam->psSaoPart[0], 0);
    2968     runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0);
    2969     pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0;
    2970     if(pcSaoParam->bSaoFlag[0])
    2971     {
    2972       convertQT2SaoUnit(pcSaoParam, 0, 0);
    2973       assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0],  pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0);
    2974     }
    2975   }
    2976   if (pcSaoParam->bSaoFlag[0])
    2977   {
    2978     processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0);
    2979   }
    2980   if (pcSaoParam->bSaoFlag[1])
    2981   {
    2982     processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);
    2983     processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);
    2984   }
    2985 }
    2986 /** Check merge SAO unit
    2987  * \param saoUnitCurr current SAO unit
    2988  * \param saoUnitCheck SAO unit tobe check
    2989  * \param dir direction
    2990  */
    2991 Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir)
    2992 {
    2993   Int i ;
    2994   Int countDiff = 0;
    2995   if (saoUnitCurr->partIdx != saoUnitCheck->partIdx)
    2996   {
    2997     if (saoUnitCurr->typeIdx !=-1)
    2998     {
    2999       if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
    3000       {
    3001         for (i=0;i<saoUnitCurr->length;i++)
    3002         {
    3003           countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]);
    3004         }
    3005         countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx);
    3006         if (countDiff ==0)
    3007         {
    3008           saoUnitCurr->partIdx = saoUnitCheck->partIdx;
    3009           if (dir == 1)
    3010           {
    3011             saoUnitCurr->mergeUpFlag = 1;
    3012             saoUnitCurr->mergeLeftFlag = 0;
    3013           }
    3014           else
    3015           {
    3016             saoUnitCurr->mergeUpFlag = 0;
    3017             saoUnitCurr->mergeLeftFlag = 1;
    3018           }
    3019         }
    3020       }
    3021     }
    3022     else
    3023     {
    3024       if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
    3025       {
    3026         saoUnitCurr->partIdx = saoUnitCheck->partIdx;
    3027         if (dir == 1)
    3028         {
    3029           saoUnitCurr->mergeUpFlag = 1;
    3030           saoUnitCurr->mergeLeftFlag = 0;
    3031         }
    3032         else
    3033         {
    3034           saoUnitCurr->mergeUpFlag = 0;
    3035           saoUnitCurr->mergeLeftFlag = 1;
    3036         }
    3037       }
    3038     }
    3039   }
    3040 }
    3041 /** Assign SAO unit syntax from picture-based algorithm
    3042  * \param saoLcuParam SAO LCU parameters
    3043  * \param saoPart SAO part
    3044  * \param oneUnitFlag SAO one unit flag
    3045  * \param iYCbCr color component Index
    3046  */
    3047 Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr)
    3048 {
    3049   if (saoPart->bSplit == 0)
    3050   {
    3051     oneUnitFlag = 1;
    3052   }
    3053   else
    3054   {
    3055     Int i,j, addr, addrUp, addrLeft,  idx, idxUp, idxLeft,  idxCount;
    3056 
    3057     oneUnitFlag = 0;
    3058 
    3059     idxCount = -1;
    3060     saoLcuParam[0].mergeUpFlag = 0;
    3061     saoLcuParam[0].mergeLeftFlag = 0;
    3062 
    3063     for (j=0;j<m_iNumCuInHeight;j++)
    3064     {
    3065       for (i=0;i<m_iNumCuInWidth;i++)
    3066       {
    3067         addr     = i + j*m_iNumCuInWidth;
    3068         addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1;
    3069         addrUp   = (addr<m_iNumCuInWidth)      ? -1 : addr - m_iNumCuInWidth;
    3070         idx      = saoLcuParam[addr].partIdxTmp;
    3071         idxLeft  = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp;
    3072         idxUp    = (addrUp == -1)   ? -1 : saoLcuParam[addrUp].partIdxTmp;
    3073 
    3074         if(idx!=idxLeft && idx!=idxUp)
    3075         {
    3076           saoLcuParam[addr].mergeUpFlag   = 0; idxCount++;
    3077           saoLcuParam[addr].mergeLeftFlag = 0;
    3078           saoLcuParam[addr].partIdx = idxCount;
    3079         }
    3080         else if (idx==idxLeft)
    3081         {
    3082           saoLcuParam[addr].mergeUpFlag   = 1;
    3083           saoLcuParam[addr].mergeLeftFlag = 1;
    3084           saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx;
    3085         }
    3086         else if (idx==idxUp)
    3087         {
    3088           saoLcuParam[addr].mergeUpFlag   = 1;
    3089           saoLcuParam[addr].mergeLeftFlag = 0;
    3090           saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx;
    3091         }
    3092         if (addrUp != -1)
    3093         {
    3094           checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1);
    3095         }
    3096         if (addrLeft != -1)
    3097         {
    3098           checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0);
    3099         }
    3100       }
    3101     }
    3102   }
    3103 }
    3104 /** rate distortion optimization of all SAO units
    3105  * \param saoParam SAO parameters
    3106  * \param lambda
    3107  * \param lambdaChroma
    3108  */
    3109 #if SAO_ENCODING_CHOICE
    3110 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth)
    3111 #else
    3112 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma)
    3113 #endif
    3114 {
    3115 
    3116   Int idxY;
    3117   Int idxX;
    3118   Int frameHeightInCU = saoParam->numCuInHeight;
    3119   Int frameWidthInCU  = saoParam->numCuInWidth;
    3120   Int j, k;
    3121   Int addr = 0;
    3122   Int addrUp = -1;
    3123   Int addrLeft = -1;
    3124   Int compIdx = 0;
    3125   SaoLcuParam mergeSaoParam[3][2];
    3126   Double compDistortion[3];
    3127 
    3128   saoParam->bSaoFlag[0] = true;
    3129 #if AUXILIARY_PICTURES
    3130   saoParam->bSaoFlag[1] = m_pcPic->getChromaFormat() == CHROMA_400 ? false : true;
    3131 #else
    3132   saoParam->bSaoFlag[1] = true;
    3133 #endif
    3134   saoParam->oneUnitFlag[0] = false;
    3135   saoParam->oneUnitFlag[1] = false;
    3136   saoParam->oneUnitFlag[2] = false;
    3137 
    3138 #if SAO_ENCODING_CHOICE
    3139 #if SAO_ENCODING_CHOICE_CHROMA
    3140   Int numNoSao[2];
    3141   numNoSao[0] = 0;// Luma
    3142   numNoSao[1] = 0;// Chroma
    3143   if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE )
    3144   {
    3145     saoParam->bSaoFlag[0] = false;
    3146   }
    3147   if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA )
    3148   {
    3149     saoParam->bSaoFlag[1] = false;
    3150   }
    3151 #else
    3152   Int numNoSao = 0;
    3153 
    3154   if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE )
    3155   {
    3156     saoParam->bSaoFlag[0] = false;
    3157     saoParam->bSaoFlag[1] = false;
    3158   }
    3159 #endif
    3160 #endif
    3161 
    3162   for (idxY = 0; idxY< frameHeightInCU; idxY++)
    3163   {
    3164     for (idxX = 0; idxX< frameWidthInCU; idxX++)
    3165     {
    3166       addr     = idxX  + frameWidthInCU*idxY;
    3167       addrUp   = addr < frameWidthInCU ? -1:idxX   + frameWidthInCU*(idxY-1);
    3168       addrLeft = idxX == 0               ? -1:idxX-1 + frameWidthInCU*idxY;
    3169       Int allowMergeLeft = 1;
    3170       Int allowMergeUp   = 1;
    3171       UInt rate;
    3172       Double bestCost, mergeCost;
    3173       if (idxX!=0)
    3174       {
    3175         // check tile id and slice id
    3176         if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    3177         {
    3178           allowMergeLeft = 0;
    3179         }
    3180       }
    3181       else
    3182       {
    3183         allowMergeLeft = 0;
    3184       }
    3185       if (idxY!=0)
    3186       {
    3187         if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx()))
    3188         {
    3189           allowMergeUp = 0;
    3190         }
    3191       }
    3192       else
    3193       {
    3194         allowMergeUp = 0;
    3195       }
    3196 
    3197       compDistortion[0] = 0;
    3198       compDistortion[1] = 0;
    3199       compDistortion[2] = 0;
    3200       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    3201       if (allowMergeLeft)
    3202       {
    3203         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    3204       }
    3205       if (allowMergeUp)
    3206       {
    3207         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    3208       }
    3209       m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    3210       // reset stats Y, Cb, Cr
    3211       for ( compIdx=0;compIdx<3;compIdx++)
    3212       {
    3213         for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
    3214         {
    3215           for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
    3216           {
    3217             m_iOffset   [compIdx][j][k] = 0;
    3218             if( m_saoLcuBasedOptimization && m_saoLcuBoundary ){
    3219               m_iCount    [compIdx][j][k] = m_count_PreDblk    [addr][compIdx][j][k];
    3220               m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k];
    3221             }
    3222             else
    3223             {
    3224               m_iCount    [compIdx][j][k] = 0;
    3225               m_iOffsetOrg[compIdx][j][k] = 0;
    3226             }
    3227           } 
    3228         }
    3229         saoParam->saoLcuParam[compIdx][addr].typeIdx       =  -1;
    3230         saoParam->saoLcuParam[compIdx][addr].mergeUpFlag   = 0;
    3231         saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0;
    3232         saoParam->saoLcuParam[compIdx][addr].subTypeIdx    = 0;
    3233 #if SAO_ENCODING_CHOICE
    3234   if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) )
    3235 #endif
    3236         {
    3237           calcSaoStatsCu(addr, compIdx,  compIdx);
    3238 
    3239        }
    3240       }
    3241       saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0,  lambda, &mergeSaoParam[0][0], &compDistortion[0]);
    3242       sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]);
    3243      if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    3244       {
    3245         // Cost of new SAO_params
    3246         m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    3247         m_pcRDGoOnSbacCoder->resetBits();
    3248         if (allowMergeLeft)
    3249         {
    3250           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    3251         }
    3252         if (allowMergeUp)
    3253         {
    3254           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    3255         }
    3256         for ( compIdx=0;compIdx<3;compIdx++)
    3257         {
    3258         if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1]))
    3259           {
    3260            m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    3261           }
    3262         }
    3263 
    3264         rate = m_pcEntropyCoder->getNumberOfWrittenBits();
    3265         bestCost = compDistortion[0] + (Double)rate;
    3266         m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3267 
    3268         // Cost of Merge
    3269         for(Int mergeUp=0; mergeUp<2; ++mergeUp)
    3270         {
    3271           if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) )
    3272           {
    3273             m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    3274             m_pcRDGoOnSbacCoder->resetBits();
    3275             if (allowMergeLeft)
    3276             {
    3277               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp);
    3278             }
    3279             if ( allowMergeUp && (mergeUp==1) )
    3280             {
    3281               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1);
    3282             }
    3283 
    3284             rate = m_pcEntropyCoder->getNumberOfWrittenBits();
    3285             mergeCost = compDistortion[mergeUp+1] + (Double)rate;
    3286             if (mergeCost < bestCost)
    3287             {
    3288               bestCost = mergeCost;
    3289               m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);             
    3290               for ( compIdx=0;compIdx<3;compIdx++)
    3291               {
    3292                 mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp;
    3293                 mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp;
    3294                 if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1]))
    3295                 {
    3296                   copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] );             
    3297                 }
    3298               }
    3299             }
    3300           }
    3301         }
    3302 #if SAO_ENCODING_CHOICE
    3303 #if SAO_ENCODING_CHOICE_CHROMA
    3304 if( saoParam->saoLcuParam[0][addr].typeIdx == -1)
    3305 {
    3306   numNoSao[0]++;
    3307 }
    3308 if( saoParam->saoLcuParam[1][addr].typeIdx == -1)
    3309 {
    3310   numNoSao[1]+=2;
    3311 }
    3312 #else
    3313         for ( compIdx=0;compIdx<3;compIdx++)
    3314         {
    3315           if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1)
    3316           {
    3317             numNoSao++;
    3318           }
    3319         }
    3320 #endif
    3321 #endif
    3322         m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3323         m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    3324       }
    3325     }
    3326   }
    3327 #if SAO_ENCODING_CHOICE
    3328 #if SAO_ENCODING_CHOICE_CHROMA
    3329   if( !saoParam->bSaoFlag[0])
    3330   {
    3331     m_depthSaoRate[0][depth] = 1.0;
    3332   }
    3333   else
    3334   {
    3335     m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
    3336   }
    3337   if( !saoParam->bSaoFlag[1])
    3338   {
    3339     m_depthSaoRate[1][depth] = 1.0;
    3340   }
    3341   else
    3342   {
    3343     m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
    3344   }
    3345 #else
    3346   if( depth == 0)
    3347   {
    3348     // update SAO Rate
    3349     m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3);
    3350   }
    3351 #endif
    3352 #endif
    3353 
    3354 }
    3355 /** rate distortion optimization of SAO unit
    3356  * \param saoParam SAO parameters
    3357  * \param addr address
    3358  * \param addrUp above address
    3359  * \param addrLeft left address
    3360  * \param yCbCr color component index
    3361  * \param lambda
    3362  */
    3363 inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo)
    3364 {
    3365   Int64 estDist = 0;
    3366   Int classIdx;
    3367   Int bitDepth = (compIdx==0) ? g_bitDepthY : g_bitDepthC;
    3368   Int saoBitIncrease = (compIdx==0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC;
    3369   Int saoOffsetTh = (compIdx==0) ? m_iOffsetThY : m_iOffsetThC;
    3370 
    3371   for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ?  m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++)
    3372   {
    3373     if( typeIdx == SAO_BO)
    3374     {
    3375       currentDistortionTableBo[classIdx-1] = 0;
    3376       currentRdCostTableBo[classIdx-1] = lambda;
    3377     }
    3378     if(m_iCount [compIdx][typeIdx][classIdx])
    3379     {
    3380       m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi(bitDepth, (Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<(bitDepth-8)) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<saoBitIncrease));
    3381       m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-saoOffsetTh+1, saoOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]);
    3382       if (typeIdx < 4)
    3383       {
    3384         if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 )
    3385         {
    3386           m_iOffset[compIdx][typeIdx][classIdx] = 0;
    3387         }
    3388         if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3)
    3389         {
    3390           m_iOffset[compIdx][typeIdx][classIdx] = 0;
    3391         }
    3392       }
    3393       m_iOffset[compIdx][typeIdx][classIdx] = estIterOffset( typeIdx, classIdx, lambda, m_iOffset[compIdx][typeIdx][classIdx], m_iCount [compIdx][typeIdx][classIdx], m_iOffsetOrg[compIdx][typeIdx][classIdx], shift, saoBitIncrease, currentDistortionTableBo, currentRdCostTableBo, saoOffsetTh );
    3394     }
    3395     else
    3396     {
    3397       m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0;
    3398       m_iOffset[compIdx][typeIdx][classIdx] = 0;
    3399     }
    3400     if( typeIdx != SAO_BO )
    3401     {
    3402       estDist   += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << saoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift);
    3403     }
    3404 
    3405   }
    3406   return estDist;
    3407 }
    3408 
    3409 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift)
    3410 {
    3411   return (( count*offset*offset-offsetOrg*offset*2 ) >> shift);
    3412 }
    3413 inline Int64 TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh )
    3414 {
    3415   //Clean up, best_q_offset.
    3416   Int64 iterOffset, tempOffset;
    3417   Int64 tempDist, tempRate;
    3418   Double tempCost, tempMinCost;
    3419   Int64 offsetOutput = 0;
    3420   iterOffset = offsetInput;
    3421   // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
    3422   tempMinCost = lambda;
    3423   while (iterOffset != 0)
    3424   {
    3425     // Calculate the bits required for signalling the offset
    3426     tempRate = (typeIdx == SAO_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
    3427     if (abs((Int)iterOffset)==offsetTh-1)
    3428     { 
    3429       tempRate --;
    3430     }
    3431     // Do the dequntization before distorion calculation
    3432     tempOffset  = iterOffset << bitIncrease;
    3433     tempDist    = estSaoDist( count, tempOffset, offsetOrg, shift);
    3434     tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
    3435     if(tempCost < tempMinCost)
    3436     {
    3437       tempMinCost = tempCost;
    3438       offsetOutput = iterOffset;
    3439       if(typeIdx == SAO_BO)
    3440       {
    3441         currentDistortionTableBo[classIdx-1] = (Int) tempDist;
    3442         currentRdCostTableBo[classIdx-1] = tempCost;
    3443       }
    3444     }
    3445     iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
    3446   }
    3447   return offsetOutput;
    3448 }
    3449 
    3450 
    3451 Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion)
    3452 {
    3453   Int typeIdx;
    3454 
    3455   Int64 estDist;
    3456   Int classIdx;
    3457   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(((yCbCr==0)?g_bitDepthY:g_bitDepthC)-8);
    3458   Int64 bestDist;
    3459 
    3460   SaoLcuParam*  saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]);
    3461   SaoLcuParam*  saoLcuParamNeighbor = NULL;
    3462 
    3463   resetSaoUnit(saoLcuParam);
    3464   resetSaoUnit(&compSaoParam[0]);
    3465   resetSaoUnit(&compSaoParam[1]);
    3466 
    3467 
    3468   Double dCostPartBest = MAX_DOUBLE;
    3469 
    3470   Double  bestRDCostTableBo = MAX_DOUBLE;
    3471   Int     bestClassTableBo    = 0;
    3472   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    3473   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    3474 
    3475 
    3476   SaoLcuParam   saoLcuParamRdo;   
    3477   Double   estRate = 0;
    3478 
    3479   resetSaoUnit(&saoLcuParamRdo);
    3480 
    3481   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3482   m_pcRDGoOnSbacCoder->resetBits();
    3483  m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
    3484  
    3485   dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
    3486   copySaoUnit(saoLcuParam, &saoLcuParamRdo );
    3487   bestDist = 0;
    3488  
    3489 
    3490 
    3491   for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
    3492   {
    3493     estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    3494 
    3495     if( typeIdx == SAO_BO )
    3496     {
    3497       // Estimate Best Position
    3498       Double currentRDCost = 0.0;
    3499 
    3500       for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    3501       {
    3502         currentRDCost = 0.0;
    3503         for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    3504         {
    3505           currentRDCost += currentRdCostTableBo[uj];
    3506         }
    3507 
    3508         if( currentRDCost < bestRDCostTableBo)
    3509         {
    3510           bestRDCostTableBo = currentRDCost;
    3511           bestClassTableBo  = i;
    3512         }
    3513       }
    3514 
    3515       // Re code all Offsets
    3516       // Code Center
    3517       estDist = 0;
    3518       for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++)
    3519       {
    3520         estDist += currentDistortionTableBo[classIdx];
    3521       }
    3522     }
    3523     resetSaoUnit(&saoLcuParamRdo);
    3524     saoLcuParamRdo.length = m_iNumClass[typeIdx];
    3525     saoLcuParamRdo.typeIdx = typeIdx;
    3526     saoLcuParamRdo.mergeLeftFlag = 0;
    3527     saoLcuParamRdo.mergeUpFlag   = 0;
    3528     saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0;
    3529     for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++)
    3530     {
    3531       saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1];
    3532     }
    3533     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3534     m_pcRDGoOnSbacCoder->resetBits();
    3535     m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
    3536 
    3537     estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    3538     m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate);
    3539 
    3540     if(m_dCost[yCbCr][typeIdx] < dCostPartBest)
    3541     {
    3542       dCostPartBest = m_dCost[yCbCr][typeIdx];
    3543       copySaoUnit(saoLcuParam, &saoLcuParamRdo );
    3544       bestDist = estDist;       
    3545     }
    3546   }
    3547   compDistortion[0] += ((Double)bestDist/lambda);
    3548   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3549  m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr);
    3550   m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    3551 
    3552 
    3553   // merge left or merge up
    3554 
    3555   for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
    3556   {
    3557     saoLcuParamNeighbor = NULL;
    3558     if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
    3559     {
    3560       saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]);
    3561     }
    3562     else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
    3563     {
    3564       saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]);
    3565     }
    3566     if (saoLcuParamNeighbor!=NULL)
    3567     {
    3568       estDist = 0;
    3569       typeIdx = saoLcuParamNeighbor->typeIdx;
    3570       if (typeIdx>=0)
    3571       {
    3572         Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0;
    3573         Int   merge_iOffset;
    3574         for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
    3575         {
    3576           merge_iOffset = saoLcuParamNeighbor->offset[classIdx];
    3577           estDist   += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1],  shift);
    3578         }
    3579       }
    3580       else
    3581       {
    3582         estDist = 0;
    3583       }
    3584 
    3585       copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor );
    3586       compSaoParam[idxNeighbor].mergeUpFlag   = idxNeighbor;
    3587       compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor;
    3588 
    3589       compDistortion[idxNeighbor+1] += ((Double)estDist/lambda);
    3590     }
    3591   }
    3592 }
    3593 Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion)
    3594 {
    3595   Int typeIdx;
    3596 
    3597   Int64 estDist[2];
    3598   Int classIdx;
    3599   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8);
    3600   Int64 bestDist = 0;
    3601 
    3602   SaoLcuParam*  saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])};
    3603   SaoLcuParam*  saoLcuParamNeighbor[2] = {NULL, NULL};
    3604   SaoLcuParam*  saoMergeParam[2][2];
    3605   saoMergeParam[0][0] = &crSaoParam[0];
    3606   saoMergeParam[0][1] = &crSaoParam[1];
    3607   saoMergeParam[1][0] = &cbSaoParam[0];
    3608   saoMergeParam[1][1] = &cbSaoParam[1];
    3609 
    3610   resetSaoUnit(saoLcuParam[0]);
    3611   resetSaoUnit(saoLcuParam[1]);
    3612   resetSaoUnit(saoMergeParam[0][0]);
    3613   resetSaoUnit(saoMergeParam[0][1]);
    3614   resetSaoUnit(saoMergeParam[1][0]);
    3615   resetSaoUnit(saoMergeParam[1][1]);
    3616 
    3617 
    3618   Double costPartBest = MAX_DOUBLE;
    3619 
    3620   Double  bestRDCostTableBo;
    3621   Int     bestClassTableBo[2]    = {0, 0};
    3622   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    3623   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    3624 
    3625   SaoLcuParam   saoLcuParamRdo[2];   
    3626   Double   estRate = 0;
    3627 
    3628   resetSaoUnit(&saoLcuParamRdo[0]);
    3629   resetSaoUnit(&saoLcuParamRdo[1]);
    3630 
    3631   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3632   m_pcRDGoOnSbacCoder->resetBits();
    3633   m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1);
    3634   m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2);
    3635  
    3636   costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
    3637   copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
    3638   copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
    3639 
    3640   for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
    3641   {
    3642     if( typeIdx == SAO_BO )
    3643     {
    3644       // Estimate Best Position
    3645       for(Int compIdx = 0; compIdx < 2; compIdx++)
    3646       {
    3647         Double currentRDCost = 0.0;
    3648         bestRDCostTableBo = MAX_DOUBLE;
    3649         estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    3650         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    3651         {
    3652           currentRDCost = 0.0;
    3653           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    3654           {
    3655             currentRDCost += currentRdCostTableBo[uj];
    3656           }
    3657 
    3658           if( currentRDCost < bestRDCostTableBo)
    3659           {
    3660             bestRDCostTableBo = currentRDCost;
    3661             bestClassTableBo[compIdx]  = i;
    3662           }
    3663         }
    3664 
    3665         // Re code all Offsets
    3666         // Code Center
    3667         estDist[compIdx] = 0;
    3668         for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++)
    3669         {
    3670           estDist[compIdx] += currentDistortionTableBo[classIdx];
    3671         }
    3672       }
    3673     }
    3674     else
    3675     {
    3676       estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    3677       estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    3678     }
    3679 
    3680     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3681     m_pcRDGoOnSbacCoder->resetBits();
    3682 
    3683     for(Int compIdx = 0; compIdx < 2; compIdx++)
    3684     {
    3685       resetSaoUnit(&saoLcuParamRdo[compIdx]);
    3686       saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx];
    3687       saoLcuParamRdo[compIdx].typeIdx = typeIdx;
    3688       saoLcuParamRdo[compIdx].mergeLeftFlag = 0;
    3689       saoLcuParamRdo[compIdx].mergeUpFlag   = 0;
    3690       saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0;
    3691       for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++)
    3692       {
    3693         saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1];
    3694       }
    3695 
    3696       m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1);
    3697     }
    3698     estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    3699     m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1])  + lambda * (Double) estRate);
    3700    
    3701     if(m_dCost[1][typeIdx] < costPartBest)
    3702     {
    3703       costPartBest = m_dCost[1][typeIdx];
    3704       copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
    3705       copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
    3706       bestDist = (estDist[0]+estDist[1]);       
    3707     }
    3708   }
    3709 
    3710   distortion[0] += ((Double)bestDist/lambda);
    3711   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    3712   m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1);
    3713   m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2);
    3714   m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    3715 
    3716   // merge left or merge up
    3717 
    3718   for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
    3719   {
    3720     for(Int compIdx = 0; compIdx < 2; compIdx++)
    3721     {
    3722       saoLcuParamNeighbor[compIdx] = NULL;
    3723       if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
    3724       {
    3725         saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]);
    3726       }
    3727       else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
    3728       {
    3729         saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]);
    3730       }
    3731       if (saoLcuParamNeighbor[compIdx]!=NULL)
    3732       {
    3733         estDist[compIdx] = 0;
    3734         typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx;
    3735         if (typeIdx>=0)
    3736         {
    3737           Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0;
    3738           Int   merge_iOffset;
    3739           for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
    3740           {
    3741             merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx];
    3742             estDist[compIdx]   += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1],  shift);
    3743           }
    3744         }
    3745         else
    3746         {
    3747           estDist[compIdx] = 0;
    3748         }
    3749 
    3750         copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] );
    3751         saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag   = idxNeighbor;
    3752         saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor;
    3753         distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda);
    3754       }
    3755     }
    3756   }
    3757 }
    3758 
    3759 #endif
    3760 
    37611315//! \}
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    5454// ====================================================================================================================
    5555
    56 #if HM_CLEANUP_SAO
    5756enum SAOCabacStateLablesRDO //CABAC state labels
    5857{
     
    146145  TEncSbac*              m_pcRDGoOnSbacCoder;
    147146  TEncBinCABACCounter**  m_pppcBinCoderCABAC;   
    148   Double                 m_labmda[NUM_SAO_COMPONENTS];
     147  Double                 m_lambda[NUM_SAO_COMPONENTS];
    149148
    150149  //statistics
     
    159158  Int                    m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
    160159};
    161 #else
    162 
    163 
    164 class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
    165 {
    166 private:
    167   TEncEntropy*      m_pcEntropyCoder;
    168   TEncSbac***       m_pppcRDSbacCoder;              ///< for CABAC
    169   TEncSbac*         m_pcRDGoOnSbacCoder;
    170 #if FAST_BIT_EST
    171   TEncBinCABACCounter*** m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
    172 #else
    173   TEncBinCABAC***   m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
    174 #endif
    175  
    176   Int64  ***m_iCount;      //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    177   Int64  ***m_iOffset;     //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    178   Int64  ***m_iOffsetOrg;  //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    179   Int64  ****m_count_PreDblk;      //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    180   Int64  ****m_offsetOrg_PreDblk;  //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    181   Int64  **m_iRate;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    182   Int64  **m_iDist;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    183   Double **m_dCost;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    184   Double *m_dCostPartBest; //[MAX_NUM_SAO_PART];
    185   Int64  *m_iDistOrg;      //[MAX_NUM_SAO_PART];
    186   Int    *m_iTypePartBest; //[MAX_NUM_SAO_PART];
    187   Int     m_iOffsetThY;
    188   Int     m_iOffsetThC;
    189   Bool    m_bUseSBACRD;
    190 #if SAO_ENCODING_CHOICE
    191 #if SAO_ENCODING_CHOICE_CHROMA
    192   Double  m_depthSaoRate[2][4];
    193 #else
    194   Double  m_depth0SaoRate;
    195 #endif
    196 #endif
    197 
    198 public:
    199   TEncSampleAdaptiveOffset         ();
    200   virtual ~TEncSampleAdaptiveOffset();
    201 
    202   Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder);
    203   Void endSaoEnc();
    204   Void resetStats();
    205 #if SAO_ENCODING_CHOICE
    206   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
    207 #else
    208   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
    209 #endif
    210 
    211   Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr);
    212   Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr);
    213  
    214   Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx);
    215   Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr);
    216   Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr);
    217   Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);
    218   Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);
    219   Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic );
    220   Void destroyEncBuffer();
    221   Void createEncBuffer();
    222   Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr);
    223   Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir);
    224 #if SAO_ENCODING_CHOICE
    225   Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth);
    226 #else
    227   Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma);
    228 #endif
    229   Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion);
    230   Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion);
    231   inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift);
    232   inline Int64 estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh );
    233   inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo);
    234   Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; }
    235   Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
    236 };
    237 #endif
    238160//! \}
    239161
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    7878, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    7979, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    80 , m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    8180, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    8281, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     
    112111  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT);
    113112  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    114   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
    115113  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    116114  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
     
    166164      curCost += m_cCUMergeIdxExtSCModel.calcCost     ( curSliceType, qp, (UChar*)INIT_MERGE_IDX_EXT);
    167165      curCost += m_cCUPartSizeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PART_SIZE );
    168       curCost += m_cCUAMPSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS );
    169166      curCost += m_cCUPredModeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PRED_MODE );
    170167      curCost += m_cCUIntraPredSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
     
    215212  m_cCUMergeIdxExtSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_MERGE_IDX_EXT);
    216213  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    217   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
    218214  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    219215  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
     
    442438        if (eSize == SIZE_2NxN)
    443439        {
    444           m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 ));
     440          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    445441        }
    446442        else
    447443        {
    448           m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 ));         
     444          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    449445          m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1));
    450446        }
     
    466462        if (eSize == SIZE_Nx2N)
    467463        {
    468           m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 ));
     464          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    469465        }
    470466        else
    471467        {
    472           m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 ));
     468          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    473469          m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1));
    474470        }
     
    13931389  {
    13941390    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    1395 #if HM_CLEANUP_SAO
    13961391    m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
    1397 #else
    1398     m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 );
    1399 #endif
    14001392  }
    14011393}
     
    16001592}
    16011593
    1602 #if HM_CLEANUP_SAO
    16031594Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
    16041595{
     
    17131704  }
    17141705}
    1715 #endif
    17161706
    17171707//! \}
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    104104  Void  codeScalingList      ( TComScalingList* /*scalingList*/     ){ assert (0);  return;};
    105105
    106 #if HM_CLEANUP_SAO
    107106  Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
    108107  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
     
    112111                    , Bool onlyEstMergeInfo = false
    113112                    );
    114 #endif
    115113
    116114private:
     
    208206  ContextModel3DBuffer m_cMVPIdxSCModel;
    209207 
    210   ContextModel3DBuffer m_cCUAMPSCModel;
    211208  ContextModel3DBuffer m_cSaoMergeSCModel;
    212209  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    199199  m_pppcRDSbacCoder     = pppcRDSbacCoder;
    200200  m_pcRDGoOnSbacCoder   = pcRDGoOnSbacCoder;
    201  
    202   m_bUseSBACRD          = pppcRDSbacCoder ? true : false;
    203201 
    204202  for (Int iDir = 0; iDir < 2; iDir++)
     
    11251123  {
    11261124    Int scalingListType = 0 + g_eTTable[(Int)TEXT_LUMA];
    1127     assert(scalingListType < 6);
     1125    assert(scalingListType < SCALING_LIST_NUM);
    11281126    m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
    11291127  }
     
    13181316    {
    13191317      Int scalingListType = 0 + g_eTTable[(Int)eText];
    1320       assert(scalingListType < 6);
     1318      assert(scalingListType < SCALING_LIST_NUM);
    13211319      m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
    13221320    }
     
    14241422  checkTransformSkip         &= (widthTransformSkip == 4 && heightTransformSkip == 4);
    14251423  checkTransformSkip         &= (!pcCU->getCUTransquantBypass(0));
    1426   checkTransformSkip         &= (!((pcCU->getQP( 0 ) == 0) && (pcCU->getSlice()->getSPS()->getUseLossless())));
    14271424  if ( m_pcEncCfg->getUseTransformSkipFast() )
    14281425  {
     
    14341431    {
    14351432      //----- store original entropy coding status -----
    1436       if( m_bUseSBACRD)
    1437       {
    1438         m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1439       }
     1433      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     1434
    14401435      UInt   singleDistYTmp     = 0;
    14411436      UInt   singleDistCTmp     = 0;
     
    15031498          {
    15041499            xStoreIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly );
    1505             if( m_bUseSBACRD)
    1506             {
    1507               m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    1508             }
     1500            m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    15091501          }
    15101502        }
     
    15291521          }
    15301522        }
    1531         if(m_bUseSBACRD)
    1532         {
    1533           m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    1534         }
    1535       }
     1523        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
     1524      }
    15361525
    15371526      if( !bLumaOnly )
     
    15581547      pcCU ->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiFullDepth );
    15591548      //----- store original entropy coding status -----
    1560       if( m_bUseSBACRD && bCheckSplit )
     1549      if( bCheckSplit )
    15611550      {
    15621551        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     
    15951584  {
    15961585    //----- store full entropy coding status, load original entropy coding status -----
    1597     if( m_bUseSBACRD )
    1598     {
    1599       if( bCheckFull )
    1600       {
    1601         m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] );
    1602         m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1603       }
    1604       else
    1605       {
    1606         m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1607       }
    1608     }
     1586    if( bCheckFull )
     1587    {
     1588      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] );
     1589      m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     1590    }
     1591    else
     1592    {
     1593      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     1594    }
     1595
    16091596    //----- code splitted block -----
    16101597    Double  dSplitCost      = 0.0;
     
    16471634    }
    16481635    //----- restore context states -----
    1649     if( m_bUseSBACRD )
    1650     {
    1651       m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1652     }
     1636    m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     1637
    16531638    //----- determine rate and r-d cost -----
    16541639    UInt uiSplitBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false );
     
    16651650    }
    16661651    //----- set entropy coding status -----
    1667     if( m_bUseSBACRD )
    1668     {
    1669       m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] );
    1670     }
    1671    
     1652    m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] );
     1653
    16721654    //--- set transform index and Cbf values ---
    16731655    pcCU->setTrIdxSubParts( uiTrDepth, uiAbsPartIdx, uiFullDepth );
     
    21942176    {
    21952177        //use RDO to decide whether Cr/Cb takes TS
    2196         if( m_bUseSBACRD )
    2197         {
    2198           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
    2199         }
     2178        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
    22002179
    22012180        for(Int chromaId = 0; chromaId < 2; chromaId ++)
     
    22392218
    22402219            if(singleCostTmp < dSingleCost)
     2220          {
     2221            dSingleCost = singleCostTmp;
     2222            singleDistC = singleDistCTmp;
     2223            bestModeId  = chromaModeId;
     2224            singleCbfC  = singleCbfCTmp;
     2225           
     2226            if(bestModeId == firstCheckId)
    22412227            {
    2242               dSingleCost = singleCostTmp;
    2243               singleDistC = singleDistCTmp;
    2244               bestModeId  = chromaModeId;
    2245               singleCbfC  = singleCbfCTmp;
    2246 
    2247               if(bestModeId == firstCheckId)
    2248               {
    2249                 xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
    2250                 if( m_bUseSBACRD)
    2251                 {
    2252                   m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    2253                 }
    2254               }
    2255             }
    2256             if(chromaModeId == firstCheckId)
    2257             {
    2258               m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     2228              xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
     2229              m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    22592230            }
    22602231          }
    2261 
    2262           if(bestModeId == firstCheckId)
     2232          if(chromaModeId == firstCheckId)
    22632233          {
    2264             xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
    2265             pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth );
    2266             if(m_bUseSBACRD)
    2267             {
    2268               m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    2269             }
     2234            m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    22702235          }
    2271           pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) +  actualTrDepth );
    2272           ruiDist += singleDistC;
    2273 
    2274           if(chromaId == 0)
    2275           {
    2276             if( m_bUseSBACRD )
    2277             {
    2278               m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
    2279             }
    2280           }
    2281         }
     2236        }
     2237       
     2238        if(bestModeId == firstCheckId)
     2239        {
     2240          xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
     2241          pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth );
     2242          m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
     2243        }
     2244        pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) +  actualTrDepth );
     2245        ruiDist += singleDistC;
     2246       
     2247        if(chromaId == 0)
     2248        {
     2249          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
     2250        }
     2251      }
    22822252    }
    22832253    else
     
    25752545     
    25762546      // set context models
    2577       if( m_bUseSBACRD )
    2578       {
    2579         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    2580       }
     2547      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    25812548     
    25822549      // determine residual for partition
     
    26402607     
    26412608      // set context models
    2642       if( m_bUseSBACRD )
    2643       {
    2644         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    2645       }
     2609      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    26462610     
    26472611      // determine residual for partition
     
    27702734 
    27712735  //===== reset context models =====
    2772   if(m_bUseSBACRD)
    2773   {
    2774     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    2775   }
     2736  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    27762737 
    27772738  //===== set distortion (rate and r-d costs are determined later) =====
     
    28052766  {
    28062767    //----- restore context models -----
    2807     if( m_bUseSBACRD )
    2808     {
    2809       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    2810     }
     2768    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    28112769   
    28122770    //----- chroma coding -----
     
    28142772    pcCU->setChromIntraDirSubParts  ( uiModeList[uiMode], 0, uiDepth );
    28152773    xRecurIntraChromaCodingQT       ( pcCU,   0, 0, pcOrgYuv, pcPredYuv, pcResiYuv, uiDist );
    2816     if( m_bUseSBACRD && pcCU->getSlice()->getPPS()->getUseTransformSkip() )
     2774    if( pcCU->getSlice()->getPPS()->getUseTransformSkip() )
    28172775    {
    28182776      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     
    28462804 
    28472805  //----- restore context models -----
    2848   if( m_bUseSBACRD )
    2849   {
    2850     m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    2851   }
     2806  m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    28522807}
    28532808
     
    30052960  dCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion );
    30062961
    3007   if(m_bUseSBACRD)
    3008   {
    3009     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    3010   }
     2962  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    30112963
    30122964  pcCU->getTotalBits()       = uiBits;
     
    45744526    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    45754527
    4576     if( m_bUseSBACRD )
    4577     {
    4578       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]);
    4579     }
     4528    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]);
    45804529   
    45814530    m_pcEntropyCoder->resetBits();
     
    45924541    pcCU->getTotalCost()       = m_pcRdCost->calcRdCost( uiBits, uiDistortion );
    45934542   
    4594     if( m_bUseSBACRD )
    4595     {
    4596       m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]);
    4597     }
     4543    m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]);
    45984544   
    45994545    pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) );
     
    46314577    uiBits = 0;
    46324578    uiDistortion = 0;
    4633     if( m_bUseSBACRD )
    4634     {
    4635       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] );
    4636     }
     4579    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] );
    46374580   
    46384581    UInt uiZeroDistortion = 0;
     
    46684611    }
    46694612   
    4670     if( m_bUseSBACRD )
    4671     {
    4672       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    4673     }
     4613    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    46744614#if 0 // check
    46754615    {
     
    46774617      m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) );
    46784618      const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits();
    4679       if( m_bUseSBACRD )
    4680       {
    4681         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    4682       }
     4619      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    46834620      if( uiBitsForCoeff != uiBits )
    46844621        assert( 0 );
     
    47294666      dCostBest        = dCost;
    47304667      qpBest           = qp;
    4731       if( m_bUseSBACRD )
    4732       {
    4733         m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    4734       }
     4668      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    47354669    }
    47364670  }
     
    47404674  if( qpMin != qpMax && qpBest != qpMax )
    47414675  {
    4742     if( m_bUseSBACRD )
    4743     {
    4744       assert( 0 ); // check
    4745       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    4746     }
     4676    assert( 0 ); // check
     4677    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
     4678
    47474679    // copy best cbf and trIdx to pcCU
    47484680    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1);
     
    48244756  UInt uiBestTransformMode[3] = {0};
    48254757
    4826   if( m_bUseSBACRD )
    4827   {
    4828     m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    4829   }
     4758  m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    48304759 
    48314760  if( bCheckFull )
     
    49654894
    49664895      Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
    4967       assert(scalingListType < 6);     
     4896      assert(scalingListType < SCALING_LIST_NUM);
    49684897      m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
    49694898     
     
    50384967
    50394968        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U];
    5040         assert(scalingListType < 6);
     4969        assert(scalingListType < SCALING_LIST_NUM);
    50414970        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType  );
    50424971       
     
    51085037
    51095038        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V];
    5110         assert(scalingListType < 6);
     5039        assert(scalingListType < SCALING_LIST_NUM);
    51115040        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType );
    51125041       
     
    51925121      }
    51935122
    5194       if( m_bUseSBACRD )
    5195       {
    5196         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    5197       }
     5123      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    51985124
    51995125      pcCU->setTransformSkipSubParts ( 1, TEXT_LUMA, uiAbsPartIdx, uiDepth );
     
    52345160
    52355161        Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
    5236         assert(scalingListType < 6);     
     5162        assert(scalingListType < SCALING_LIST_NUM);
    52375163
    52385164        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType, true );
     
    52925218      }
    52935219
    5294       if( m_bUseSBACRD )
    5295       {
    5296         m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    5297       }
     5220      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    52985221
    52995222      pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC );
     
    53455268
    53465269        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U];
    5347         assert(scalingListType < 6);
     5270        assert(scalingListType < SCALING_LIST_NUM);
    53485271
    53495272        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType, true  );
     
    53875310
    53885311        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V];
    5389         assert(scalingListType < 6);
     5312        assert(scalingListType < SCALING_LIST_NUM);
    53905313
    53915314        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType, true );
     
    54235346    }
    54245347
    5425     if( m_bUseSBACRD )
    5426     {
    5427       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    5428     }
    5429 
     5348    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    54305349    m_pcEntropyCoder->resetBits();
    54315350
     
    54605379  if( bCheckSplit )
    54615380  {
    5462     if( m_bUseSBACRD && bCheckFull )
     5381    if( bCheckFull )
    54635382    {
    54645383      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
     
    54925411    }
    54935412   
    5494     if( m_bUseSBACRD )
    5495     {
    5496       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    5497     }
     5413    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    54985414    m_pcEntropyCoder->resetBits();
    54995415   
     
    55235439    }
    55245440    assert( bCheckFull );
    5525     if( m_bUseSBACRD )
    5526     {
    5527       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
    5528     }
     5441
     5442    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
    55295443  }
    55305444  rdCost += dSingleCost;
     
    57175631UInt TEncSearch::xModeBitsIntra( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth )
    57185632{
    5719   if( m_bUseSBACRD )
    5720   {
    5721     // Reload only contexts required for coding intra mode information
    5722     m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    5723   }
     5633  // Reload only contexts required for coding intra mode information
     5634  m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    57245635 
    57255636  pcCU->setLumaIntraDirSubParts ( uiMode, uiPartOffset, uiDepth + uiInitTrDepth );
     
    60375948}
    60385949
     5950#if SVC_EXTENSION
    60395951#if REF_IDX_ME_ZEROMV
    60405952Void TEncSearch::xPatternSearchFracDIFMv0(TComDataCU* pcCU,
     
    62056117}
    62066118#endif
     6119#endif //SVC_EXTENSION
    62076120
    62086121//! \}
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    9797  TEncCfg*        m_pcEncCfg;
    9898 
    99 #if SVC_EXTENSION
    100   TEncTop**       m_ppcTEncTop;
    101 #endif
    102  
    10399  // interface to classes
    104100  TComTrQuant*    m_pcTrQuant;
     
    118114  TEncSbac***     m_pppcRDSbacCoder;
    119115  TEncSbac*       m_pcRDGoOnSbacCoder;
    120   Bool            m_bUseSBACRD;
    121116  DistParam       m_cDistParam;
    122117 
     
    130125  UInt            m_auiMVPIdxCost[AMVP_MAX_NUM_CANDS+1][AMVP_MAX_NUM_CANDS+1]; //th array bounds
    131126
     127#if SVC_EXTENSION
     128  TEncTop**       m_ppcTEncTop;
    132129#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    133130  Bool            m_disableILP;
    134131#endif
     132#endif //SVC_EXTENAION
    135133
    136134public:
     
    207205                                );
    208206 
    209 #if (ENCODER_FAST_MODE)
    210   Bool predInterSearchILRUni    ( TComDataCU* pcCU, TComYuv*    pcOrgYuv, TComYuv*&   rpcPredYuv, TComYuv*&   rpcResiYuv, TComYuv*&   rpcRecoYuv, UInt        refLayerId );
    211 #endif
    212  
    213207  /// encode residual and compute rd-cost for inter mode
    214208  Void encodeResAndCalcRdInterCU( TComDataCU* pcCU,
     
    226220  Void IPCMSearch (TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv );
    227221
     222#if SVC_EXTENSION
     223#if (ENCODER_FAST_MODE)
     224  Bool predInterSearchILRUni    ( TComDataCU* pcCU, TComYuv*    pcOrgYuv, TComYuv*&   rpcPredYuv, TComYuv*&   rpcResiYuv, TComYuv*&   rpcRecoYuv, UInt        refLayerId );
     225#endif 
    228226#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    229227  Void setDisableILP(Bool a) {m_disableILP = a;}
    230228#endif
     229#endif //SVC_EXTENSION
    231230
    232231protected:
     
    453452                                   ,Bool biPred
    454453                                   );
     454 
     455  Void xExtDIFUpSamplingH( TComPattern* pcPattern, Bool biPred  );
     456  Void xExtDIFUpSamplingQ( TComPattern* pcPatternKey, TComMv halfPelRef, Bool biPred );
     457 
     458  // -------------------------------------------------------------------------------------------------------------------
     459  // T & Q & Q-1 & T-1
     460  // -------------------------------------------------------------------------------------------------------------------
     461 
     462  Void xEncodeResidualQT( TComDataCU* pcCU, UInt uiAbsPartIdx, const UInt uiDepth, Bool bSubdivAndCbf, TextType eType );
     463  Void xEstimateResidualQT( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx, UInt absTUPartIdx,TComYuv* pcResi, const UInt uiDepth, Double &rdCost, UInt &ruiBits, UInt &ruiDist, UInt *puiZeroDist );
     464  Void xSetResidualQTData( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx,UInt absTUPartIdx, TComYuv* pcResi, UInt uiDepth, Bool bSpatial );
     465 
     466  UInt  xModeBitsIntra ( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth );
     467  UInt  xUpdateCandList( UInt uiMode, Double uiCost, UInt uiFastCandNum, UInt * CandModeList, Double * CandCostList );
     468 
     469  // -------------------------------------------------------------------------------------------------------------------
     470  // compute symbol bits
     471  // -------------------------------------------------------------------------------------------------------------------
     472 
     473  Void xAddSymbolBitsInter        ( TComDataCU*   pcCU,
     474                                   UInt          uiQp,
     475                                   UInt          uiTrMode,
     476                                   UInt&         ruiBits,
     477                                   TComYuv*&     rpcYuvRec,
     478                                   TComYuv*      pcYuvPred,
     479                                   TComYuv*&     rpcYuvResi );
     480 
     481  Void  setWpScalingDistParam( TComDataCU* pcCU, Int iRefIdx, RefPicList eRefPicListCur );
     482  inline  Void  setDistParamComp( UInt uiComp )  { m_cDistParam.uiComp = uiComp; }
     483
     484#if SVC_EXTENSION
    455485#if REF_IDX_ME_ZEROMV
    456486  Void xPatternSearchFracDIFMv0  ( TComDataCU*   pcCU,
     
    464494                                   Bool          biPred );
    465495#endif
    466   Void xExtDIFUpSamplingH( TComPattern* pcPattern, Bool biPred  );
    467   Void xExtDIFUpSamplingQ( TComPattern* pcPatternKey, TComMv halfPelRef, Bool biPred );
    468  
    469   // -------------------------------------------------------------------------------------------------------------------
    470   // T & Q & Q-1 & T-1
    471   // -------------------------------------------------------------------------------------------------------------------
    472  
    473   Void xEncodeResidualQT( TComDataCU* pcCU, UInt uiAbsPartIdx, const UInt uiDepth, Bool bSubdivAndCbf, TextType eType );
    474   Void xEstimateResidualQT( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx, UInt absTUPartIdx,TComYuv* pcResi, const UInt uiDepth, Double &rdCost, UInt &ruiBits, UInt &ruiDist, UInt *puiZeroDist );
    475   Void xSetResidualQTData( TComDataCU* pcCU, UInt uiQuadrant, UInt uiAbsPartIdx,UInt absTUPartIdx, TComYuv* pcResi, UInt uiDepth, Bool bSpatial );
    476  
    477   UInt  xModeBitsIntra ( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth );
    478   UInt  xUpdateCandList( UInt uiMode, Double uiCost, UInt uiFastCandNum, UInt * CandModeList, Double * CandCostList );
    479  
    480   // -------------------------------------------------------------------------------------------------------------------
    481   // compute symbol bits
    482   // -------------------------------------------------------------------------------------------------------------------
    483  
    484   Void xAddSymbolBitsInter        ( TComDataCU*   pcCU,
    485                                    UInt          uiQp,
    486                                    UInt          uiTrMode,
    487                                    UInt&         ruiBits,
    488                                    TComYuv*&     rpcYuvRec,
    489                                    TComYuv*      pcYuvPred,
    490                                    TComYuv*&     rpcYuvResi );
    491  
    492   Void  setWpScalingDistParam( TComDataCU* pcCU, Int iRefIdx, RefPicList eRefPicListCur );
    493   inline  Void  setDistParamComp( UInt uiComp )  { m_cDistParam.uiComp = uiComp; }
    494  
     496#endif //SVC_EXTENSION 
     497
    495498};// END CLASS DEFINITION TEncSearch
    496499
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r588 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    254254
    255255  eSliceType=B_SLICE;
    256   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     256  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    257257
    258258  rpcSlice->setSliceType    ( eSliceType );
     
    280280  {
    281281#if REPN_FORMAT_IN_VPS
    282     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     282    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
    283283#else
    284     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     284    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
    285285#endif
    286286    {
     
    423423#if HB_LAMBDA_FOR_LDC
    424424  // restore original slice type
    425   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     425  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    426426
    427427#if SVC_EXTENSION
     
    785785
    786786  // set entropy coder
    787   if( m_pcCfg->getUseSBACRD() )
    788   {
    789     m_pcSbacCoder->init( m_pcBinCABAC );
    790     m_pcEntropyCoder->setEntropyCoder   ( m_pcSbacCoder, pcSlice );
    791     m_pcEntropyCoder->resetEntropy      ();
    792     m_pppcRDSbacCoder[0][CI_CURR_BEST]->load(m_pcSbacCoder);
    793     pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf();
    794     pppcRDSbacCoder->setBinCountingEnableFlag( false );
    795     pppcRDSbacCoder->setBinsCoded( 0 );
    796   }
    797   else
    798   {
    799     m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    800     m_pcEntropyCoder->resetEntropy      ();
    801     m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    802   }
    803 
     787  m_pcSbacCoder->init( m_pcBinCABAC );
     788  m_pcEntropyCoder->setEntropyCoder   ( m_pcSbacCoder, pcSlice );
     789  m_pcEntropyCoder->resetEntropy      ();
     790  m_pppcRDSbacCoder[0][CI_CURR_BEST]->load(m_pcSbacCoder);
     791  pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf();
     792  pppcRDSbacCoder->setBinCountingEnableFlag( false );
     793  pppcRDSbacCoder->setBinsCoded( 0 );
     794 
    804795  //------------------------------------------------------------------------------
    805796  //  Weighted Prediction parameters estimation.
     
    854845  UInt uiTilesAcross  = 0;
    855846
    856   if( m_pcCfg->getUseSBACRD() )
    857   {
    858     iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    859     uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
    860     delete[] m_pcBufferSbacCoders;
    861     delete[] m_pcBufferBinCoderCABACs;
    862     m_pcBufferSbacCoders     = new TEncSbac    [uiTilesAcross];
    863     m_pcBufferBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
    864     for (Int ui = 0; ui < uiTilesAcross; ui++)
    865     {
    866       m_pcBufferSbacCoders[ui].init( &m_pcBufferBinCoderCABACs[ui] );
    867     }
    868     for (UInt ui = 0; ui < uiTilesAcross; ui++)
    869     {
    870       m_pcBufferSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
    871     }
    872 
    873     for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) //init all sbac coders for RD optimization
    874     {
    875       ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    876     }
    877   }
    878   //if( m_pcCfg->getUseSBACRD() )
    879   {
    880     delete[] m_pcBufferLowLatSbacCoders;
    881     delete[] m_pcBufferLowLatBinCoderCABACs;
    882     m_pcBufferLowLatSbacCoders     = new TEncSbac    [uiTilesAcross];
    883     m_pcBufferLowLatBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
    884     for (Int ui = 0; ui < uiTilesAcross; ui++)
    885     {
    886       m_pcBufferLowLatSbacCoders[ui].init( &m_pcBufferLowLatBinCoderCABACs[ui] );
    887     }
    888     for (UInt ui = 0; ui < uiTilesAcross; ui++)
    889       m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
    890   }
     847  iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
     848  uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     849  delete[] m_pcBufferSbacCoders;
     850  delete[] m_pcBufferBinCoderCABACs;
     851  m_pcBufferSbacCoders     = new TEncSbac    [uiTilesAcross];
     852  m_pcBufferBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
     853  for (Int ui = 0; ui < uiTilesAcross; ui++)
     854  {
     855    m_pcBufferSbacCoders[ui].init( &m_pcBufferBinCoderCABACs[ui] );
     856  }
     857  for (UInt ui = 0; ui < uiTilesAcross; ui++)
     858  {
     859    m_pcBufferSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
     860  }
     861
     862  for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ ) //init all sbac coders for RD optimization
     863  {
     864    ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
     865  }
     866
     867  delete[] m_pcBufferLowLatSbacCoders;
     868  delete[] m_pcBufferLowLatBinCoderCABACs;
     869  m_pcBufferLowLatSbacCoders     = new TEncSbac    [uiTilesAcross];
     870  m_pcBufferLowLatBinCoderCABACs = new TEncBinCABAC[uiTilesAcross];
     871  for (Int ui = 0; ui < uiTilesAcross; ui++)
     872  {
     873    m_pcBufferLowLatSbacCoders[ui].init( &m_pcBufferLowLatBinCoderCABACs[ui] );
     874  }
     875  for (UInt ui = 0; ui < uiTilesAcross; ui++)
     876    m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
     877
    891878  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    892879  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     
    944931
    945932    // inherit from TR if necessary, select substream to use.
    946     if( m_pcCfg->getUseSBACRD() )
    947     {
    948       uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    949       uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
    950       uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
    951       //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
    952       uiCol     = uiCUAddr % uiWidthInLCUs;
    953       uiLin     = uiCUAddr / uiWidthInLCUs;
    954       if (pcSlice->getPPS()->getNumSubstreams() > 1)
    955       {
    956         // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
    957         Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    958         uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
    959                       + uiLin%iNumSubstreamsPerTile;
     933    uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
     934    uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     935    uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     936    //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     937    uiCol     = uiCUAddr % uiWidthInLCUs;
     938    uiLin     = uiCUAddr / uiWidthInLCUs;
     939    if (pcSlice->getPPS()->getNumSubstreams() > 1)
     940    {
     941      // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
     942      Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
     943      uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
     944          + uiLin%iNumSubstreamsPerTile;
     945    }
     946    else
     947    {
     948      // dependent tiles => substreams are "per frame".
     949      uiSubStrm = uiLin % iNumSubstreams;
     950    }
     951    if ( ((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     952    {
     953      // We'll sync if the TR is available.
     954      TComDataCU *pcCUUp = pcCU->getCUAbove();
     955      UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
     956      UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     957      TComDataCU *pcCUTR = NULL;
     958      if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
     959      {
     960        pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
     961      }
     962      if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     963          (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
     964          ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     965      )
     966      )
     967      {
     968        // TR not available.
    960969      }
    961970      else
    962971      {
    963         // dependent tiles => substreams are "per frame".
    964         uiSubStrm = uiLin % iNumSubstreams;
    965       }
    966       if ( ((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled ) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    967       {
    968         // We'll sync if the TR is available.
    969         TComDataCU *pcCUUp = pcCU->getCUAbove();
    970         UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
    971         UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
    972         TComDataCU *pcCUTR = NULL;
    973         if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
    974         {
    975           pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
    976         }
    977         if ( ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
    978              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
    979              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    980              )
    981            )
    982         {
    983           // TR not available.
    984         }
    985         else
    986         {
    987           // TR is available, we use it.
    988           ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
    989         }
    990       }
    991       m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
    992     }
     972        // TR is available, we use it.
     973        ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
     974      }
     975    }
     976    m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
    993977
    994978    // reset the entropy coder
     
    1008992      m_pcEntropyCoder->setEntropyCoder     ( m_pcSbacCoder, pcSlice );
    1009993    }
    1010     // if RD based on SBAC is used
    1011     if( m_pcCfg->getUseSBACRD() )
    1012     {
    1013       // set go-on entropy coder
    1014       m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
    1015       m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
    1016 
    1017       ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    1018 
    1019       Double oldLambda = m_pcRdCost->getLambda();
    1020       if ( m_pcCfg->getUseRateCtrl() )
    1021       {
    1022         Int estQP        = pcSlice->getSliceQp();
    1023         Double estLambda = -1.0;
    1024         Double bpp       = -1.0;
    1025 
    1026         if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
     994
     995    // set go-on entropy coder
     996    m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
     997    m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
     998
     999    ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
     1000
     1001    Double oldLambda = m_pcRdCost->getLambda();
     1002    if ( m_pcCfg->getUseRateCtrl() )
     1003    {
     1004      Int estQP        = pcSlice->getSliceQp();
     1005      Double estLambda = -1.0;
     1006      Double bpp       = -1.0;
     1007
     1008      if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
     1009      {
     1010        estQP = pcSlice->getSliceQp();
     1011      }
     1012      else
     1013      {
     1014        bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
     1015        if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
    10271016        {
    1028           estQP = pcSlice->getSliceQp();
     1017          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
    10291018        }
    10301019        else
    10311020        {
    1032           bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
    1033           if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
    1034           {
    1035             estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambdaAndQP(bpp, pcSlice->getSliceQp(), &estQP);
    1036           }
    1037           else
    1038           {
    1039             estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    1040             estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    1041           }
     1021          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     1022          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
     1023        }
    10421024
    10431025#if REPN_FORMAT_IN_VPS
     
    10561038          m_pcTrQuant->setLambda( estLambda );
    10571039#endif
     1040      }
     1041
     1042      m_pcRateCtrl->setRCQP( estQP );
     1043      pcCU->getSlice()->setSliceQpBase( estQP );
     1044    }
     1045
     1046    // run CU encoder
     1047    m_pcCuEncoder->compressCU( pcCU );
     1048
     1049    // restore entropy coder to an initial stage
     1050    m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
     1051    m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
     1052    m_pcCuEncoder->setBitCounter( &pcBitCounters[uiSubStrm] );
     1053    m_pcBitCounter = &pcBitCounters[uiSubStrm];
     1054    pppcRDSbacCoder->setBinCountingEnableFlag( true );
     1055    m_pcBitCounter->resetBits();
     1056    pppcRDSbacCoder->setBinsCoded( 0 );
     1057    m_pcCuEncoder->encodeCU( pcCU );
     1058
     1059    pppcRDSbacCoder->setBinCountingEnableFlag( false );
     1060    if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits() + m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
     1061    {
     1062      pcSlice->setNextSlice( true );
     1063      break;
     1064    }
     1065    if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+m_pcEntropyCoder->getNumberOfWrittenBits() > (m_pcCfg->getSliceSegmentArgument() << 3) &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
     1066    {
     1067      pcSlice->setNextSliceSegment( true );
     1068      break;
     1069    }
     1070
     1071    ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
     1072    //Store probabilties of second LCU in line into buffer
     1073    if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
     1074    {
     1075      m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
     1076    }
     1077
     1078    if ( m_pcCfg->getUseRateCtrl() )
     1079    {
     1080
     1081      Int actualQP        = g_RCInvalidQPValue;
     1082      Double actualLambda = m_pcRdCost->getLambda();
     1083      Int actualBits      = pcCU->getTotalBits();
     1084      Int numberOfEffectivePixels    = 0;
     1085      for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
     1086      {
     1087        if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
     1088        {
     1089          numberOfEffectivePixels = numberOfEffectivePixels + 16;
     1090          break;
    10581091        }
    1059 
    1060         m_pcRateCtrl->setRCQP( estQP );
    1061         pcCU->getSlice()->setSliceQpBase( estQP );
    1062       }
    1063 
    1064       // run CU encoder
    1065       m_pcCuEncoder->compressCU( pcCU );
    1066 
    1067       // restore entropy coder to an initial stage
    1068       m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
    1069       m_pcEntropyCoder->setBitstream( &pcBitCounters[uiSubStrm] );
    1070       m_pcCuEncoder->setBitCounter( &pcBitCounters[uiSubStrm] );
    1071       m_pcBitCounter = &pcBitCounters[uiSubStrm];
    1072       pppcRDSbacCoder->setBinCountingEnableFlag( true );
    1073       m_pcBitCounter->resetBits();
    1074       pppcRDSbacCoder->setBinsCoded( 0 );
    1075       m_pcCuEncoder->encodeCU( pcCU );
    1076 
    1077       pppcRDSbacCoder->setBinCountingEnableFlag( false );
    1078       if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits() + m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    1079       {
    1080         pcSlice->setNextSlice( true );
    1081         break;
    1082       }
    1083       if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+m_pcEntropyCoder->getNumberOfWrittenBits() > (m_pcCfg->getSliceSegmentArgument() << 3) &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
    1084       {
    1085         pcSlice->setNextSliceSegment( true );
    1086         break;
    1087       }
    1088       if( m_pcCfg->getUseSBACRD() )
    1089       {
    1090          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    1091 
    1092          //Store probabilties of second LCU in line into buffer
    1093          if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
    1094         {
    1095           m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
    1096         }
    1097       }
    1098 
    1099       if ( m_pcCfg->getUseRateCtrl() )
    1100       {
    1101 
    1102         Int actualQP        = g_RCInvalidQPValue;
    1103         Double actualLambda = m_pcRdCost->getLambda();
    1104         Int actualBits      = pcCU->getTotalBits();
    1105         Int numberOfEffectivePixels    = 0;
    1106         for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
    1107         {
    1108           if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
    1109           {
    1110             numberOfEffectivePixels = numberOfEffectivePixels + 16;
    1111             break;
    1112           }
    1113         }
    1114 
    1115         if ( numberOfEffectivePixels == 0 )
    1116         {
    1117           actualQP = g_RCInvalidQPValue;
    1118         }
    1119         else
    1120         {
    1121           actualQP = pcCU->getQP( 0 );
    1122         }
    1123         m_pcRdCost->setLambda(oldLambda);
    1124 
    1125         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    1126           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1127       }
    1128     }
    1129     // other case: encodeCU is not called
    1130     else
    1131     {
    1132       m_pcCuEncoder->compressCU( pcCU );
    1133       m_pcCuEncoder->encodeCU( pcCU );
    1134       if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    1135       {
    1136         pcSlice->setNextSlice( true );
    1137         break;
    1138       }
    1139       if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
    1140       {
    1141         pcSlice->setNextSliceSegment( true );
    1142         break;
    1143       }
     1092      }
     1093
     1094      if ( numberOfEffectivePixels == 0 )
     1095      {
     1096        actualQP = g_RCInvalidQPValue;
     1097      }
     1098      else
     1099      {
     1100        actualQP = pcCU->getQP( 0 );
     1101      }
     1102      m_pcRdCost->setLambda(oldLambda);
     1103
     1104      m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
     1105        pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    11441106    }
    11451107
     
    11511113  {
    11521114    pcSlice->setNextSlice( true );
     1115  }
     1116  if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES)
     1117  {
     1118    if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr())
     1119    {
     1120       pcSlice->setNextSlice( true );
     1121    }
     1122    else
     1123    {
     1124       pcSlice->setNextSliceSegment( true );
     1125    }
    11531126  }
    11541127  if( depSliceSegmentsEnabled )
     
    12691242       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
    12701243  {
    1271     if( m_pcCfg->getUseSBACRD() )
    1272     {
    1273       uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    1274       uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
    1275       uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
    1276       //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
    1277       uiCol     = uiCUAddr % uiWidthInLCUs;
    1278       uiLin     = uiCUAddr / uiWidthInLCUs;
    1279       if (pcSlice->getPPS()->getNumSubstreams() > 1)
    1280       {
    1281         // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
    1282         Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
    1283         uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
    1284                       + uiLin%iNumSubstreamsPerTile;
     1244    uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
     1245    uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     1246    uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     1247    //UInt uiSliceStartLCU = pcSlice->getSliceCurStartCUAddr();
     1248    uiCol     = uiCUAddr % uiWidthInLCUs;
     1249    uiLin     = uiCUAddr / uiWidthInLCUs;
     1250    if (pcSlice->getPPS()->getNumSubstreams() > 1)
     1251    {
     1252      // independent tiles => substreams are "per tile".  iNumSubstreams has already been multiplied.
     1253      Int iNumSubstreamsPerTile = iNumSubstreams/rpcPic->getPicSym()->getNumTiles();
     1254      uiSubStrm = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)*iNumSubstreamsPerTile
     1255          + uiLin%iNumSubstreamsPerTile;
     1256    }
     1257    else
     1258    {
     1259      // dependent tiles => substreams are "per frame".
     1260      uiSubStrm = uiLin % iNumSubstreams;
     1261    }
     1262
     1263    m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
     1264    // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
     1265    if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
     1266    {
     1267      // We'll sync if the TR is available.
     1268      TComDataCU *pcCUUp = rpcPic->getCU( uiCUAddr )->getCUAbove();
     1269      UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
     1270      UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
     1271      TComDataCU *pcCUTR = NULL;
     1272      if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
     1273      {
     1274        pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
     1275      }
     1276      if ( (true/*bEnforceSliceRestriction*/ &&
     1277          ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
     1278              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
     1279              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
     1280          ))
     1281      )
     1282      {
     1283        // TR not available.
    12851284      }
    12861285      else
    12871286      {
    1288         // dependent tiles => substreams are "per frame".
    1289         uiSubStrm = uiLin % iNumSubstreams;
    1290       }
    1291 
    1292       m_pcEntropyCoder->setBitstream( &pcSubstreams[uiSubStrm] );
    1293       // Synchronize cabac probabilities with upper-right LCU if it's available and we're at the start of a line.
    1294       if (((pcSlice->getPPS()->getNumSubstreams() > 1) || depSliceSegmentsEnabled) && (uiCol == uiTileLCUX) && m_pcCfg->getWaveFrontsynchro())
    1295       {
    1296         // We'll sync if the TR is available.
    1297         TComDataCU *pcCUUp = rpcPic->getCU( uiCUAddr )->getCUAbove();
    1298         UInt uiWidthInCU = rpcPic->getFrameWidthInCU();
    1299         UInt uiMaxParts = 1<<(pcSlice->getSPS()->getMaxCUDepth()<<1);
    1300         TComDataCU *pcCUTR = NULL;
    1301         if ( pcCUUp && ((uiCUAddr%uiWidthInCU+1) < uiWidthInCU)  )
    1302         {
    1303           pcCUTR = rpcPic->getCU( uiCUAddr - uiWidthInCU + 1 );
    1304         }
    1305         if ( (true/*bEnforceSliceRestriction*/ &&
    1306              ((pcCUTR==NULL) || (pcCUTR->getSlice()==NULL) ||
    1307              (pcCUTR->getSCUAddr()+uiMaxParts-1 < pcSlice->getSliceCurStartCUAddr()) ||
    1308              ((rpcPic->getPicSym()->getTileIdxMap( pcCUTR->getAddr() ) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)))
    1309              ))
    1310            )
    1311         {
    1312           // TR not available.
    1313         }
    1314         else
    1315         {
    1316           // TR is available, we use it.
    1317           pcSbacCoders[uiSubStrm].loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
    1318         }
    1319       }
    1320       m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
    1321     }
     1287        // TR is available, we use it.
     1288        pcSbacCoders[uiSubStrm].loadContexts( &m_pcBufferSbacCoders[uiTileCol] );
     1289      }
     1290    }
     1291    m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
     1292
    13221293    // reset the entropy coder
    13231294    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
     
    13601331
    13611332    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
    1362 #if HM_CLEANUP_SAO
    13631333    if ( pcSlice->getSPS()->getUseSAO() )
    13641334    {
     
    13891359      }
    13901360    }
    1391 #else
    1392     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    1393     {
    1394       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1395       Int iNumCuInWidth     = saoParam->numCuInWidth;
    1396       Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
    1397       Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
    1398       Int rx = uiCUAddr % iNumCuInWidth;
    1399       Int ry = uiCUAddr / iNumCuInWidth;
    1400       Int allowMergeLeft = 1;
    1401       Int allowMergeUp   = 1;
    1402       if (rx!=0)
    1403       {
    1404         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1405         {
    1406           allowMergeLeft = 0;
    1407         }
    1408       }
    1409       if (ry!=0)
    1410       {
    1411         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1412         {
    1413           allowMergeUp = 0;
    1414         }
    1415       }
    1416       Int addr = pcCU->getAddr();
    1417       allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
    1418       allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
    1419       if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    1420       {
    1421         Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
    1422         Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag;
    1423         if (allowMergeLeft)
    1424         {
    1425           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
    1426         }
    1427         else
    1428         {
    1429           mergeLeft = 0;
    1430         }
    1431         if(mergeLeft == 0)
    1432         {
    1433           if (allowMergeUp)
    1434           {
    1435             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
    1436           }
    1437           else
    1438           {
    1439             mergeUp = 0;
    1440           }
    1441           if(mergeUp == 0)
    1442           {
    1443             for (Int compIdx=0;compIdx<3;compIdx++)
    1444             {
    1445             if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
    1446               {
    1447                 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    1448               }
    1449             }
    1450           }
    1451         }
    1452       }
    1453     }
    1454     else if (pcSlice->getSPS()->getUseSAO())
    1455     {
    1456       Int addr = pcCU->getAddr();
    1457       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1458       for (Int cIdx=0; cIdx<3; cIdx++)
    1459       {
    1460         SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
    1461         if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
    1462         {
    1463           saoLcuParam->mergeUpFlag   = 0;
    1464           saoLcuParam->mergeLeftFlag = 0;
    1465           saoLcuParam->subTypeIdx    = 0;
    1466           saoLcuParam->typeIdx       = -1;
    1467           saoLcuParam->offset[0]     = 0;
    1468           saoLcuParam->offset[1]     = 0;
    1469           saoLcuParam->offset[2]     = 0;
    1470           saoLcuParam->offset[3]     = 0;
    1471         }
    1472       }
    1473     }
    1474 #endif
    14751361
    14761362#if ENC_DEC_TRACE
     
    14891375    g_bJustDoIt = g_bEncDecTraceDisable;
    14901376#endif
    1491     if( m_pcCfg->getUseSBACRD() )
    1492     {
    1493        pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
    1494 
    1495 
    1496        //Store probabilties of second LCU in line into buffer
    1497        if ( (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
    1498       {
    1499         m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
    1500       }
     1377    pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
     1378    //Store probabilties of second LCU in line into buffer
     1379    if ( (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && (uiCol == uiTileLCUX+1) && m_pcCfg->getWaveFrontsynchro())
     1380    {
     1381      m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
    15011382    }
    15021383  }
     
    18701751}
    18711752
     1753#if SVC_EXTENSION
    18721754#if JCTVC_M0259_LAMBDAREFINEMENT
    18731755Double TEncSlice::xCalEnhLambdaFactor( Double deltaQP , Double beta )
     
    18881770}
    18891771#endif
     1772#endif //SVC_EXTENSION
    18901773//! \}
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r540 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    6565  // encoder configuration
    6666  TEncCfg*                m_pcCfg;                              ///< encoder configuration class
    67  
    68 #if SVC_EXTENSION
    69   TEncTop**               m_ppcTEncTop;
    70 #endif 
    7167
    7268  // pictures
     
    107103  UInt                    m_uiSliceIdx;
    108104  std::vector<TEncSbac*> CTXMem;
     105
     106#if SVC_EXTENSION
     107  TEncTop**               m_ppcTEncTop;
     108#endif
     109
    109110public:
    110111  TEncSlice();
     
    152153  Double  xGetQPValueAccordingToLambda ( Double lambda );
    153154
     155#if SVC_EXTENSION
    154156#if JCTVC_M0259_LAMBDAREFINEMENT
    155 private:
    156157  Double  xCalEnhLambdaFactor( Double deltaQP , Double beta );
    157158#endif
     159#endif //SVC_EXTENSION
    158160};
    159161
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    129129  if (m_bUseSAO)
    130130  {
    131 #if HM_CLEANUP_SAO
    132131#if AUXILIARY_PICTURES
    133132    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     
    140139    m_cEncSAO.createEncData();
    141140#endif
    142 #else
    143     m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
    144     m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
    145     m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
    146     m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
    147     m_cEncSAO.createEncBuffer();
    148 #endif
    149141  }
    150142#if ADAPTIVE_QP_SELECTION
     
    161153                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
    162154  }
    163   // if SBAC-based RD optimization is used
    164   if( m_bUseSBACRD )
    165   {
    166     m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
     155
     156  m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
    167157#if FAST_BIT_EST
    168     m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
    169 #else
    170     m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
    171 #endif
    172    
    173     for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    174     {
    175       m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
     158  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
     159#else
     160  m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
     161#endif
     162
     163  for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
     164  {
     165    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
    176166#if FAST_BIT_EST
    177       m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
    178 #else
    179       m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
    180 #endif
    181      
    182       for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    183       {
    184         m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
     167    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
     168#else
     169    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
     170#endif
     171
     172    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     173    {
     174      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
    185175#if FAST_BIT_EST
    186         m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
    187 #else
    188         m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
    189 #endif
    190         m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
    191       }
     176      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
     177#else
     178      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
     179#endif
     180      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
    192181    }
    193182  }
     
    226215    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
    227216  }
    228   if( m_bUseSBACRD )
    229   {
    230     m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
    231     m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
    232     for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
    233     {
    234       m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
    235       m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
    236      
    237       for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    238       {
    239         m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
    240         m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
    241 
    242         for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    243         {
    244           m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
    245           m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
    246           m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
    247         }
     217
     218  m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
     219  m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
     220  for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
     221  {
     222    m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
     223    m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
     224
     225    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
     226    {
     227      m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
     228      m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
     229
     230      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     231      {
     232        m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
     233        m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
     234        m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
    248235      }
    249236    }
     
    259246  if (m_cSPS.getUseSAO())
    260247  {
    261 #if HM_CLEANUP_SAO
    262248    m_cEncSAO.destroyEncData();
    263249    m_cEncSAO.destroy();
    264 #else
    265     m_cEncSAO.destroy();
    266     m_cEncSAO.destroyEncBuffer();
    267 #endif
    268250  }
    269251  m_cLoopFilter.        destroy();
    270252  m_cRateCtrl.          destroy();
    271   // SBAC RD
    272   if( m_bUseSBACRD )
    273   {
    274     Int iDepth;
     253
     254  Int iDepth;
     255  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
     256  {
     257    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
     258    {
     259      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
     260      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
     261    }
     262  }
     263
     264  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
     265  {
     266    delete [] m_pppcRDSbacCoder[iDepth];
     267    delete [] m_pppcBinCoderCABAC[iDepth];
     268  }
     269
     270  delete [] m_pppcRDSbacCoder;
     271  delete [] m_pppcBinCoderCABAC;
     272
     273  for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
     274  {
    275275    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    276276    {
    277277      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    278278      {
    279         delete m_pppcRDSbacCoder[iDepth][iCIIdx];
    280         delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
    281       }
    282     }
    283    
     279        delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
     280        delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
     281      }
     282    }
     283
    284284    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    285285    {
    286       delete [] m_pppcRDSbacCoder[iDepth];
    287       delete [] m_pppcBinCoderCABAC[iDepth];
    288     }
    289    
    290     delete [] m_pppcRDSbacCoder;
    291     delete [] m_pppcBinCoderCABAC;
    292 
    293     for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
    294     {
    295       for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    296       {
    297         for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    298         {
    299           delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
    300           delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
    301         }
    302       }
    303 
    304       for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
    305       {
    306         delete [] m_ppppcRDSbacCoders  [ui][iDepth];
    307         delete [] m_ppppcBinCodersCABAC[ui][iDepth];
    308       }
    309       delete[] m_ppppcRDSbacCoders  [ui];
    310       delete[] m_ppppcBinCodersCABAC[ui];
    311     }
    312     delete[] m_ppppcRDSbacCoders;
    313     delete[] m_ppppcBinCodersCABAC;
    314   }
     286      delete [] m_ppppcRDSbacCoders  [ui][iDepth];
     287      delete [] m_ppppcBinCodersCABAC[ui][iDepth];
     288    }
     289    delete[] m_ppppcRDSbacCoders  [ui];
     290    delete[] m_ppppcBinCodersCABAC[ui];
     291  }
     292  delete[] m_ppppcRDSbacCoders;
     293  delete[] m_ppppcBinCodersCABAC;
    315294  delete[] m_pcSbacCoders;
    316295  delete[] m_pcBinCoderCABACs;
     
    525504    TComPic *pcTopField;
    526505    xGetNewPicBuffer( pcTopField );
    527 #if !HM_CLEANUP_SAO
    528     pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
    529 #endif
    530506    pcTopField->setReconMark (false);
    531507   
     
    568544    TComPic* pcBottomField;
    569545    xGetNewPicBuffer( pcBottomField );
    570 #if !HM_CLEANUP_SAO
    571     pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
    572 #endif
    573546    pcBottomField->setReconMark (false);
    574547   
     
    652625    TComPic *pcTopField;
    653626    xGetNewPicBuffer( pcTopField );
    654 #if !HM_CLEANUP_SAO
    655     pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
    656 #endif
    657627    pcTopField->setReconMark (false);
    658628   
     
    706676    TComPic* pcBottomField;
    707677    xGetNewPicBuffer( pcBottomField );
    708 #if !HM_CLEANUP_SAO
    709     pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
    710 #endif
    711678    pcBottomField->setReconMark (false);
    712679   
     
    912879#endif
    913880    }
    914 #if !HM_CLEANUP_SAO
    915     if (getUseSAO())
    916     {
    917       rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
    918     }
    919 #endif
    920881    m_cListPic.pushBack( rpcPic );
    921882  }
     
    1001962 
    1002963  m_cSPS.setTMVPFlagsPresent(false);
    1003   m_cSPS.setUseLossless   ( m_useLossless  );
    1004964
    1005965  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
     
    1038998  m_cSPS.setMaxTLayers( m_maxTempLayer );
    1039999  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
    1040   for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
     1000  for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
    10411001  {
    10421002    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
     
    10981058  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
    10991059
    1100 #if REPN_FORMAT_IN_VPS
    1101   Int lowestQP;
    1102 #if O0096_REP_FORMAT_INDEX
    1103   if( m_layerId == 0 )
    1104   {
    1105     lowestQP = - m_cSPS.getQpBDOffsetY();
    1106   }
    1107   else
    1108   {
    1109     lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
    1110   }
    1111 #else
    1112   if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
    1113   {
    1114     lowestQP = - m_cSPS.getQpBDOffsetY();
    1115   }
    1116   else
    1117   {
    1118     lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
    1119   }
    1120 #endif
    1121 #else
    1122   Int lowestQP = - m_cSPS.getQpBDOffsetY();
    1123 #endif
    1124 
    1125   if(getUseLossless())
    1126   {
    1127     if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )
    1128     {
    1129       bUseDQP = false;
    1130     }
    1131     else
    1132     {
    1133       bUseDQP = true;
    1134     }
    1135   }
    1136   else
    1137   {
    1138     if(bUseDQP == false)
    1139     {
    1140       if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
    1141       {
    1142         bUseDQP = true;
    1143       }
    1144     }
     1060  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
     1061  {
     1062    bUseDQP = true;
    11451063  }
    11461064
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r588 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
     
    7373  UInt                    m_uiNumAllPicCoded;             ///< number of coded pictures
    7474  TComList<TComPic*>      m_cListPic;                     ///< dynamic list of pictures
    75 #if SVC_EXTENSION
    76   static Int              m_iSPSIdCnt;                    ///< next Id number for SPS   
    77   static Int              m_iPPSIdCnt;                    ///< next Id number for PPS   
    78 #if AVC_SYNTAX
    79   fstream*                m_pBLSyntaxFile;
    80 #endif
    81 #endif
    82  
     75 
    8376  // encoder search
    8477  TEncSearch              m_cSearch;                      ///< encoder search class
     
    130123 
    131124#if SVC_EXTENSION
    132 
     125  static Int              m_iSPSIdCnt;                    ///< next Id number for SPS   
     126  static Int              m_iPPSIdCnt;                    ///< next Id number for PPS   
     127#if AVC_SYNTAX
     128  fstream*                m_pBLSyntaxFile;
     129#endif
    133130  TEncTop**               m_ppcTEncTop;
    134131  TEncTop*                getLayerEnc(UInt layer)   { return m_ppcTEncTop[layer]; }
     
    163160  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
    164161#if SVC_EXTENSION
    165   Void xInitILRP();
     162  Void  xInitILRP();
    166163#endif
    167164public:
     
    210207  Int getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid );
    211208  TComScalingList*        getScalingList        () { return  &m_scalingList;         }
     209  // -------------------------------------------------------------------------------------------------------------------
     210  // encoder function
     211  // -------------------------------------------------------------------------------------------------------------------
     212
     213  /// encode several number of pictures until end-of-sequence
    212214#if SVC_EXTENSION
    213215  Void                    setLayerEnc(TEncTop** p) {m_ppcTEncTop = p;}
     
    224226#endif
    225227  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
    226 #endif //SVC_EXTENSION
    227 
    228   // -------------------------------------------------------------------------------------------------------------------
    229   // encoder function
    230   // -------------------------------------------------------------------------------------------------------------------
    231 
    232   /// encode several number of pictures until end-of-sequence
    233 #if SVC_EXTENSION
    234228  TComPic** getIlpList() { return m_cIlpPic; }
    235229#if REF_IDX_MFM
     
    281275
    282276#endif // __TENCTOP__
     277
  • trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp

    r494 r595  
    44 * granted under this license.
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TLibEncoder/WeightPredAnalysis.h

    r313 r595  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2013, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
Note: See TracChangeset for help on using the changeset viewer.