Changeset 872 in 3DVCSoftware for trunk/source


Ignore:
Timestamp:
27 Mar 2014, 10:11:29 (12 years ago)
Author:
tech
Message:

Merged HTM-10.0-dev0@871. (MV-HEVC 7 HLS)

Location:
trunk/source
Files:
148 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/App/TAppDecoder/TAppDecCfg.cpp

    r773 r872  
    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/App/TAppDecoder/TAppDecCfg.h

    r773 r872  
    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/App/TAppDecoder/TAppDecTop.cpp

    r773 r872  
    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 *
     
    140140    AOF( m_pScaleOffsetFile );
    141141  }
     142#if !FIX_CAM_PARS_COLLECTOR
    142143  m_cCamParsCollector.init( m_pScaleOffsetFile );
     144#endif
    143145#endif
    144146  InputByteStream bytestream(bitstreamFile);
     
    165167  Bool firstSlice        = true;
    166168#endif
    167  
     169  Bool loopFiltered      = false;
     170
    168171  while (!!bitstreamFile)
    169172  {
     
    206209      read(nalu, nalUnit);
    207210#if H_MV     
     211#if H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO
     212      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer)
     213          || !isNaluWithinTargetDecLayerIdSet(&nalu)
     214          || nalu.m_layerId > MAX_NUM_LAYER_IDS-1
     215          || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_layerId > 0)           
     216#if H_MV_HLS_7_MISC_P0130_EOS
     217          || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0)           
     218#endif
     219         )
     220#else
    208221      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) || nalu.m_layerId > MAX_NUM_LAYER_IDS-1 )
     222#endif
    209223      {
    210224        bNewPicture = false;
     
    234248          }
    235249
     250#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     251          if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= vps->getNumOutputLayerSets() )
     252          {
     253            fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", vps->getNumOutputLayerSets() - 1 );           
     254            exit(EXIT_FAILURE);
     255          }
     256#endif
    236257          m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx );
    237258        }
     259
     260#if FIX_CAM_PARS_COLLECTOR
     261#if H_3D
     262        if (nalu.m_nalUnitType == NAL_UNIT_VPS )
     263        {       
     264         
     265          m_cCamParsCollector.init( m_pScaleOffsetFile, m_tDecTop[decIdx]->getPrefetchedVPS() );
     266        }       
     267#endif
     268#endif
    238269        bNewPicture       = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag;
    239270        if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag )       
     
    278309          bitstreamFile.seekg(location-streamoff(3));
    279310          bytestream.reset();
     311#if H_MV_ENC_DEC_TRAC
    280312#if ENC_DEC_TRACE
    281 #if H_MV_ENC_DEC_TRAC
    282313          const Bool resetCounter = false;
    283314          if ( resetCounter )
     
    287318          else
    288319          {
    289             g_disableHLSTrace = true;     // Trancing of second parsing of SH is not carried out
    290           }         
    291 #else
    292           g_nSymbolCounter = symCount;
    293 #endif
    294 #endif
    295         }
    296       }
    297     }
    298     if (bNewPicture || !bitstreamFile)
    299     {
    300 #if H_MV
    301       assert( decIdxLastPic != -1 );
    302       m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
    303 #else
    304       m_cTDecTop.executeLoopFilters(poc, pcListPic);
    305 #endif
     320            g_disableHLSTrace = true;     // Tracing of second parsing of SH is not carried out
     321          }     
     322#endif
     323#endif
     324        }
     325      }
     326    }
     327    if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS )
     328    {
     329      if (!loopFiltered || bitstreamFile)
     330      {
     331#if H_MV
     332        assert( decIdxLastPic != -1 );
     333        m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet );
     334#else
     335        m_cTDecTop.executeLoopFilters(poc, pcListPic);
     336#endif
     337      }
     338      loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS);
    306339    }
    307340#if H_3D
     
    351384#endif
    352385      }
     386      if (nalu.m_nalUnitType == NAL_UNIT_EOS)
     387      {
     388#if H_MV
     389        xFlushOutput( pcListPic, decIdxLastPic );
     390#else
     391        xFlushOutput( pcListPic );
     392#endif
     393      }
    353394      // write reconstruction to file
    354395      if(bNewPicture)
     
    462503#endif
    463504{
     505
     506  if (pcListPic->empty())
     507  {
     508    return;
     509  }
     510
    464511  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
    465512  Int numPicsNotYetDisplayed = 0;
     
    647694#endif
    648695{
    649   if(!pcListPic)
     696  if(!pcListPic || pcListPic->empty())
    650697  {
    651698    return;
  • trunk/source/App/TAppDecoder/TAppDecTop.h

    r773 r872  
    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/App/TAppDecoder/decmain.cpp

    r608 r872  
    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/App/TAppEncoder/TAppEncCfg.cpp

    r833 r872  
    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 *
     
    388388  ("VpsNumLayerSets",       m_vpsNumLayerSets    , 1                    , "Number of layer sets")   
    389389  ("LayerIdsInSet_%d",      m_layerIdsInSets     , std::vector<Int>(1,0), MAX_VPS_OP_SETS_PLUS1 ,"LayerIds of Layer set") 
     390#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     391  ("DefaultTargetOutputLayerIdc"     , m_defaultTargetOutputLayerIdc     , 0, "Specifies output layers of layer sets, 0: output all layers, 1: output highest layer, 2: specified by LayerIdsInDefOutputLayerSet")
     392#else
    390393  ("DefaultOneTargetOutputLayerFlag"  , m_defaultOneTargetOutputLayerIdc  , 0, "Output highest layer of layer sets by default")
     394#endif
    391395  ("OutputLayerSetIdx",     m_outputLayerSetIdx  , std::vector<Int>(0,0), "Indices of layer sets used as additional output layer sets") 
     396
     397#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     398  ("LayerIdsInAddOutputLayerSet_%d", m_layerIdsInAddOutputLayerSet      , std::vector<Int>(0,0), MAX_VPS_ADD_OUTPUT_LAYER_SETS, "Indices in VPS of output layers in additional output layer set") 
     399  ("LayerIdsInDefOutputLayerSet_%d", m_layerIdsInDefOutputLayerSet      , std::vector<Int>(0,0), MAX_VPS_OP_SETS_PLUS1, "Indices in VPS of output layers in layer set") 
     400#else
    392401  ("LayerIdsInAddOutputLayerSet_%d", m_layerIdsInAddOutputLayerSet      , std::vector<Int>(1,0), MAX_VPS_ADD_OUTPUT_LAYER_SETS, "LayerIds of additional output layers") 
     402#endif
    393403  ("ProfileLevelTierIdx",   m_profileLevelTierIdx, std::vector<Int>(1,0), "Indices to profile level tier")
    394404 
     
    444454  ("QuadtreeTUMaxDepthIntra", m_uiQuadtreeTUMaxDepthIntra, 1u, "Depth of TU tree for intra CUs")
    445455  ("QuadtreeTUMaxDepthInter", m_uiQuadtreeTUMaxDepthInter, 2u, "Depth of TU tree for inter CUs")
     456#if H_MV 
    446457  // Coding structure parameters
    447 #if H_MV 
    448458  ("IntraPeriod,-ip",         m_iIntraPeriod,std::vector<Int>(1,-1), "Intra period in frames, (-1: only first frame), per layer")
    449459#else
     460  // Coding structure paramters
    450461("IntraPeriod,-ip",         m_iIntraPeriod,              -1, "Intra period in frames, (-1: only first frame)")
    451462#endif
     
    492503  ("RDOQTS",                        m_useRDOQTS,                true )
    493504  ("RDpenalty",                     m_rdPenalty,                0,  "RD-penalty for 32x32 TU for intra in non-intra slices. 0:disbaled  1:RD-penalty  2:maximum RD-penalty")
    494   // Entropy coding parameters
    495   ("SBACRD",                         m_bUseSBACRD,                      true, "SBAC based RD estimation")
    496505 
    497506  // Deblocking filter parameters
     
    539548  ("MaxNumOffsetsPerPic",      m_maxNumOffsetsPerPic,       2048,  "Max number of SAO offset per picture (Default: 2048)")   
    540549  ("SAOLcuBoundary",           m_saoLcuBoundary,            false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas")
    541   ("SAOLcuBasedOptimization",  m_saoLcuBasedOptimization,   true,  "0: SAO picture-based optimization, 1: SAO LCU-based optimization ")
    542550  ("SliceMode",                m_sliceMode,                0,     "0: Disable all Recon slice limits, 1: Enforce max # of LCUs, 2: Enforce max # of bytes, 3:specify tiles per dependent slice")
    543551  ("SliceArgument",            m_sliceArgument,            0,     "Depending on SliceMode being:"
     
    559567  ("PCMInputBitDepthFlag",     m_bPCMInputBitDepthFlag,     true)
    560568  ("PCMFilterDisableFlag",     m_bPCMFilterDisableFlag,    false)
    561 
    562   ("LosslessCuEnabled",        m_useLossless, false)
    563569
    564570  ("WeightedPredP,-wpP",          m_useWeightedPred,               false,      "Use weighted prediction in P slices")
     
    590596  ("CFM", m_bUseCbfFastMode, false, "Cbf fast mode setting")
    591597  ("ESD", m_useEarlySkipDetection, false, "Early SKIP detection setting")
    592 #if RATE_CONTROL_LAMBDA_DOMAIN
    593598  ( "RateControl",         m_RCEnableRateControl,   false, "Rate control: enable rate control" )
    594599  ( "TargetBitrate",       m_RCTargetBitrate,           0, "Rate control: target bitrate" )
    595 #if M0036_RC_IMPROVEMENT
    596600  ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit,     0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" )
    597 #else
    598   ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, false, "Rate control: keep hierarchical bit allocation in rate control algorithm" )
    599 #endif
    600601  ( "LCULevelRateControl", m_RCLCULevelRC,           true, "Rate control: true: LCU level RC; false: picture level RC" )
    601602  ( "RCLCUSeparateModel",  m_RCUseLCUSeparateModel,  true, "Rate control: use LCU level separate R-lambda model" )
     
    610611  ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
    611612#endif
    612 #else
    613   ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")
    614   ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")
    615   ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")
    616 
    617 #if KWU_RC_VIEWRC_E0227
    618   ("ViewWiseTargetBits, -vtbr" ,  m_viewTargetBits,  std::vector<Int>(1, 32), "View-wise target bit-rate setting")
    619   ("TargetBitAssign, -ta", m_viewWiseRateCtrl, false, "View-wise rate control on/off")
    620 #endif
    621 #if KWU_RC_MADPRED_E0227
    622   ("DepthMADPred, -dm", m_depthMADPred, (UInt)0, "Depth based MAD prediction on/off")
    623 #endif
    624 #endif
    625 
    626613#if H_MV
    627614
    628615  // DBP Size
     616#if !H_MV_HLS_7_FIX_SET_DPB_SIZE
    629617  ("SubLayerFlagInfoPresentFlag",  m_subLayerFlagInfoPresentFlag , false                                           , "SubLayerFlagInfoPresentFlag")
     618#endif
    630619  // VPS VUI
    631620  ("VpsVuiPresentFlag"           , m_vpsVuiPresentFlag           , false                                           , "VpsVuiPresentFlag           ")
    632621  ("CrossLayerPicTypeAlignedFlag", m_crossLayerPicTypeAlignedFlag, false                                           , "CrossLayerPicTypeAlignedFlag")  // Could actually be derived by the encoder
    633622  ("CrossLayerIrapAlignedFlag"   , m_crossLayerIrapAlignedFlag   , false                                           , "CrossLayerIrapAlignedFlag   ")  // Could actually be derived by the encoder
     623#if H_MV_HLS_7_MISC_P0068_21
     624  ("AllLayersIdrAlignedFlag"     , m_allLayersIdrAlignedFlag     , false                                           , "CrossLayerIrapAlignedFlag   ")  // Could actually be derived by the encoder
     625#endif
    634626  ("BitRatePresentVpsFlag"       , m_bitRatePresentVpsFlag       , false                                           , "BitRatePresentVpsFlag       ")
    635627  ("PicRatePresentVpsFlag"       , m_picRatePresentVpsFlag       , false                                           , "PicRatePresentVpsFlag       ")
     
    653645
    654646  ("TransquantBypassEnableFlag", m_TransquantBypassEnableFlag, false, "transquant_bypass_enable_flag indicator in PPS")
    655   ("CUTransquantBypassFlagValue", m_CUTransquantBypassFlagValue, false, "Fixed cu_transquant_bypass_flag value, when transquant_bypass_enable_flag is enabled")
     647  ("CUTransquantBypassFlagForce", m_CUTransquantBypassFlagForce, false, "Force transquant bypass mode, when transquant_bypass_enable_flag is enabled")
    656648  ("RecalculateQPAccordingToLambda", m_recalculateQPAccordingToLambda, false, "Recalculate QP values according to lambda values. Do not suggest to be enabled in all intra case")
    657649  ("StrongIntraSmoothing,-sis",      m_useStrongIntraSmoothing,           true, "Enable strong intra smoothing for 32x32 blocks")
     
    745737  ("SEISOPDescription",              m_SOPDescriptionSEIEnabled,              0, "Control generation of SOP description SEI messages")
    746738  ("SEIScalableNesting",             m_scalableNestingSEIEnabled,              0, "Control generation of scalable nesting SEI messages")
     739#if H_MV_HLS_7_SEI_P0204_26
     740  ("SubBitstreamPropSEIEnabled",              m_subBistreamPropSEIEnabled,    false                     ,"Enable signaling of sub-bitstream property SEI message")
     741  ("SEISubBitstreamNumAdditionalSubStreams",  m_sbPropNumAdditionalSubStreams,0, "Number of substreams for which additional information is signalled")
     742  ("SEISubBitstreamSubBitstreamMode",         m_sbPropSubBitstreamMode,       std::vector< Int  >(1,0)  ,"Specifies mode of generation of the i-th sub-bitstream (0 or 1)")
     743  ("SEISubBitstreamOutputLayerSetIdxToVps",   m_sbPropOutputLayerSetIdxToVps, std::vector< Int  >(1,0)  ,"Specifies output layer set index of the i-th sub-bitstream ")
     744  ("SEISubBitstreamHighestSublayerId",        m_sbPropHighestSublayerId,      std::vector< Int  >(1,0)  ,"Specifies highest TemporalId of the i-th sub-bitstream")
     745  ("SEISubBitstreamAvgBitRate",               m_sbPropAvgBitRate,             std::vector< Int  >(1,0)  ,"Specifies average bit rate of the i-th sub-bitstream")
     746  ("SEISubBitstreamMaxBitRate",               m_sbPropMaxBitRate,             std::vector< Int  >(1,0)  ,"Specifies maximum bit rate of the i-th sub-bitstream")
     747#endif
    747748#if H_3D
    748749  ("CameraParameterFile,cpf", m_pchCameraParameterFile,    (Char *) 0, "Camera Parameter File Name")
     
    14311432  }
    14321433
     1434#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1435  xConfirmPara( m_defaultTargetOutputLayerIdc < 0 || m_defaultTargetOutputLayerIdc > 2, "Default target output layer idc must greater than or equal to 0 and less than or equal to 2." ); 
     1436
     1437  if( m_defaultTargetOutputLayerIdc != 2 )
     1438  {
     1439    Bool anyDefaultOutputFlag = false;   
     1440    for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++)
     1441    {
     1442      anyDefaultOutputFlag = anyDefaultOutputFlag || ( m_layerIdsInDefOutputLayerSet[lsIdx].size() != 0 );
     1443    }   
     1444    printf( "\nWarning: Ignoring LayerIdsInDefOutputLayerSet parameters, since defaultTargetOuputLayerIdc is not equal 2.\n" );   
     1445  }
     1446  else 
     1447  { 
     1448    for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++)
     1449    {
     1450      for (Int i = 0; i < m_layerIdsInDefOutputLayerSet[ lsIdx ].size(); i++)
     1451      {
     1452        Bool inLayerSetFlag = false;
     1453        for (Int j = 0; j < m_layerIdsInSets[ lsIdx].size(); j++ )
     1454        {
     1455          if ( m_layerIdsInSets[ lsIdx ][ j ] == m_layerIdsInDefOutputLayerSet[ lsIdx ][ i ] )
     1456          {
     1457            inLayerSetFlag = true;
     1458            break;
     1459          }       
     1460        }
     1461        xConfirmPara( !inLayerSetFlag, "All output layers of a output layer set must be included in corresponding layer set.");
     1462      }
     1463    }
     1464  }
     1465#else
    14331466  xConfirmPara( m_defaultOneTargetOutputLayerIdc < 0 || m_defaultOneTargetOutputLayerIdc > 1, "Default one target output layer idc must be equal to 0 or equal to 1" );
     1467#endif
    14341468  xConfirmPara( m_profileLevelTierIdx.size() < m_vpsNumLayerSets + m_outputLayerSetIdx.size(), "The number of Profile Level Tier indices must be equal to the number of layer set plus the number of output layer set indices" );
    14351469
     
    20212055      m_maxTempLayer = m_GOPList[i].m_temporalId+1;
    20222056    }
    2023     xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P', "Slice type must be equal to B or P");
     2057    xConfirmPara(m_GOPList[i].m_sliceType!='B'&&m_GOPList[i].m_sliceType!='P'&&m_GOPList[i].m_sliceType!='I', "Slice type must be equal to B or P or I");
    20242058  }
    20252059  for(Int i=0; i<MAX_TLAYER; i++)
     
    21722206  }
    21732207
    2174 #if RATE_CONTROL_LAMBDA_DOMAIN
    21752208  if ( m_RCEnableRateControl )
    21762209  {
     
    21852218    xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" );
    21862219  }
    2187 #else
    2188   if(m_enableRateCtrl)
    2189   {
    2190     Int numLCUInWidth  = (m_iSourceWidth  / m_uiMaxCUWidth) + (( m_iSourceWidth  %  m_uiMaxCUWidth ) ? 1 : 0);
    2191     Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight %  m_uiMaxCUHeight) ? 1 : 0);
    2192     Int numLCUInPic    =  numLCUInWidth * numLCUInHeight;
    2193 
    2194     xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );
    2195 
    2196 #if !KWU_FIX_URQ
    2197     m_iMaxDeltaQP       = MAX_DELTA_QP;
    2198 #endif
    2199     m_iMaxCuDQPDepth    = MAX_CUDQP_DEPTH;
    2200   }
    2201 #endif
    22022220#if H_MV
    22032221  // VPS VUI
     
    22232241#endif
    22242242
    2225   xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagValue, "CUTransquantBypassFlagValue cannot be 1 when TransquantBypassEnableFlag is 0");
     2243  xConfirmPara(!m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce, "CUTransquantBypassFlagForce cannot be 1 when TransquantBypassEnableFlag is 0");
    22262244
    22272245  xConfirmPara(m_log2ParallelMergeLevel < 2, "Log2ParallelMergeLevel should be larger than or equal to 2");
     
    22332251#if H_MV
    22342252  }
     2253  }
     2254#endif
     2255#if H_MV_HLS_7_SEI_P0204_26
     2256  // Check input parameters for Sub-bitstream property SEI message
     2257  if( m_subBistreamPropSEIEnabled )
     2258  {
     2259    xConfirmPara(
     2260      (this->m_sbPropNumAdditionalSubStreams != m_sbPropAvgBitRate.size() )
     2261      || (this->m_sbPropNumAdditionalSubStreams != m_sbPropHighestSublayerId.size() )
     2262      || (this->m_sbPropNumAdditionalSubStreams != m_sbPropMaxBitRate.size() )
     2263      || (this->m_sbPropNumAdditionalSubStreams != m_sbPropOutputLayerSetIdxToVps.size() )
     2264      || (this->m_sbPropNumAdditionalSubStreams != m_sbPropSubBitstreamMode.size()), "Some parameters of some sub-bitstream not defined");
     2265
     2266    for( Int i = 0; i < m_sbPropNumAdditionalSubStreams; i++ )
     2267    {
     2268      xConfirmPara( m_sbPropSubBitstreamMode[i] < 0 || m_sbPropSubBitstreamMode[i] > 1, "Mode value should be 0 or 1" );
     2269      xConfirmPara( m_sbPropHighestSublayerId[i] < 0 || m_sbPropHighestSublayerId[i] > MAX_TLAYER-1, "Maximum sub-layer ID out of range" );
     2270      xConfirmPara( m_sbPropOutputLayerSetIdxToVps[i] < 0 || m_sbPropOutputLayerSetIdxToVps[i] >= MAX_VPS_OUTPUTLAYER_SETS, "OutputLayerSetIdxToVps should be within allowed range" );
     2271    }
    22352272  }
    22362273#endif
     
    23432380  printf("Internal bit depth           : (Y:%d, C:%d)\n", m_internalBitDepthY, m_internalBitDepthC );
    23442381  printf("PCM sample bit depth         : (Y:%d, C:%d)\n", g_uiPCMBitDepthLuma, g_uiPCMBitDepthChroma );
    2345 #if RATE_CONTROL_LAMBDA_DOMAIN
    23462382  printf("RateControl                  : %d\n", m_RCEnableRateControl );
    23472383  if(m_RCEnableRateControl)
     
    23732409#endif
    23742410  }
    2375 #else
    2376   printf("RateControl                  : %d\n", m_enableRateCtrl);
    2377   if(m_enableRateCtrl)
    2378   {
    2379     printf("TargetBitrate                : %d\n", m_targetBitrate);
    2380     printf("NumLCUInUnit                 : %d\n", m_numLCUInUnit);
    2381 
    2382 #if KWU_RC_MADPRED_E0227
    2383     printf("Depth based MAD prediction   : %d\n", m_depthMADPred);
    2384 #endif
    2385 #if KWU_RC_VIEWRC_E0227
    2386     printf("View-wise Rate control       : %d\n", m_viewWiseRateCtrl);
    2387     if(m_viewWiseRateCtrl)
    2388     {
    2389 
    2390       printf("ViewWiseTargetBits           : ");
    2391       for (Int i = 0 ; i < m_iNumberOfViews ; i++)
    2392         printf("%d ", m_viewTargetBits[i]);
    2393       printf("\n");
    2394     }
    2395     else
    2396     {
    2397       printf("TargetBitrate                : %d\n", m_targetBitrate );
    2398     }
    2399 #endif
    2400   }
    2401 #endif
    24022411  printf("Max Num Merge Candidates     : %d\n", m_maxNumMergeCand);
    24032412#if H_3D
     
    24292438  printf("IBD:%d ", g_bitDepthY > m_inputBitDepthY || g_bitDepthC > m_inputBitDepthC);
    24302439  printf("HAD:%d ", m_bUseHADME           );
    2431   printf("SRD:%d ", m_bUseSBACRD          );
    24322440  printf("RDQ:%d ", m_useRDOQ            );
    24332441  printf("RDQTS:%d ", m_useRDOQTS        );
     
    24582466#endif
    24592467  printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0);
    2460   printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0));
    2461 
    2462   printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 );
     2468  if (m_TransquantBypassEnableFlag && m_CUTransquantBypassFlagForce)
     2469  {
     2470    printf("TransQuantBypassEnabled: =1 ");
     2471  }
     2472  else
     2473  {
     2474    printf("TransQuantBypassEnabled:%d ", (m_TransquantBypassEnableFlag)? 1:0 );
     2475  }
    24632476  printf("WPP:%d ", (Int)m_useWeightedPred);
    24642477  printf("WPB:%d ", (Int)m_useWeightedBiPred);
  • trunk/source/App/TAppEncoder/TAppEncCfg.h

    r833 r872  
    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  Int                    m_vpsNumLayerSets;                   ///< Number of layer sets
    9090  std::vector< std::vector<Int> > m_layerIdsInSets;           ///< LayerIds in vps of layer set
     91#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     92  Int                    m_defaultTargetOutputLayerIdc;       ///< Specifies output layers of layer sets, 0: output all layers, 1: output highest layers, 2: specified by LayerIdsInDefOuputLayerSet
     93#else
    9194  Int                    m_defaultOneTargetOutputLayerIdc;    ///< Output highest layer of layer sets by default when equal to 1
     95#endif
    9296  std::vector<Int>       m_outputLayerSetIdx;                 ///< Indices of layer sets used as additional output layer sets 
    9397  std::vector< std::vector<Int> > m_layerIdsInAddOutputLayerSet; ///< LayerIds in vps of additional output layers
     98#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     99  std::vector< std::vector<Int> > m_layerIdsInDefOutputLayerSet; ///< Indices in vps of output layers in layer sets
     100#endif
    94101  std::vector<Int>       m_profileLevelTierIdx;               ///< Indices of of profile level tier
    95102 
     
    99106
    100107  // DBP Size
     108#if !H_MV_HLS_7_FIX_SET_DPB_SIZE
    101109  Bool m_subLayerFlagInfoPresentFlag;
     110#endif
    102111
    103112  // VPS VUI
     
    105114  Bool m_crossLayerPicTypeAlignedFlag;
    106115  Bool m_crossLayerIrapAlignedFlag;
     116#if H_MV_HLS_7_MISC_P0068_21
     117  Bool m_allLayersIdrAlignedFlag;
     118#endif
    107119  Bool m_bitRatePresentVpsFlag;
    108120  Bool m_picRatePresentVpsFlag;
     
    259271  Bool      m_bPCMInputBitDepthFlag;                          ///< 0: PCM bit-depth is internal bit-depth. 1: PCM bit-depth is input bit-depth.
    260272
    261   // coding tool (lossless)
    262   Bool      m_useLossless;                                    ///< flag for using lossless coding
     273  // coding tool (SAO)
    263274#if H_MV
    264275  std::vector<Bool> m_bUseSAO;
     
    268279  Int       m_maxNumOffsetsPerPic;                            ///< SAO maximun number of offset per picture
    269280  Bool      m_saoLcuBoundary;                                 ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
    270   Bool      m_saoLcuBasedOptimization;                        ///< SAO LCU-based optimization
    271281  // coding tools (loop filter)
    272282#if H_MV
     
    288298
    289299  // coding tools (encoder-only parameters)
    290   Bool      m_bUseSBACRD;                                     ///< flag for using RD optimization based on SBAC
    291300  Bool      m_bUseASR;                                        ///< flag for using adaptive motion search range
    292301  Bool      m_bUseHADME;                                      ///< flag for using HAD in sub-pel ME
     
    372381  Int       m_TMVPModeId;
    373382  Int       m_signHideFlag;
    374 #if RATE_CONTROL_LAMBDA_DOMAIN
    375383  Bool      m_RCEnableRateControl;                ///< enable rate control or not
    376384  Int       m_RCTargetBitrate;                    ///< target bitrate when rate control is enabled
    377 #if M0036_RC_IMPROVEMENT
    378385  Int       m_RCKeepHierarchicalBit;              ///< 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation
    379 #else
    380   Bool      m_RCKeepHierarchicalBit;              ///< whether keeping hierarchical bit allocation structure or not
    381 #endif
    382386  Bool      m_RCLCULevelRC;                       ///< true: LCU level rate control; false: picture level rate control
    383387  Bool      m_RCUseLCUSeparateModel;              ///< use separate R-lambda model at LCU level
     
    392396  UInt       m_depthMADPred;
    393397#endif
    394 #else
    395   Bool      m_enableRateCtrl;                                   ///< Flag for using rate control algorithm
    396   Int       m_targetBitrate;                                 ///< target bitrate
    397   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit
    398 
    399 #if KWU_RC_VIEWRC_E0227
    400   vector<Int>     m_viewTargetBits;
    401   Bool      m_viewWiseRateCtrl;                              ///< Flag for using view-wise rate control
    402 #endif
    403 #if KWU_RC_MADPRED_E0227
    404   UInt       m_depthMADPred;
    405 #endif
    406 #endif
    407398  Int       m_useScalingListId;                               ///< using quantization matrix
    408399  Char*     m_scalingListFile;                                ///< quantization matrix file name
    409400
    410401  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    411   Bool      m_CUTransquantBypassFlagValue;                    ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.
     402  Bool      m_CUTransquantBypassFlagForce;                    ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true.
    412403
    413404  Bool      m_recalculateQPAccordingToLambda;                 ///< recalculate QP value according to the lambda value
     
    449440  Int       m_log2MaxMvLengthHorizontal;                      ///< Indicate the maximum absolute value of a decoded horizontal MV component in quarter-pel luma units
    450441  Int       m_log2MaxMvLengthVertical;                        ///< Indicate the maximum absolute value of a decoded vertical MV component in quarter-pel luma units
    451 
     442#if H_MV_HLS_7_SEI_P0204_26
     443  Bool              m_subBistreamPropSEIEnabled;
     444  Int               m_sbPropNumAdditionalSubStreams;
     445  std::vector<Int>  m_sbPropSubBitstreamMode;
     446  std::vector<Int>  m_sbPropOutputLayerSetIdxToVps;
     447  std::vector<Int>  m_sbPropHighestSublayerId;
     448  std::vector<Int>  m_sbPropAvgBitRate;
     449  std::vector<Int>  m_sbPropMaxBitRate;
     450#endif
    452451#if H_3D
    453452  // Camera parameters
  • trunk/source/App/TAppEncoder/TAppEncTop.cpp

    r833 r872  
    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 *
     
    127127  xSetRepFormat            ( vps );
    128128  xSetLayerSets            ( vps );
     129#if H_MV_HLS_7_FIX_SET_DPB_SIZE
     130  xSetDpbSize              ( vps );
     131#endif
    129132  xSetVPSVUI               ( vps );
    130133#if H_3D
     
    309312#endif
    310313
    311   Int lowestQP;
    312   lowestQP =  - 6*(g_bitDepthY - 8); // XXX: check
    313 
    314 #if H_MV
    315   if ((m_iMaxDeltaQP == 0 ) && (m_iQP[layerIdInVps] == lowestQP) && (m_useLossless == true))
    316 #else
    317   if ((m_iMaxDeltaQP == 0 ) && (m_iQP == lowestQP) && (m_useLossless == true))
    318 #endif
    319   {
    320     m_bUseAdaptiveQP = false;
    321   }
    322314  m_cTEncTop.setUseAdaptiveQP                ( m_bUseAdaptiveQP  );
    323315  m_cTEncTop.setQPAdaptationRange            ( m_iQPAdaptationRange );
    324316 
    325317  //====== Tool list ========
    326   m_cTEncTop.setUseSBACRD                    ( m_bUseSBACRD   );
    327318  m_cTEncTop.setDeltaQpRD                    ( m_uiDeltaQpRD  );
    328319  m_cTEncTop.setUseASR                       ( m_bUseASR      );
    329320  m_cTEncTop.setUseHADME                     ( m_bUseHADME    );
    330   m_cTEncTop.setUseLossless                  ( m_useLossless );
    331321#if H_MV
    332322  m_cTEncTop.setdQPs                         ( m_aidQP[layerIdInVps]   );
     
    396386
    397387  m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary);
    398   m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization);
    399388  m_cTEncTop.setPCMInputBitDepthFlag  ( m_bPCMInputBitDepthFlag);
    400389  m_cTEncTop.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag);
     
    440429  m_cTEncTop.setSOPDescriptionSEIEnabled( m_SOPDescriptionSEIEnabled );
    441430  m_cTEncTop.setScalableNestingSEIEnabled( m_scalableNestingSEIEnabled );
     431#if H_MV_HLS_7_SEI_P0204_26
     432  m_cTEncTop.setSubBitstreamPropSEIEnabled( m_subBistreamPropSEIEnabled );
     433  if( m_subBistreamPropSEIEnabled )
     434  {
     435    m_cTEncTop.setNumAdditionalSubStreams ( m_sbPropNumAdditionalSubStreams );
     436    m_cTEncTop.setSubBitstreamMode        ( m_sbPropSubBitstreamMode );
     437    m_cTEncTop.setOutputLayerSetIdxToVps  ( m_sbPropOutputLayerSetIdxToVps );
     438    m_cTEncTop.setHighestSublayerId       ( m_sbPropHighestSublayerId );
     439    m_cTEncTop.setAvgBitRate              ( m_sbPropAvgBitRate );
     440    m_cTEncTop.setMaxBitRate              ( m_sbPropMaxBitRate );
     441  }
     442#endif
    442443  m_cTEncTop.setUniformSpacingIdr          ( m_iUniformSpacingIdr );
    443444  m_cTEncTop.setNumColumnsMinus1           ( m_iNumColumnsMinus1 );
     
    461462  m_cTEncTop.setScalingListFile            ( m_scalingListFile   );
    462463  m_cTEncTop.setSignHideFlag(m_signHideFlag);
    463 #if RATE_CONTROL_LAMBDA_DOMAIN
    464464#if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
    465465  if(!m_cTEncTop.getIsDepth())    //only for texture
     
    482482  m_cTEncTop.setInitialQP           ( m_RCInitialQP );
    483483  m_cTEncTop.setForceIntraQP        ( m_RCForceIntraQP );
    484 
    485484#if KWU_RC_MADPRED_E0227
    486485  if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
    487486  {
    488487    m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
    489 
    490488    if(m_cTEncTop.getUseDepthMADPred())
    491489    {
     
    498496  {
    499497    m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
    500 
    501498    if(m_iNumberOfViews == 1)
    502499    {
     
    552549  }
    553550#endif
    554 #else
    555 #if KWU_RC_VIEWRC_E0227 || KWU_RC_MADPRED_E0227
    556   if(!m_cTEncTop.getIsDepth())    //only for texture
    557   {
    558     m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
    559     m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
    560     m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
    561   }
    562   else
    563   {
    564     m_cTEncTop.setUseRateCtrl         ( 0 );
    565   }
    566 #else
    567   m_cTEncTop.setUseRateCtrl         ( m_enableRateCtrl );
    568   m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
    569   m_cTEncTop.setNumLCUInUnit        ( m_numLCUInUnit);
    570 #endif
    571 
    572  
    573 #if KWU_RC_MADPRED_E0227
    574   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
    575   {
    576     m_cTEncTop.setUseDepthMADPred(layerIdInVps ? m_depthMADPred       : 0);
    577 
    578     if(m_cTEncTop.getUseDepthMADPred())
    579     {
    580       m_cTEncTop.setCamParam(&m_cCameraData);
    581     }
    582   }
    583 #endif
    584 
    585 #if KWU_RC_VIEWRC_E0227
    586   if(m_cTEncTop.getUseRateCtrl() && !m_cTEncTop.getIsDepth())
    587   {
    588     m_cTEncTop.setUseViewWiseRateCtrl(m_viewWiseRateCtrl);
    589     if(m_iNumberOfViews == 1)
    590     {
    591       if(m_viewWiseRateCtrl)
    592       {
    593         m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
    594       }
    595       else
    596       {
    597         m_cTEncTop.setTargetBitrate       ( m_targetBitrate );
    598       }
    599     }
    600     else
    601     {
    602       if(m_viewWiseRateCtrl)
    603       {
    604         m_cTEncTop.setTargetBitrate(m_viewTargetBits[layerIdInVps>>1]);
    605       }
    606       else
    607       {
    608         if(m_iNumberOfViews == 2)
    609         {
    610           if(m_cTEncTop.getViewId() == 0)
    611           {
    612             m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*80)/100 );
    613           }
    614           else if(m_cTEncTop.getViewId() == 1)
    615           {
    616             m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*20)/100 );
    617           }
    618         }
    619         else if(m_iNumberOfViews == 3)
    620         {
    621           if(m_cTEncTop.getViewId() == 0)
    622           {
    623             m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*66)/100 );
    624           }
    625           else if(m_cTEncTop.getViewId() == 1)
    626           {
    627             m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
    628           }
    629           else if(m_cTEncTop.getViewId() == 2)
    630           {
    631             m_cTEncTop.setTargetBitrate              ( (m_targetBitrate*17)/100 );
    632           }
    633         }
    634         else
    635         {
    636           m_cTEncTop.setTargetBitrate              ( m_targetBitrate );
    637         }
    638       }
    639     }
    640   }
    641 #endif
    642 #endif
    643551  m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag);
    644   m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue);
     552  m_cTEncTop.setCUTransquantBypassFlagForceValue(m_CUTransquantBypassFlagForce);
    645553  m_cTEncTop.setUseRecalculateQPAccordingToLambda( m_recalculateQPAccordingToLambda );
    646554  m_cTEncTop.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
     
    932840    }
    933841
    934 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
    935     for(Int layer=0; layer < m_numberOfLayers; layer++ )
    936     {
    937       if(m_acTEncTopList[layer]->getUseRateCtrl()  && !m_acTEncTopList[layer]->getIsDepth())
    938       {
    939         m_acTEncTopList[layer]->getRateCtrl()->updateRCGOPStatus();
    940       }
    941     }
    942 #endif
    943 
    944842    gopSize = maxGopSize;
    945843  }
     
    12031101      rateStatsAccum(au, stats);   
    12041102    }
    1205 #endif   
     1103#endif
    12061104  }
    12071105}
     
    12211119    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    12221120    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    1223     case NAL_UNIT_CODED_SLICE_TLA_R:
     1121    case NAL_UNIT_CODED_SLICE_TSA_R:
    12241122    case NAL_UNIT_CODED_SLICE_TSA_N:
    12251123    case NAL_UNIT_CODED_SLICE_STSA_R:
     
    16081506}
    16091507
     1508#if H_MV_HLS_7_FIX_SET_DPB_SIZE
     1509Void TAppEncTop::xSetDpbSize                ( TComVPS& vps )
     1510{
     1511  // These settings need to be verified
     1512
     1513  TComDpbSize* dpbSize = vps.getDpbSize();
     1514
     1515  assert ( dpbSize != 0 );
     1516
     1517  for( Int i = 1; i < vps.getNumOutputLayerSets(); i++ )
     1518  { 
     1519    std::vector<Int> targetDecLayerIdList = vps.getTargetDecLayerIdList( i );
     1520    Bool subLayerFlagInfoPresentFlag = false;
     1521
     1522#if H_MV_HLS_7_HRD_P0156_7
     1523    for( Int j = 0; j  <=  vps.getMaxSubLayersInLayerSetMinus1( i ); j++ )
     1524#else
     1525    for( Int j = 0; j  <=  vps.getMaxTLayers() - 1 ; j++ )
     1526#endif
     1527    {   
     1528      Bool subLayerDpbInfoPresentFlag = false;
     1529#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1530      assert( vps.getNumSubDpbs( vps.getLayerSetIdxForOutputLayerSet( i ) ) == targetDecLayerIdList.size() );
     1531      for( Int k = 0; k < vps.getNumSubDpbs( vps.getLayerSetIdxForOutputLayerSet( i )); k++ )   
     1532#else
     1533      assert( vps.getNumSubDpbs( vps.getOutputLayerSetIdxMinus1( i ) + 1 ) == targetDecLayerIdList.size() );
     1534      for( Int k = 0; k < vps.getNumSubDpbs( vps.getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
     1535#endif
     1536      {
     1537        Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[k] );           
     1538#if H_MV_HLS7_GEN
     1539        // TBD. Some derivation based on output layer set might be added here.
     1540#endif
     1541        dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, m_maxDecPicBufferingMvc[ layerIdInVps ][ j ] - 1 );
     1542        if ( j > 0 )
     1543        {
     1544          subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) != dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j - 1 ) );
     1545        }
     1546      }       
     1547
     1548      Int maxNumReorderPics = MIN_INT;
     1549      for ( Int idx = 0; idx < targetDecLayerIdList.size(); idx++ )
     1550      {
     1551        Int layerIdInVps = vps.getLayerIdInVps( targetDecLayerIdList[ idx ] );
     1552        maxNumReorderPics = std::max( maxNumReorderPics, m_numReorderPicsMvc[ layerIdInVps ][ j ] );
     1553      }
     1554      assert( maxNumReorderPics != MIN_INT );
     1555
     1556      dpbSize->setMaxVpsNumReorderPics( i, j, maxNumReorderPics );
     1557      if ( j > 0 )
     1558      {
     1559        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsNumReorderPics( i, j ) != dpbSize->getMaxVpsNumReorderPics( i, j - 1 ) );
     1560      }
     1561
     1562      // To Be Done !
     1563      // dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, xx );
     1564      if ( j > 0 )
     1565      {
     1566        subLayerDpbInfoPresentFlag = subLayerDpbInfoPresentFlag || ( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ) != dpbSize->getMaxVpsLatencyIncreasePlus1( i, j - 1  ) );
     1567      }
     1568
     1569      if( j > 0 ) 
     1570      {
     1571        dpbSize->setSubLayerDpbInfoPresentFlag( i, j, subLayerDpbInfoPresentFlag );
     1572        subLayerFlagInfoPresentFlag = subLayerFlagInfoPresentFlag || subLayerDpbInfoPresentFlag;
     1573      }       
     1574    } 
     1575    dpbSize->setSubLayerFlagInfoPresentFlag( i, subLayerFlagInfoPresentFlag );
     1576  } 
     1577}
     1578#else
    16101579Void TAppEncTop::xSetDpbSize                ( TComVPS& vps )
    16111580{
     
    16201589    std::vector<Int> targetDecLayerIdList = vps.getTargetDecLayerIdList( i );
    16211590    dpbSize->setSubLayerFlagInfoPresentFlag( i, m_subLayerFlagInfoPresentFlag );
    1622 
    16231591    if ( dpbSize->getSubLayerFlagInfoPresentFlag( i ) )
    16241592    {
     
    16631631  } 
    16641632}
    1665 
     1633#endif
    16661634
    16671635Void TAppEncTop::xSetLayerSets( TComVPS& vps )
     
    16691637  // Layer sets
    16701638  vps.setVpsNumLayerSetsMinus1   ( m_vpsNumLayerSets - 1 );
     1639#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    16711640  vps.setVpsNumberLayerSetsMinus1( vps.getVpsNumLayerSetsMinus1() );
     1641#endif
    16721642   
    16731643  for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++ )
     
    16861656  Int numAddOuputLayerSets = (Int) m_outputLayerSetIdx.size();
    16871657  // Additional output layer sets + profileLevelTierIdx
     1658#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1659  vps.setDefaultTargetOutputLayerIdc      ( m_defaultTargetOutputLayerIdc );   
     1660  vps.setNumAddOutputLayerSets            ( numAddOuputLayerSets          );
     1661  vps.initTargetLayerIdLists();
     1662#else
    16881663  vps.setDefaultOneTargetOutputLayerIdc   ( m_defaultOneTargetOutputLayerIdc );
    16891664  vps.setMoreOutputLayerSetsThanDefaultFlag( numAddOuputLayerSets       != 0 );   
    16901665  vps.setNumAddOutputLayerSetsMinus1       ( numAddOuputLayerSets - 1        );
    1691 
    1692 
    1693 
     1666#endif
     1667
     1668#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1669  for (Int olsIdx = 0; olsIdx < m_vpsNumLayerSets + numAddOuputLayerSets; olsIdx++)
     1670  {
     1671    Int addOutLsIdx = olsIdx - m_vpsNumLayerSets;     
     1672   
     1673    vps.setOutputLayerSetIdxMinus1( olsIdx, ( ( addOutLsIdx < 0 ) ?  olsIdx  : m_outputLayerSetIdx[ addOutLsIdx ] ) - 1 );
     1674
     1675    std::vector<Int>& layerIdList    = m_layerIdsInSets[ vps.getLayerSetIdxForOutputLayerSet( olsIdx ) ];
     1676
     1677    if (vps.getDefaultTargetOutputLayerIdc() == 2 || addOutLsIdx >= 0 )
     1678    {
     1679      for ( Int i = 0; i < layerIdList.size(); i++)
     1680      {
     1681        vps.setOutputLayerFlag( olsIdx, i, ( olsIdx == 0 && i == 0 ) ? vps.inferOutputLayerFlag(olsIdx, i ) : false ); // This is a software only fix for a bug in the spec. In spec outputLayerFlag neither present nor inferred for this case !
     1682      }
     1683
     1684      std::vector<Int>& outLayerIdList = ( addOutLsIdx >= 0 ) ? m_layerIdsInAddOutputLayerSet[addOutLsIdx] : m_layerIdsInDefOutputLayerSet[olsIdx];
     1685
     1686      Bool outputLayerInLayerSetFlag = false;
     1687      for (Int j = 0; j < outLayerIdList.size(); j++)
     1688      {   
     1689        for (Int i = 0; i < layerIdList.size(); i++ )
     1690        {
     1691          if ( layerIdList[ i ] == outLayerIdList[ j ] )
     1692          {
     1693            vps.setOutputLayerFlag( olsIdx, i, true );       
     1694            outputLayerInLayerSetFlag = true;
     1695            break;
     1696          }
     1697        }
     1698        assert( outputLayerInLayerSetFlag ); // The output layer is not not in the layer set.
     1699      }
     1700    }
     1701    else
     1702    {
     1703      for ( Int i = 0; i < layerIdList.size(); i++)
     1704      {
     1705        vps.setOutputLayerFlag( olsIdx, i, vps.inferOutputLayerFlag( olsIdx, i ) );       
     1706      }
     1707    }
     1708
     1709    vps.deriveTargetLayerIdList(  olsIdx );
     1710
     1711    if ( olsIdx > 0 )
     1712    {
     1713      vps.setProfileLevelTierIdx( olsIdx, m_profileLevelTierIdx[ olsIdx ] );
     1714    }
     1715
     1716    vps.setAltOutputLayerFlag( olsIdx , false);     
     1717  }
     1718#else
    16941719  for (Int lsIdx = 0; lsIdx < m_vpsNumLayerSets; lsIdx++)
    16951720  {
     
    17291754  }
    17301755  vps.deriveTargetLayerIdLists();
     1756#endif
    17311757}
    17321758
     
    17351761  vps.setVpsVuiPresentFlag( m_vpsVuiPresentFlag );
    17361762
     1763#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
     1764  TComVPSVUI* pcVPSVUI = vps.getVPSVUI(  );
     1765  assert( pcVPSVUI );
     1766#endif
     1767
    17371768  if ( m_vpsVuiPresentFlag )
    17381769  {
     1770#if !H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
    17391771    TComVPSVUI* pcVPSVUI = vps.getVPSVUI(  );
    17401772
    17411773    assert( pcVPSVUI );
    1742 
     1774#endif
    17431775
    17441776    // All this stuff could actually be derived by the encoder,
     
    17471779    pcVPSVUI->setCrossLayerPicTypeAlignedFlag( m_crossLayerPicTypeAlignedFlag );
    17481780    pcVPSVUI->setCrossLayerIrapAlignedFlag   ( m_crossLayerIrapAlignedFlag    );
    1749 
     1781#if H_MV_HLS_7_MISC_P0068_21
     1782    pcVPSVUI->setAllLayersIdrAlignedFlag     ( m_allLayersIdrAlignedFlag      );
     1783#endif
    17501784    pcVPSVUI->setBitRatePresentVpsFlag( m_bitRatePresentVpsFlag );
    17511785    pcVPSVUI->setPicRatePresentVpsFlag( m_picRatePresentVpsFlag );
     
    17531787    if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
    17541788    {
     1789#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1790      for( Int i = 0; i  <=  vps.getVpsNumLayerSetsMinus1(); i++ )
     1791#else
    17551792      for( Int i = 0; i  <=  vps.getVpsNumberLayerSetsMinus1(); i++ )
     1793#endif
    17561794      {
    17571795        for( Int j = 0; j  <=  vps.getMaxTLayers(); j++ )
     
    18711909    pcVPSVUI->setVpsVuiBspHrdPresentFlag( false ); // TBD
    18721910  }
     1911#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
     1912  else
     1913  {
     1914    pcVPSVUI->setCrossLayerIrapAlignedFlag   ( false   );
     1915  }
     1916#endif
    18731917}
    18741918#endif
     
    19632007}
    19642008#endif
    1965 
    19662009//! \}
  • trunk/source/App/TAppEncoder/TAppEncTop.h

    r773 r872  
    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/App/TAppEncoder/encmain.cpp

    r608 r872  
    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/App/utils/BitrateTargeting/ExtractBitrates.cpp

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/ExtractBitrates.h

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/ExtractBitratesMain.cpp

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.cpp

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiers.h

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/GuessLambdaModifiersMain.cpp

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/RuntimeError.h

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/BitrateTargeting/encode.shl

    r56 r872  
    44# granted under this license. 
    55#
    6 # Copyright (c) 2010-2012, ITU/ISO/IEC
     6# Copyright (c) 2010-2014, ITU/ISO/IEC
    77# All rights reserved.
    88#
  • trunk/source/App/utils/BitrateTargeting/encodeCommand.sh

    r56 r872  
    66# granted under this license. 
    77#
    8 # Copyright (c) 2010-2012, ITU/ISO/IEC
     8# Copyright (c) 2010-2014, ITU/ISO/IEC
    99# All rights reserved.
    1010#
  • trunk/source/App/utils/BitrateTargeting/makefile

    r56 r872  
    44# granted under this license. 
    55#
    6 # Copyright (c) 2010-2012, ITU/ISO/IEC
     6# Copyright (c) 2010-2014, ITU/ISO/IEC
    77# All rights reserved.
    88#
  • trunk/source/App/utils/BitrateTargeting/targetBitrates.sh

    r56 r872  
    66# granted under this license. 
    77#
    8 # Copyright (c) 2010-2012, ITU/ISO/IEC
     8# Copyright (c) 2010-2014, ITU/ISO/IEC
    99# All rights reserved.
    1010#
  • trunk/source/App/utils/annexBbytecount.cpp

    r56 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/App/utils/convert_NtoMbit_YCbCr.cpp

    r608 r872  
    44 * granted under this license. 
    55 *
    6  * Copyright (c) 2010-2012, ITU/ISO/IEC
     6 * Copyright (c) 2010-2014, ITU/ISO/IEC
    77 * All rights reserved.
    88 *
  • trunk/source/Lib/TAppCommon/program_options_lite.cpp

    r608 r872  
    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 *
     
    3838#include <list>
    3939#include <map>
     40#include <algorithm>
    4041#include "program_options_lite.h"
    4142#include  "../TLibCommon/TypeDef.h"
  • trunk/source/Lib/TAppCommon/program_options_lite.h

    r608 r872  
    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/TLibCommon/AccessUnit.h

    r608 r872  
    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/TLibCommon/CommonDef.h

    r864 r872  
    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 *
     
    6161#if H_MV
    6262#define NV_VERSION        "10.0r1"                ///< Current software version
    63 #define HM_VERSION        "12.0"                ///<
     63#define HM_VERSION        "13.0"                ///<
    6464#else
    65 #define NV_VERSION        "12.0"                 ///< Current software version
     65#define NV_VERSION        "13.0"                 ///< Current software version
    6666#endif
    6767
     
    247247 
    248248  NAL_UNIT_CODED_SLICE_TSA_N,     // 2
    249   NAL_UNIT_CODED_SLICE_TLA_R,       // 3
     249  NAL_UNIT_CODED_SLICE_TSA_R,       // 3
    250250 
    251251  NAL_UNIT_CODED_SLICE_STSA_N,    // 4
  • trunk/source/Lib/TLibCommon/ContextModel.cpp

    r608 r872  
    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/TLibCommon/ContextModel.h

    r608 r872  
    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/TLibCommon/ContextModel3DBuffer.cpp

    r608 r872  
    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/TLibCommon/ContextModel3DBuffer.h

    r608 r872  
    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/TLibCommon/ContextTables.h

    r833 r872  
    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 *
     
    4242//! \ingroup TLibCommon
    4343//! \{
    44 #define FIX827 1 ///< Fix for issue #827: CABAC init tables
    45 #define FIX712 1 ///< Fix for issue #712: CABAC init tables
    4644
    4745// ====================================================================================================================
     
    5856
    5957#define NUM_PART_SIZE_CTX             4       ///< number of context models for partition size
    60 #define NUM_CU_AMP_CTX                1       ///< number of context models for partition size (AMP)
    6158#define NUM_PRED_MODE_CTX             1       ///< number of context models for prediction mode
    6259
     
    6966#define NUM_REF_NO_CTX                2       ///< number of context models for reference index
    7067#define NUM_TRANS_SUBDIV_FLAG_CTX     3       ///< number of context models for transform subdivision flags
    71 #define NUM_QT_CBF_CTX                5       ///< number of context models for QT CBF
     68#define NUM_QT_CBF_CTX                4       ///< number of context models for QT CBF
    7269#define NUM_QT_ROOT_CBF_CTX           1       ///< number of context models for QT ROOT CBF
    7370#define NUM_DELTA_QP_CTX              3       ///< number of context models for dQP
     
    8885#define NUM_ABS_FLAG_CTX_CHROMA        2      ///< number of context models for greater than 2 flag of chroma
    8986
    90 #define NUM_MVP_IDX_CTX               2       ///< number of context models for MVP index
     87#define NUM_MVP_IDX_CTX               1       ///< number of context models for MVP index
    9188
    9289#define NUM_SAO_MERGE_FLAG_CTX        1       ///< number of context models for SAO merge flags
     
    199196INIT_PART_SIZE[3][NUM_PART_SIZE_CTX] = 
    200197{
    201   { 154,  139,  CNU,  CNU, },
    202   { 154,  139,  CNU,  CNU, },
    203   { 184,  CNU,  CNU,  CNU, },
    204 };
    205 
    206 static const UChar
    207 INIT_CU_AMP_POS[3][NUM_CU_AMP_CTX] = 
    208 {
    209   { 154, },
    210   { 154, },
    211   { CNU, },
     198  { 154,  139,  154,  154 },
     199  { 154,  139,  154,  154 },
     200  { 184,  CNU,  CNU,  CNU },
    212201};
    213202
     
    271260INIT_QT_CBF[3][2*NUM_QT_CBF_CTX] = 
    272261{
    273   { 153,  111,  CNU,  CNU,  CNU,  149,   92,  167,  CNU,  CNU, },
    274   { 153,  111,  CNU,  CNU,  CNU,  149,  107,  167,  CNU,  CNU, },
    275   { 111,  141,  CNU,  CNU,  CNU,   94,  138,  182,  CNU,  CNU, },
     262  { 153,  111,  CNU,  CNU,   149,   92,  167,  154 },
     263  { 153,  111,  CNU,  CNU,   149,  107,  167,  154 },
     264  { 111,  141,  CNU,  CNU,    94,  138,  182,  154 },
    276265};
    277266
     
    339328INIT_MVP_IDX[3][NUM_MVP_IDX_CTX] = 
    340329{
    341   { 168,  CNU, },
    342   { 168,  CNU, },
    343   { CNU,  CNU, },
     330  { 168 },
     331  { 168 },
     332  { CNU },
    344333};
    345334
     
    355344INIT_SAO_TYPE_IDX[3][NUM_SAO_TYPE_IDX_CTX] =
    356345{
    357 #if FIX827
    358346  { 160, },
    359347  { 185, },
    360348  { 200, },
    361 #else
    362   { 200, },
    363   { 185, },
    364   { 160, },
    365 #endif
    366349};
    367350
     
    369352INIT_TRANS_SUBDIV_FLAG[3][NUM_TRANS_SUBDIV_FLAG_CTX] =
    370353{
    371 #if FIX712
    372354  { 224,  167,  122, },
    373355  { 124,  138,   94, },
    374356  { 153,  138,  138, },
    375 #else
    376   { 153,  138,  138, },
    377   { 124,  138,   94, },
    378   { 224,  167,  122, },
    379 #endif
    380357};
    381358
  • trunk/source/Lib/TLibCommon/NAL.h

    r608 r872  
    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 *
     
    7979    return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R
    8080        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N
    81         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA_R
     81        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R
    8282        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N
    8383        || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R
  • trunk/source/Lib/TLibCommon/SEI.cpp

    r608 r872  
    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/TLibCommon/SEI.h

    r608 r872  
    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 *
     
    7272    SCALABLE_NESTING                     = 133,
    7373    REGION_REFRESH_INFO                  = 134,
     74#if H_MV_HLS_7_SEI_P0204_26
     75    SUB_BITSTREAM_PROPERTY               = 139,    // Final PayloadType to be defined after finalization
     76#endif
    7477  };
    7578 
     
    363366};
    364367
     368#if H_MV_HLS_7_SEI_P0204_26
     369class SEISubBitstreamProperty : public SEI
     370{
     371public:
     372  PayloadType payloadType() const { return SUB_BITSTREAM_PROPERTY; }
     373
     374  SEISubBitstreamProperty():   m_activeVpsId(-1), m_numAdditionalSubStreams(0) {}
     375  virtual ~SEISubBitstreamProperty() {}
     376
     377  Int  m_activeVpsId;
     378  Int  m_numAdditionalSubStreams;
     379  std::vector<Int>  m_subBitstreamMode;
     380  std::vector<Int>  m_outputLayerSetIdxToVps;
     381  std::vector<Int>  m_highestSublayerId;
     382  std::vector<Int>  m_avgBitRate;
     383  std::vector<Int>  m_maxBitRate;
     384};
     385#endif
     386
    365387typedef std::list<SEI*> SEIMessages;
    366388
  • trunk/source/Lib/TLibCommon/TComBitCounter.h

    r608 r872  
    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/TLibCommon/TComBitStream.cpp

    r608 r872  
    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/TLibCommon/TComBitStream.h

    r608 r872  
    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/TLibCommon/TComCABACTables.cpp

    r608 r872  
    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/TLibCommon/TComCABACTables.h

    r608 r872  
    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/TLibCommon/TComDataCU.cpp

    r863 r872  
    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 *
     
    488488}
    489489
    490 const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src)
    491 {
    492   this->tileID = src.tileID;
    493   this->sliceID= src.sliceID;
    494   this->startSU= src.startSU;
    495   this->endSU  = src.endSU;
    496   this->widthSU= src.widthSU;
    497   this->heightSU=src.heightSU;
    498   this->posX   = src.posX;
    499   this->posY   = src.posY;
    500   this->width  = src.width;
    501   this->height = src.height;
    502   ::memcpy(this->isBorderAvailable, src.isBorderAvailable, sizeof(Bool)*((Int)NUM_SGU_BORDER));
    503   this->allBordersAvailable = src.allBordersAvailable;
    504 
    505   return *this;
    506 }
    507 
    508 
    509490// ====================================================================================================================
    510491// Public member functions
     
    801782*- set last-coded qp value according to input last-coded qp
    802783*/
    803 Void TComDataCU::initEstData( UInt uiDepth, Int qp )
     784Void TComDataCU::initEstData( UInt uiDepth, Int qp, Bool bTransquantBypass )
    804785{
    805786  m_dTotalCost         = MAX_DOUBLE;
     
    829810      m_pePartSize[ui] = SIZE_NONE;
    830811      m_pePredMode[ui] = MODE_NONE;
    831       m_CUTransquantBypass[ui] = false;
     812      m_CUTransquantBypass[ui] = bTransquantBypass;
    832813      m_pbIPCMFlag[ui] = 0;
    833814      m_phQP[ui] = qp;
     
    47374718
    47384719          TComMvField cMVField;
    4739 
    47404720#if !HTM10RC1_FIX
    47414721          UChar ucInterDir = pcTextureCU->getInterDir( uiPartIdx );
     
    59965976    xAddMVPCand( pInfo, eRefPicList, iRefIdx, uiPartIdxLT, MD_ABOVE_LEFT);
    59975977  }
    5998   bAdded = bAddedSmvp;
    5999   if (pInfo->iN==2) bAdded = true;
    6000 
    6001   if(!bAdded)
     5978
     5979  if (!bAddedSmvp)
    60025980  {
    60035981    bAdded = xAddMVPCandOrder( pInfo, eRefPicList, iRefIdx, uiPartIdxRT, MD_ABOVE_RIGHT);
     
    66576635{
    66586636  return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU;
    6659 }
    6660 
    6661 /** Set neighboring blocks availabilities for non-deblocked filtering
    6662  * \param numLCUInPicWidth number of LCUs in picture width
    6663  * \param numLCUInPicHeight number of LCUs in picture height
    6664  * \param numSUInLCUWidth number of SUs in LCU width
    6665  * \param numSUInLCUHeight number of SUs in LCU height
    6666  * \param picWidth picture width
    6667  * \param picHeight picture height
    6668  * \param bIndependentSliceBoundaryEnabled true for independent slice boundary enabled
    6669  * \param bTopTileBoundary true means that top boundary coincides tile boundary
    6670  * \param bDownTileBoundary true means that bottom boundary coincides tile boundary
    6671  * \param bLeftTileBoundary true means that left boundary coincides tile boundary
    6672  * \param bRightTileBoundary true means that right boundary coincides tile boundary
    6673  * \param bIndependentTileBoundaryEnabled true for independent tile boundary enabled
    6674  */
    6675 Void TComDataCU::setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt /*numLCUInPicHeight*/, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
    6676                                                     ,std::vector<Bool>& LFCrossSliceBoundary
    6677                                                     ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
    6678                                                     ,Bool bIndependentTileBoundaryEnabled)
    6679 {
    6680   UInt numSUInLCU = numSUInLCUWidth*numSUInLCUHeight;
    6681   Int* pSliceIDMapLCU = m_piSliceSUMap;
    6682   Bool onlyOneSliceInPic = ((Int)LFCrossSliceBoundary.size() == 1);
    6683   UInt uiLPelX, uiTPelY;
    6684   UInt width, height;
    6685   Bool bPicRBoundary, bPicBBoundary, bPicTBoundary, bPicLBoundary;
    6686   Bool bLCURBoundary= false, bLCUBBoundary= false, bLCUTBoundary= false, bLCULBoundary= false;
    6687   Bool* pbAvailBorder;
    6688   Bool* pbAvail;
    6689   UInt rTLSU, rBRSU, widthSU, heightSU;
    6690   UInt zRefSU;
    6691   Int* pRefID;
    6692   Int* pRefMapLCU;
    6693   UInt rTRefSU= 0, rBRefSU= 0, rLRefSU= 0, rRRefSU= 0;
    6694   Int* pRRefMapLCU= NULL;
    6695   Int* pLRefMapLCU= NULL;
    6696   Int* pTRefMapLCU= NULL;
    6697   Int* pBRefMapLCU= NULL;
    6698   Int  sliceID;
    6699   UInt numSGU = (UInt)m_vNDFBlock.size();
    6700 
    6701   for(Int i=0; i< numSGU; i++)
    6702   {
    6703     NDBFBlockInfo& rSGU = m_vNDFBlock[i];
    6704 
    6705     sliceID = rSGU.sliceID;
    6706     uiLPelX = rSGU.posX;
    6707     uiTPelY = rSGU.posY;
    6708     width   = rSGU.width;
    6709     height  = rSGU.height;
    6710     rTLSU     = g_auiZscanToRaster[ rSGU.startSU ];
    6711     rBRSU     = g_auiZscanToRaster[ rSGU.endSU   ];
    6712     widthSU   = rSGU.widthSU;
    6713     heightSU  = rSGU.heightSU;
    6714 
    6715     pbAvailBorder = rSGU.isBorderAvailable;
    6716 
    6717     bPicTBoundary= (uiTPelY == 0                       )?(true):(false);
    6718     bPicLBoundary= (uiLPelX == 0                       )?(true):(false);
    6719     bPicRBoundary= (!(uiLPelX+ width < picWidth )  )?(true):(false);
    6720     bPicBBoundary= (!(uiTPelY + height < picHeight))?(true):(false);
    6721 
    6722     bLCULBoundary = (rTLSU % numSUInLCUWidth == 0)?(true):(false);
    6723     bLCURBoundary = ( (rTLSU+ widthSU) % numSUInLCUWidth == 0)?(true):(false);
    6724     bLCUTBoundary = ( (UInt)(rTLSU / numSUInLCUWidth)== 0)?(true):(false);
    6725     bLCUBBoundary = ( (UInt)(rBRSU / numSUInLCUWidth) == (numSUInLCUHeight-1) )?(true):(false);
    6726 
    6727     //       SGU_L
    6728     pbAvail = &(pbAvailBorder[SGU_L]);
    6729     if(bPicLBoundary)
    6730     {
    6731       *pbAvail = false;
    6732     }
    6733     else if (onlyOneSliceInPic)
    6734     {
    6735       *pbAvail = true;
    6736     }
    6737     else
    6738     {
    6739       //      bLCULBoundary = (rTLSU % uiNumSUInLCUWidth == 0)?(true):(false);
    6740       if(bLCULBoundary)
    6741       {
    6742         rLRefSU     = rTLSU + numSUInLCUWidth -1;
    6743         zRefSU      = g_auiRasterToZscan[rLRefSU];
    6744         pRefMapLCU = pLRefMapLCU= (pSliceIDMapLCU - numSUInLCU);
    6745       }
    6746       else
    6747       {
    6748         zRefSU   = g_auiRasterToZscan[rTLSU - 1];
    6749         pRefMapLCU  = pSliceIDMapLCU;
    6750       }
    6751       pRefID = pRefMapLCU + zRefSU;
    6752       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6753     }
    6754 
    6755     //       SGU_R
    6756     pbAvail = &(pbAvailBorder[SGU_R]);
    6757     if(bPicRBoundary)
    6758     {
    6759       *pbAvail = false;
    6760     }
    6761     else if (onlyOneSliceInPic)
    6762     {
    6763       *pbAvail = true;
    6764     }
    6765     else
    6766     {
    6767       //       bLCURBoundary = ( (rTLSU+ uiWidthSU) % uiNumSUInLCUWidth == 0)?(true):(false);
    6768       if(bLCURBoundary)
    6769       {
    6770         rRRefSU      = rTLSU + widthSU - numSUInLCUWidth;
    6771         zRefSU       = g_auiRasterToZscan[rRRefSU];
    6772         pRefMapLCU  = pRRefMapLCU= (pSliceIDMapLCU + numSUInLCU);
    6773       }
    6774       else
    6775       {
    6776         zRefSU       = g_auiRasterToZscan[rTLSU + widthSU];
    6777         pRefMapLCU  = pSliceIDMapLCU;
    6778       }
    6779       pRefID = pRefMapLCU + zRefSU;
    6780       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6781     }
    6782 
    6783     //       SGU_T
    6784     pbAvail = &(pbAvailBorder[SGU_T]);
    6785     if(bPicTBoundary)
    6786     {
    6787       *pbAvail = false;
    6788     }
    6789     else if (onlyOneSliceInPic)
    6790     {
    6791       *pbAvail = true;
    6792     }
    6793     else
    6794     {
    6795       //      bLCUTBoundary = ( (UInt)(rTLSU / uiNumSUInLCUWidth)== 0)?(true):(false);
    6796       if(bLCUTBoundary)
    6797       {
    6798         rTRefSU      = numSUInLCU - (numSUInLCUWidth - rTLSU);
    6799         zRefSU       = g_auiRasterToZscan[rTRefSU];
    6800         pRefMapLCU  = pTRefMapLCU= (pSliceIDMapLCU - (numLCUInPicWidth*numSUInLCU));
    6801       }
    6802       else
    6803       {
    6804         zRefSU       = g_auiRasterToZscan[rTLSU - numSUInLCUWidth];
    6805         pRefMapLCU  = pSliceIDMapLCU;
    6806       }
    6807       pRefID = pRefMapLCU + zRefSU;
    6808       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6809     }
    6810 
    6811     //       SGU_B
    6812     pbAvail = &(pbAvailBorder[SGU_B]);
    6813     if(bPicBBoundary)
    6814     {
    6815       *pbAvail = false;
    6816     }
    6817     else if (onlyOneSliceInPic)
    6818     {
    6819       *pbAvail = true;
    6820     }
    6821     else
    6822     {
    6823       //      bLCUBBoundary = ( (UInt)(rBRSU / uiNumSUInLCUWidth) == (uiNumSUInLCUHeight-1) )?(true):(false);
    6824       if(bLCUBBoundary)
    6825       {
    6826         rBRefSU      = rTLSU % numSUInLCUWidth;
    6827         zRefSU       = g_auiRasterToZscan[rBRefSU];
    6828         pRefMapLCU  = pBRefMapLCU= (pSliceIDMapLCU + (numLCUInPicWidth*numSUInLCU));
    6829       }
    6830       else
    6831       {
    6832         zRefSU       = g_auiRasterToZscan[rTLSU + (heightSU*numSUInLCUWidth)];
    6833         pRefMapLCU  = pSliceIDMapLCU;
    6834       }
    6835       pRefID = pRefMapLCU + zRefSU;
    6836       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6837     }
    6838 
    6839     //       SGU_TL
    6840     pbAvail = &(pbAvailBorder[SGU_TL]);
    6841     if(bPicTBoundary || bPicLBoundary)
    6842     {
    6843       *pbAvail = false;
    6844     }
    6845     else if (onlyOneSliceInPic)
    6846     {
    6847       *pbAvail = true;
    6848     }
    6849     else
    6850     {
    6851       if(bLCUTBoundary && bLCULBoundary)
    6852       {
    6853         zRefSU       = numSUInLCU -1;
    6854         pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth+1)*numSUInLCU);
    6855       }
    6856       else if(bLCUTBoundary)
    6857       {
    6858         zRefSU       = g_auiRasterToZscan[ rTRefSU- 1];
    6859         pRefMapLCU  = pTRefMapLCU;
    6860       }
    6861       else if(bLCULBoundary)
    6862       {
    6863         zRefSU       = g_auiRasterToZscan[ rLRefSU- numSUInLCUWidth ];
    6864         pRefMapLCU  = pLRefMapLCU;
    6865       }
    6866       else //inside LCU
    6867       {
    6868         zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth -1];
    6869         pRefMapLCU  = pSliceIDMapLCU;
    6870       }
    6871       pRefID = pRefMapLCU + zRefSU;
    6872       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6873     }
    6874 
    6875     //       SGU_TR
    6876     pbAvail = &(pbAvailBorder[SGU_TR]);
    6877     if(bPicTBoundary || bPicRBoundary)
    6878     {
    6879       *pbAvail = false;
    6880     }
    6881     else if (onlyOneSliceInPic)
    6882     {
    6883       *pbAvail = true;
    6884     }
    6885     else
    6886     {
    6887       if(bLCUTBoundary && bLCURBoundary)
    6888       {
    6889         zRefSU      = g_auiRasterToZscan[numSUInLCU - numSUInLCUWidth];
    6890         pRefMapLCU  = pSliceIDMapLCU - ( (numLCUInPicWidth-1)*numSUInLCU);       
    6891       }
    6892       else if(bLCUTBoundary)
    6893       {
    6894         zRefSU       = g_auiRasterToZscan[ rTRefSU+ widthSU];
    6895         pRefMapLCU  = pTRefMapLCU;
    6896       }
    6897       else if(bLCURBoundary)
    6898       {
    6899         zRefSU       = g_auiRasterToZscan[ rRRefSU- numSUInLCUWidth ];
    6900         pRefMapLCU  = pRRefMapLCU;
    6901       }
    6902       else //inside LCU
    6903       {
    6904         zRefSU       = g_auiRasterToZscan[ rTLSU - numSUInLCUWidth +widthSU];
    6905         pRefMapLCU  = pSliceIDMapLCU;
    6906       }
    6907       pRefID = pRefMapLCU + zRefSU;
    6908       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6909     }
    6910 
    6911     //       SGU_BL
    6912     pbAvail = &(pbAvailBorder[SGU_BL]);
    6913     if(bPicBBoundary || bPicLBoundary)
    6914     {
    6915       *pbAvail = false;
    6916     }
    6917     else if (onlyOneSliceInPic)
    6918     {
    6919       *pbAvail = true;
    6920     }
    6921     else
    6922     {
    6923       if(bLCUBBoundary && bLCULBoundary)
    6924       {
    6925         zRefSU      = g_auiRasterToZscan[numSUInLCUWidth - 1];
    6926         pRefMapLCU  = pSliceIDMapLCU + ( (numLCUInPicWidth-1)*numSUInLCU);       
    6927       }
    6928       else if(bLCUBBoundary)
    6929       {
    6930         zRefSU       = g_auiRasterToZscan[ rBRefSU - 1];
    6931         pRefMapLCU  = pBRefMapLCU;
    6932       }
    6933       else if(bLCULBoundary)
    6934       {
    6935         zRefSU       = g_auiRasterToZscan[ rLRefSU+ heightSU*numSUInLCUWidth ];
    6936         pRefMapLCU  = pLRefMapLCU;
    6937       }
    6938       else //inside LCU
    6939       {
    6940         zRefSU       = g_auiRasterToZscan[ rTLSU + heightSU*numSUInLCUWidth -1];
    6941         pRefMapLCU  = pSliceIDMapLCU;
    6942       }
    6943       pRefID = pRefMapLCU + zRefSU;
    6944       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6945     }
    6946 
    6947     //       SGU_BR
    6948     pbAvail = &(pbAvailBorder[SGU_BR]);
    6949     if(bPicBBoundary || bPicRBoundary)
    6950     {
    6951       *pbAvail = false;
    6952     }
    6953     else if (onlyOneSliceInPic)
    6954     {
    6955       *pbAvail = true;
    6956     }
    6957     else
    6958     {
    6959       if(bLCUBBoundary && bLCURBoundary)
    6960       {
    6961         zRefSU = 0;
    6962         pRefMapLCU = pSliceIDMapLCU+ ( (numLCUInPicWidth+1)*numSUInLCU);
    6963       }
    6964       else if(bLCUBBoundary)
    6965       {
    6966         zRefSU      = g_auiRasterToZscan[ rBRefSU + widthSU];
    6967         pRefMapLCU = pBRefMapLCU;
    6968       }
    6969       else if(bLCURBoundary)
    6970       {
    6971         zRefSU      = g_auiRasterToZscan[ rRRefSU + (heightSU*numSUInLCUWidth)];
    6972         pRefMapLCU = pRRefMapLCU;
    6973       }
    6974       else //inside LCU
    6975       {
    6976         zRefSU      = g_auiRasterToZscan[ rTLSU + (heightSU*numSUInLCUWidth)+ widthSU];
    6977         pRefMapLCU = pSliceIDMapLCU;
    6978       }
    6979       pRefID = pRefMapLCU + zRefSU;
    6980       *pbAvail = (*pRefID == sliceID)?(true):((*pRefID > sliceID)?(LFCrossSliceBoundary[*pRefID]):(LFCrossSliceBoundary[sliceID]));
    6981     }
    6982 
    6983     if(bIndependentTileBoundaryEnabled)
    6984     {
    6985       //left LCU boundary
    6986       if(!bPicLBoundary && bLCULBoundary)
    6987       {
    6988         if(bLeftTileBoundary)
    6989         {
    6990           pbAvailBorder[SGU_L] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_BL] = false;
    6991         }
    6992       }
    6993       //right LCU boundary
    6994       if(!bPicRBoundary && bLCURBoundary)
    6995       {
    6996         if(bRightTileBoundary)
    6997         {
    6998           pbAvailBorder[SGU_R] = pbAvailBorder[SGU_TR] = pbAvailBorder[SGU_BR] = false;
    6999         }
    7000       }
    7001       //top LCU boundary
    7002       if(!bPicTBoundary && bLCUTBoundary)
    7003       {
    7004         if(bTopTileBoundary)
    7005         {
    7006           pbAvailBorder[SGU_T] = pbAvailBorder[SGU_TL] = pbAvailBorder[SGU_TR] = false;
    7007         }
    7008       }
    7009       //down LCU boundary
    7010       if(!bPicBBoundary && bLCUBBoundary)
    7011       {
    7012         if(bDownTileBoundary)
    7013         {
    7014           pbAvailBorder[SGU_B] = pbAvailBorder[SGU_BL] = pbAvailBorder[SGU_BR] = false;
    7015         }
    7016       }
    7017     }
    7018     rSGU.allBordersAvailable = true;
    7019     for(Int b=0; b< NUM_SGU_BORDER; b++)
    7020     {
    7021       if(pbAvailBorder[b] == false)
    7022       {
    7023         rSGU.allBordersAvailable = false;
    7024         break;
    7025       }
    7026     }
    7027   }
    70286637}
    70296638
  • trunk/source/Lib/TLibCommon/TComDataCU.h

    r833 r872  
    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 *
     
    5959//! \{
    6060
    61 // ====================================================================================================================
    62 // Non-deblocking in-loop filter processing block data structure
    63 // ====================================================================================================================
    64 
    65 /// Non-deblocking filter processing block border tag
    66 enum NDBFBlockBorderTag
    67 {
    68   SGU_L = 0,
    69   SGU_R,
    70   SGU_T,
    71   SGU_B,
    72   SGU_TL,
    73   SGU_TR,
    74   SGU_BL,
    75   SGU_BR,
    76   NUM_SGU_BORDER
    77 };
    78 
    79 /// Non-deblocking filter processing block information
    80 struct NDBFBlockInfo
    81 {
    82   Int   tileID;   //!< tile ID
    83   Int   sliceID;  //!< slice ID
    84   UInt  startSU;  //!< starting SU z-scan address in LCU
    85   UInt  endSU;    //!< ending SU z-scan address in LCU
    86   UInt  widthSU;  //!< number of SUs in width
    87   UInt  heightSU; //!< number of SUs in height
    88   UInt  posX;     //!< top-left X coordinate in picture
    89   UInt  posY;     //!< top-left Y coordinate in picture
    90   UInt  width;    //!< number of pixels in width
    91   UInt  height;   //!< number of pixels in height
    92   Bool  isBorderAvailable[NUM_SGU_BORDER];  //!< the border availabilities
    93   Bool  allBordersAvailable;
    94 
    95   NDBFBlockInfo():tileID(0), sliceID(0), startSU(0), endSU(0) {} //!< constructor
    96   const NDBFBlockInfo& operator= (const NDBFBlockInfo& src);  //!< "=" operator
    97 };
    9861
    9962#if H_3D_DBBP
     
    176139  Pel*          m_pcIPCMSampleCr;     ///< PCM sample buffer (Cr)
    177140
    178   Int*          m_piSliceSUMap;       ///< pointer of slice ID map
    179   std::vector<NDBFBlockInfo> m_vNDFBlock;
    180 
    181141  // -------------------------------------------------------------------------------------------------------------------
    182142  // neighbour access variables
     
    342302 
    343303  Void          initCU                ( TComPic* pcPic, UInt uiCUAddr );
    344   Void          initEstData           ( UInt uiDepth, Int qp );
     304  Void          initEstData           ( UInt uiDepth, Int qp, Bool bTransquantBypass );
    345305  Void          initSubCU             ( TComDataCU* pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp );
    346306  Void          setOutsideCUPart      ( UInt uiAbsPartIdx, UInt uiDepth );
     
    522482  DisInfo       getDvInfo             (UInt uiIdx)              { return m_pDvInfo[uiIdx];          }
    523483#endif
    524   /// get slice ID for SU
    525   Int           getSUSliceID          (UInt uiIdx)              {return m_piSliceSUMap[uiIdx];      }
    526 
    527   /// get the pointer of slice ID map
    528   Int*          getSliceSUMap         ()                        {return m_piSliceSUMap;             }
    529 
    530   /// set the pointer of slice ID map
    531   Void          setSliceSUMap         (Int *pi)                 {m_piSliceSUMap = pi;               }
    532 
    533   std::vector<NDBFBlockInfo>* getNDBFilterBlocks()      {return &m_vNDFBlock;}
    534   Void setNDBFilterBlockBorderAvailability(UInt numLCUInPicWidth, UInt numLCUInPicHeight, UInt numSUInLCUWidth, UInt numSUInLCUHeight, UInt picWidth, UInt picHeight
    535                                           ,std::vector<Bool>& LFCrossSliceBoundary
    536                                           ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary
    537                                           ,Bool bIndependentTileBoundaryEnabled );
    538484#if H_3D_NBDV
    539485  Void          xDeriveRightBottomNbIdx(Int &uiLCUIdxRBNb, Int &uiPartIdxRBNb );
  • trunk/source/Lib/TLibCommon/TComInterpolationFilter.cpp

    r608 r872  
    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/TLibCommon/TComInterpolationFilter.h

    r608 r872  
    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/TLibCommon/TComList.h

    r608 r872  
    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/TLibCommon/TComLoopFilter.cpp

    r608 r872  
    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/TLibCommon/TComLoopFilter.h

    r608 r872  
    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/TLibCommon/TComMotionInfo.cpp

    r773 r872  
    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/TLibCommon/TComMotionInfo.h

    r833 r872  
    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/TLibCommon/TComMv.h

    r655 r872  
    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/TLibCommon/TComPattern.cpp

    r608 r872  
    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/TLibCommon/TComPattern.h

    r655 r872  
    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/TLibCommon/TComPic.cpp

    r738 r872  
    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 *
     
    5656, m_bNeededForOutput                      (false)
    5757, m_uiCurrSliceIdx                        (0)
    58 , m_pSliceSUMap                           (NULL)
    59 , m_pbValidSlice                          (NULL)
    60 , m_sliceGranularityForNDBFilter          (0)
    61 , m_bIndependentSliceBoundaryForNDBFilter (false)
    62 , m_bIndependentTileBoundaryForNDBFilter  (false)
    63 , m_pNDBFilterYuvTmp                      (NULL)
    6458, m_bCheckLTMSB                           (false)
    6559#if H_MV
     
    117111  memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
    118112
    119   /* initialize the texture to depth reference status */
    120113#if H_3D_FCO
     114/* initialize the texture to depth reference status */
    121115  for (int j=0; j<2; j++)
    122116  {
     
    174168}
    175169
    176 /** Create non-deblocked filter information
    177  * \param pSliceStartAddress array for storing slice start addresses
    178  * \param numSlices number of slices in picture
    179  * \param sliceGranularityDepth slice granularity
    180  * \param bNDBFilterCrossSliceBoundary cross-slice-boundary in-loop filtering; true for "cross".
    181  * \param numTiles number of tiles in picture
    182  * \param bNDBFilterCrossTileBoundary cross-tile-boundary in-loop filtering; true for "cross".
    183  */
    184 Void TComPic::createNonDBFilterInfo(std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
    185                                     ,std::vector<Bool>* LFCrossSliceBoundary
    186                                     ,Int numTiles
    187                                     ,Bool bNDBFilterCrossTileBoundary)
    188 {
    189   UInt maxNumSUInLCU = getNumPartInCU();
    190   UInt numLCUInPic   = getNumCUsInFrame();
    191   UInt picWidth      = getSlice(0)->getSPS()->getPicWidthInLumaSamples();
    192   UInt picHeight     = getSlice(0)->getSPS()->getPicHeightInLumaSamples();
    193   Int  numLCUsInPicWidth = getFrameWidthInCU();
    194   Int  numLCUsInPicHeight= getFrameHeightInCU();
    195   UInt maxNumSUInLCUWidth = getNumPartInWidth();
    196   UInt maxNumSUInLCUHeight= getNumPartInHeight();
    197   Int  numSlices = (Int) sliceStartAddress.size() - 1;
    198   m_bIndependentSliceBoundaryForNDBFilter = false;
    199   if(numSlices > 1)
    200   {
    201     for(Int s=0; s< numSlices; s++)
    202     {
    203       if((*LFCrossSliceBoundary)[s] == false)
    204       {
    205         m_bIndependentSliceBoundaryForNDBFilter = true;
    206       }
    207     }
    208   }
    209   m_sliceGranularityForNDBFilter = sliceGranularityDepth;
    210   m_bIndependentTileBoundaryForNDBFilter  = (bNDBFilterCrossTileBoundary)?(false) :((numTiles > 1)?(true):(false));
    211 
    212   m_pbValidSlice = new Bool[numSlices];
    213   for(Int s=0; s< numSlices; s++)
    214   {
    215     m_pbValidSlice[s] = true;
    216   }
    217   m_pSliceSUMap = new Int[maxNumSUInLCU * numLCUInPic];
    218 
    219   //initialization
    220   for(UInt i=0; i< (maxNumSUInLCU * numLCUInPic); i++ )
    221   {
    222     m_pSliceSUMap[i] = -1;
    223   }
    224   for( UInt CUAddr = 0; CUAddr < numLCUInPic ; CUAddr++ )
    225   {
    226     TComDataCU* pcCU = getCU( CUAddr );
    227     pcCU->setSliceSUMap(m_pSliceSUMap + (CUAddr* maxNumSUInLCU));
    228     pcCU->getNDBFilterBlocks()->clear();
    229   }
    230   m_vSliceCUDataLink.clear();
    231 
    232   m_vSliceCUDataLink.resize(numSlices);
    233 
    234   UInt startAddr, endAddr, firstCUInStartLCU, startLCU, endLCU, lastCUInEndLCU, uiAddr;
    235   UInt LPelX, TPelY, LCUX, LCUY;
    236   UInt currSU;
    237   UInt startSU, endSU;
    238 
    239   for(Int s=0; s< numSlices; s++)
    240   {
    241     //1st step: decide the real start address
    242     startAddr = sliceStartAddress[s];
    243     endAddr   = sliceStartAddress[s+1] -1;
    244 
    245     startLCU            = startAddr / maxNumSUInLCU;
    246     firstCUInStartLCU   = startAddr % maxNumSUInLCU;
    247 
    248     endLCU              = endAddr   / maxNumSUInLCU;
    249     lastCUInEndLCU      = endAddr   % maxNumSUInLCU;   
    250 
    251     uiAddr = m_apcPicSym->getCUOrderMap(startLCU);
    252 
    253     LCUX      = getCU(uiAddr)->getCUPelX();
    254     LCUY      = getCU(uiAddr)->getCUPelY();
    255     LPelX     = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[firstCUInStartLCU] ];
    256     TPelY     = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[firstCUInStartLCU] ];
    257     currSU    = firstCUInStartLCU;
    258 
    259     Bool bMoveToNextLCU = false;
    260     Bool bSliceInOneLCU = (startLCU == endLCU);
    261 
    262     while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
    263     {
    264       currSU ++;
    265 
    266       if(bSliceInOneLCU)
    267       {
    268         if(currSU > lastCUInEndLCU)
    269         {
    270           m_pbValidSlice[s] = false;
    271           break;
    272         }
    273       }
    274 
    275       if(currSU >= maxNumSUInLCU )
    276       {
    277         bMoveToNextLCU = true;
    278         break;
    279       }
    280 
    281       LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
    282       TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
    283 
    284     }
    285 
    286 
    287     if(!m_pbValidSlice[s])
    288     {
    289       continue;
    290     }
    291 
    292     if(currSU != firstCUInStartLCU)
    293     {
    294       if(!bMoveToNextLCU)
    295       {
    296         firstCUInStartLCU = currSU;
    297       }
    298       else
    299       {
    300         startLCU++;
    301         firstCUInStartLCU = 0;
    302         assert( startLCU < getNumCUsInFrame());
    303       }
    304       assert(startLCU*maxNumSUInLCU + firstCUInStartLCU < endAddr);
    305     }
    306 
    307 
    308     //2nd step: assign NonDBFilterInfo to each processing block
    309     for(UInt i= startLCU; i <= endLCU; i++)
    310     {
    311       startSU = (i == startLCU)?(firstCUInStartLCU):(0);
    312       endSU   = (i == endLCU  )?(lastCUInEndLCU   ):(maxNumSUInLCU -1);
    313 
    314       uiAddr = m_apcPicSym->getCUOrderMap(i);
    315       Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
    316 
    317       TComDataCU* pcCU = getCU(uiAddr);
    318       m_vSliceCUDataLink[s].push_back(pcCU);
    319 
    320       createNonDBFilterInfoLCU(iTileID, s, pcCU, startSU, endSU, m_sliceGranularityForNDBFilter, picWidth, picHeight);
    321     }
    322   }
    323 
    324   //step 3: border availability
    325   for(Int s=0; s< numSlices; s++)
    326   {
    327     if(!m_pbValidSlice[s])
    328     {
    329       continue;
    330     }
    331 
    332     for(Int i=0; i< m_vSliceCUDataLink[s].size(); i++)
    333     {
    334       TComDataCU* pcCU = m_vSliceCUDataLink[s][i];
    335       uiAddr = pcCU->getAddr();
    336 
    337       if(pcCU->getPic()==0)
    338       {
    339         continue;
    340       }
    341       Int iTileID= m_apcPicSym->getTileIdxMap(uiAddr);
    342       Bool bTopTileBoundary = false, bDownTileBoundary= false, bLeftTileBoundary= false, bRightTileBoundary= false;
    343 
    344       if(m_bIndependentTileBoundaryForNDBFilter)
    345       {
    346         //left
    347         if( uiAddr % numLCUsInPicWidth != 0)
    348         {
    349           bLeftTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr -1) != iTileID )?true:false;
    350         }
    351         //right
    352         if( (uiAddr % numLCUsInPicWidth) != (numLCUsInPicWidth -1) )
    353         {
    354           bRightTileBoundary = ( m_apcPicSym->getTileIdxMap(uiAddr +1) != iTileID)?true:false;
    355         }
    356         //top
    357         if( uiAddr >= numLCUsInPicWidth)
    358         {
    359           bTopTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr - numLCUsInPicWidth) !=  iTileID )?true:false;
    360         }
    361         //down
    362         if( uiAddr + numLCUsInPicWidth < numLCUInPic )
    363         {
    364           bDownTileBoundary = (m_apcPicSym->getTileIdxMap(uiAddr + numLCUsInPicWidth) != iTileID)?true:false;
    365         }
    366 
    367       }
    368 
    369       pcCU->setNDBFilterBlockBorderAvailability(numLCUsInPicWidth, numLCUsInPicHeight, maxNumSUInLCUWidth, maxNumSUInLCUHeight,picWidth, picHeight
    370         , *LFCrossSliceBoundary
    371         ,bTopTileBoundary, bDownTileBoundary, bLeftTileBoundary, bRightTileBoundary
    372         ,m_bIndependentTileBoundaryForNDBFilter);
    373 
    374     }
    375 
    376   }
    377 
    378   if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
    379   {
    380     m_pNDBFilterYuvTmp = new TComPicYuv();
    381     m_pNDBFilterYuvTmp->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    382   }
    383 
    384 }
    385 
    386 /** Create non-deblocked filter information for LCU
    387  * \param tileID tile index
    388  * \param sliceID slice index
    389  * \param pcCU CU data pointer
    390  * \param startSU start SU index in LCU
    391  * \param endSU end SU index in LCU
    392  * \param sliceGranularyDepth slice granularity
    393  * \param picWidth picture width
    394  * \param picHeight picture height
    395  */
    396 Void TComPic::createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight)
    397 {
    398   UInt LCUX          = pcCU->getCUPelX();
    399   UInt LCUY          = pcCU->getCUPelY();
    400   Int* pCUSliceMap    = pcCU->getSliceSUMap();
    401   UInt maxNumSUInLCU = getNumPartInCU();
    402   UInt maxNumSUInSGU = maxNumSUInLCU >> (sliceGranularyDepth << 1);
    403   UInt maxNumSUInLCUWidth = getNumPartInWidth();
    404   UInt LPelX, TPelY;
    405   UInt currSU;
    406 
    407 
    408   //get the number of valid NBFilterBLock
    409   currSU   = startSU;
    410   while(currSU <= endSU)
    411   {
    412     LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
    413     TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
    414 
    415     while(!( LPelX < picWidth ) || !( TPelY < picHeight ))
    416     {
    417       currSU += maxNumSUInSGU;
    418       if(currSU >= maxNumSUInLCU || currSU > endSU)
    419       {
    420         break;
    421       }
    422       LPelX = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[currSU] ];
    423       TPelY = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[currSU] ];
    424     }
    425 
    426     if(currSU >= maxNumSUInLCU || currSU > endSU)
    427     {
    428       break;
    429     }
    430 
    431     NDBFBlockInfo NDBFBlock;
    432 
    433     NDBFBlock.tileID  = tileID;
    434     NDBFBlock.sliceID = sliceID;
    435     NDBFBlock.posY    = TPelY;
    436     NDBFBlock.posX    = LPelX;
    437     NDBFBlock.startSU = currSU;
    438 
    439     UInt uiLastValidSU  = currSU;
    440     UInt uiIdx, uiLPelX_su, uiTPelY_su;
    441     for(uiIdx = currSU; uiIdx < currSU + maxNumSUInSGU; uiIdx++)
    442     {
    443       if(uiIdx > endSU)
    444       {
    445         break;       
    446       }
    447       uiLPelX_su   = LCUX + g_auiRasterToPelX[ g_auiZscanToRaster[uiIdx] ];
    448       uiTPelY_su   = LCUY + g_auiRasterToPelY[ g_auiZscanToRaster[uiIdx] ];
    449       if( !(uiLPelX_su < picWidth ) || !( uiTPelY_su < picHeight ))
    450       {
    451         continue;
    452       }
    453       pCUSliceMap[uiIdx] = sliceID;
    454       uiLastValidSU = uiIdx;
    455     }
    456     NDBFBlock.endSU = uiLastValidSU;
    457 
    458     UInt rTLSU = g_auiZscanToRaster[ NDBFBlock.startSU ];
    459     UInt rBRSU = g_auiZscanToRaster[ NDBFBlock.endSU   ];
    460     NDBFBlock.widthSU  = (rBRSU % maxNumSUInLCUWidth) - (rTLSU % maxNumSUInLCUWidth)+ 1;
    461     NDBFBlock.heightSU = (UInt)(rBRSU / maxNumSUInLCUWidth) - (UInt)(rTLSU / maxNumSUInLCUWidth)+ 1;
    462     NDBFBlock.width    = NDBFBlock.widthSU  * getMinCUWidth();
    463     NDBFBlock.height   = NDBFBlock.heightSU * getMinCUHeight();
    464 
    465     pcCU->getNDBFilterBlocks()->push_back(NDBFBlock);
    466 
    467     currSU += maxNumSUInSGU;
    468   }
    469 
    470 }
    471 
    472 /** destroy non-deblocked filter information for LCU
    473  */
    474 Void TComPic::destroyNonDBFilterInfo()
    475 {
    476   if(m_pbValidSlice != NULL)
    477   {
    478     delete[] m_pbValidSlice;
    479     m_pbValidSlice = NULL;
    480   }
    481 
    482   if(m_pSliceSUMap != NULL)
    483   {
    484     delete[] m_pSliceSUMap;
    485     m_pSliceSUMap = NULL;
    486   }
    487   for( UInt CUAddr = 0; CUAddr < getNumCUsInFrame() ; CUAddr++ )
    488   {
    489     TComDataCU* pcCU = getCU( CUAddr );
    490     pcCU->getNDBFilterBlocks()->clear();
    491   }
    492 
    493   if( m_bIndependentSliceBoundaryForNDBFilter || m_bIndependentTileBoundaryForNDBFilter)
    494   {
    495     m_pNDBFilterYuvTmp->destroy();
    496     delete m_pNDBFilterYuvTmp;
    497     m_pNDBFilterYuvTmp = NULL;
    498   }
    499 
    500 }
     170Bool  TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr)
     171{
     172  Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU()));
     173  Bool mergeCtbInTile     = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr));
     174  return (mergeCtbInSliceSeg && mergeCtbInTile);
     175}
     176
    501177#if H_MV
    502178Void TComPic::print( Bool legend )
  • trunk/source/Lib/TLibCommon/TComPic.h

    r655 r872  
    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 *
     
    7070  Bool                  m_bNeededForOutput;
    7171  UInt                  m_uiCurrSliceIdx;         // Index of current slice
    72   Int*                  m_pSliceSUMap;
    73   Bool*                 m_pbValidSlice;
    74   Int                   m_sliceGranularityForNDBFilter;
    75   Bool                  m_bIndependentSliceBoundaryForNDBFilter;
    76   Bool                  m_bIndependentTileBoundaryForNDBFilter;
    77   TComPicYuv*           m_pNDBFilterYuvTmp;    //!< temporary picture buffer when non-cross slice/tile boundary in-loop filtering is enabled
    7872  Bool                  m_bCheckLTMSB;
    7973 
     
    198192  Window&       getDefDisplayWindow()   { return m_defaultDisplayWindow; }
    199193
    200   Void          createNonDBFilterInfo   (std::vector<Int> sliceStartAddress, Int sliceGranularityDepth
    201                                         ,std::vector<Bool>* LFCrossSliceBoundary
    202                                         ,Int  numTiles = 1
    203                                         ,Bool bNDBFilterCrossTileBoundary = true);
    204   Void          createNonDBFilterInfoLCU(Int tileID, Int sliceID, TComDataCU* pcCU, UInt startSU, UInt endSU, Int sliceGranularyDepth, UInt picWidth, UInt picHeight);
    205   Void          destroyNonDBFilterInfo();
    206 
    207   Bool          getValidSlice                                  (Int sliceID)  {return m_pbValidSlice[sliceID];}
    208   Bool          getIndependentSliceBoundaryForNDBFilter        ()             {return m_bIndependentSliceBoundaryForNDBFilter;}
    209   Bool          getIndependentTileBoundaryForNDBFilter         ()             {return m_bIndependentTileBoundaryForNDBFilter; }
    210   TComPicYuv*   getYuvPicBufferForIndependentBoundaryProcessing()             {return m_pNDBFilterYuvTmp;}
    211   std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
    212 
     194  Bool          getSAOMergeAvailability(Int currAddr, Int mergeAddr);
    213195
    214196  /* field coding parameters*/
  • trunk/source/Lib/TLibCommon/TComPicSym.cpp

    r655 r872  
    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 *
     
    6767,m_puiTileIdxMap(NULL)
    6868,m_puiInverseCUOrderMap(NULL)
     69,m_saoBlkParams(NULL)
    6970{};
    7071
     
    122123    m_puiInverseCUOrderMap[i] = i;
    123124  }
    124   m_saoParam = NULL;
     125
     126  m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame];
    125127}
    126128
     
    163165  m_puiInverseCUOrderMap = NULL;
    164166 
    165   if (m_saoParam)
    166   {
    167     TComSampleAdaptiveOffset::freeSaoParam(m_saoParam);
    168     delete m_saoParam;
    169     m_saoParam = NULL;
     167  if(m_saoBlkParams)
     168  {
     169    delete[] m_saoBlkParams; m_saoBlkParams = NULL;
    170170  }
    171171}
     
    308308}
    309309
    310 Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao)
    311 {
    312   m_saoParam = new SAOParam;
    313   sao->allocSaoParam(m_saoParam);
     310Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu,
     311                                                      Bool& isLeftAvail,
     312                                                      Bool& isRightAvail,
     313                                                      Bool& isAboveAvail,
     314                                                      Bool& isBelowAvail,
     315                                                      Bool& isAboveLeftAvail,
     316                                                      Bool& isAboveRightAvail,
     317                                                      Bool& isBelowLeftAvail,
     318                                                      Bool& isBelowRightAvail
     319                                                      )
     320{
     321
     322  isLeftAvail      = (ctu % m_uiWidthInCU != 0);
     323  isRightAvail     = (ctu % m_uiWidthInCU != m_uiWidthInCU-1);
     324  isAboveAvail     = (ctu >= m_uiWidthInCU );
     325  isBelowAvail     = (ctu <  m_uiNumCUsInFrame - m_uiWidthInCU);
     326  isAboveLeftAvail = (isAboveAvail && isLeftAvail);
     327  isAboveRightAvail= (isAboveAvail && isRightAvail);
     328  isBelowLeftAvail = (isBelowAvail && isLeftAvail);
     329  isBelowRightAvail= (isBelowAvail && isRightAvail);
     330
     331  Bool isLoopFiltAcrossTilePPS = getCU(ctu)->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     332
     333  {
     334    TComDataCU* ctuCurr  = getCU(ctu);
     335    TComDataCU* ctuLeft  = isLeftAvail ?getCU(ctu-1):NULL;
     336    TComDataCU* ctuRight = isRightAvail?getCU(ctu+1):NULL;
     337    TComDataCU* ctuAbove = isAboveAvail?getCU(ctu-m_uiWidthInCU):NULL;
     338    TComDataCU* ctuBelow = isBelowAvail?getCU(ctu+m_uiWidthInCU):NULL;
     339    TComDataCU* ctuAboveLeft  = isAboveLeftAvail ? getCU(ctu-m_uiWidthInCU-1):NULL;
     340    TComDataCU* ctuAboveRigtht= isAboveRightAvail? getCU(ctu-m_uiWidthInCU+1):NULL;
     341    TComDataCU* ctuBelowLeft  = isBelowLeftAvail ? getCU(ctu+m_uiWidthInCU-1):NULL;
     342    TComDataCU* ctuBelowRight = isBelowRightAvail? getCU(ctu+m_uiWidthInCU+1):NULL;
     343
     344    {
     345      //left
     346      if(ctuLeft != NULL)
     347      {
     348        isLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     349      }
     350      //above
     351      if(ctuAbove != NULL)
     352      {
     353        isAboveAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAbove->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     354      }
     355      //right
     356      if(ctuRight != NULL)
     357      {
     358        isRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuRight->getSlice()->getSliceCurStartCUAddr())?ctuRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
     359      }
     360      //below
     361      if(ctuBelow != NULL)
     362      {
     363        isBelowAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelow->getSlice()->getSliceCurStartCUAddr())?ctuBelow->getSlice()->getLFCrossSliceBoundaryFlag():true;
     364      }
     365      //above-left
     366      if(ctuAboveLeft != NULL)
     367      {
     368        isAboveLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAboveLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true;
     369      }
     370      //below-right
     371      if(ctuBelowRight != NULL)
     372{
     373        isBelowRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelowRight->getSlice()->getSliceCurStartCUAddr())?ctuBelowRight->getSlice()->getLFCrossSliceBoundaryFlag():true;
     374      }
     375
     376
     377      //above-right
     378      if(ctuAboveRigtht != NULL)
     379      {
     380        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
     381        Int aboveRigthtSliceStartEncOrder = ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr();
     382
     383        isAboveRightAvail = (curSliceStartEncOrder == aboveRigthtSliceStartEncOrder)?(true):
     384          (
     385          (curSliceStartEncOrder > aboveRigthtSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
     386          :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag())
     387          );         
     388      }
     389      //below-left
     390      if(ctuBelowLeft != NULL)
     391      {
     392        Int curSliceStartEncOrder  = ctuCurr->getSlice()->getSliceCurStartCUAddr();
     393        Int belowLeftSliceStartEncOrder = ctuBelowLeft->getSlice()->getSliceCurStartCUAddr();
     394
     395        isBelowLeftAvail = (curSliceStartEncOrder == belowLeftSliceStartEncOrder)?(true):
     396          (
     397          (curSliceStartEncOrder > belowLeftSliceStartEncOrder)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag())
     398          :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag())
     399          );
     400      }       
     401    }
     402
     403    if(!isLoopFiltAcrossTilePPS)
     404    {     
     405      isLeftAvail      = (!isLeftAvail      ) ?false:(getTileIdxMap( ctuLeft->getAddr()         ) == getTileIdxMap( ctu ));
     406      isAboveAvail     = (!isAboveAvail     ) ?false:(getTileIdxMap( ctuAbove->getAddr()        ) == getTileIdxMap( ctu ));
     407      isRightAvail     = (!isRightAvail     ) ?false:(getTileIdxMap( ctuRight->getAddr()        ) == getTileIdxMap( ctu ));
     408      isBelowAvail     = (!isBelowAvail     ) ?false:(getTileIdxMap( ctuBelow->getAddr()        ) == getTileIdxMap( ctu ));
     409      isAboveLeftAvail = (!isAboveLeftAvail ) ?false:(getTileIdxMap( ctuAboveLeft->getAddr()    ) == getTileIdxMap( ctu ));
     410      isAboveRightAvail= (!isAboveRightAvail) ?false:(getTileIdxMap( ctuAboveRigtht->getAddr()  ) == getTileIdxMap( ctu ));
     411      isBelowLeftAvail = (!isBelowLeftAvail ) ?false:(getTileIdxMap( ctuBelowLeft->getAddr()    ) == getTileIdxMap( ctu ));
     412      isBelowRightAvail= (!isBelowRightAvail) ?false:(getTileIdxMap( ctuBelowRight->getAddr()   ) == getTileIdxMap( ctu ));
     413    }
     414  }
     415
    314416}
    315417
  • trunk/source/Lib/TLibCommon/TComPicSym.h

    r655 r872  
    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 *
     
    107107  UInt*         m_puiInverseCUOrderMap;
    108108
    109   SAOParam *m_saoParam;
     109  SAOBlkParam *m_saoBlkParams;
    110110public:
    111111  Void        create  ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth );
     
    144144  Void         xInitTiles();
    145145  UInt         xCalculateNxtCUAddr( UInt uiCurrCUAddr );
    146   Void allocSaoParam(TComSampleAdaptiveOffset *sao);
    147   SAOParam *getSaoParam() { return m_saoParam; }
     146  SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;}
     147  Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail);
     148
     149
    148150};// END CLASS DEFINITION TComPicSym
    149151
  • trunk/source/Lib/TLibCommon/TComPicYuv.cpp

    r608 r872  
    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/TLibCommon/TComPicYuv.h

    r608 r872  
    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/TLibCommon/TComPicYuvMD5.cpp

    r608 r872  
    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/TLibCommon/TComPrediction.cpp

    r833 r872  
    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/TLibCommon/TComPrediction.h

    r833 r872  
    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/TLibCommon/TComRdCost.cpp

    r833 r872  
    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 *
     
    5151Double TComRdCost::m_dDisparityCoeff = 1.0;
    5252#endif
    53 
    5453TComRdCost::TComRdCost()
    5554{
     
    354353  }
    355354#endif
    356  
    357355  // initialize
    358356  rcDistParam.iSubShift  = 0;
     
    395393  }
    396394#endif
    397 
    398395  // initialize
    399396  rcDistParam.iSubShift  = 0;
     
    401398
    402399// Setting the Distortion Parameter for Inter (subpel ME with step)
    403 #if NS_HAD
    404 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME, Bool bUseNSHAD )
    405 #else
    406400Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME )
    407 #endif
    408401{
    409402  // set Original & Curr Pointer / Stride
     
    420413  rcDistParam.iCols    = pcPatternKey->getROIYWidth();
    421414  rcDistParam.iRows    = pcPatternKey->getROIYHeight();
    422 #if NS_HAD
    423   rcDistParam.bUseNSHAD = bUseNSHAD;
    424 #endif
    425415 
    426416  // set distortion function
     
    454444  }
    455445#endif
    456  
    457446  // initialize
    458447  rcDistParam.iSubShift  = 0;
     
    460449
    461450Void
    462 #if NS_HAD
    463 TComRdCost::setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard, Bool bUseNSHAD )
    464 #else
    465451TComRdCost::setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard )
    466 #endif
    467452{
    468453  rcDP.pOrg       = p1;
     
    476461  rcDP.bitDepth   = bitDepth;
    477462  rcDP.DistFunc   = m_afpDistortFunc[ ( bHadamard ? DF_HADS : DF_SADS ) + g_aucConvertToBit[ iWidth ] + 1 ];
    478  
    479463#if H_3D_DBBP
    480464  if( m_bUseMask )
     
    482466    rcDP.DistFunc = (bHadamard)?TComRdCost::xGetMaskedHADs:TComRdCost::xGetMaskedSAD;
    483467  }
    484 #endif
    485  
    486 #if NS_HAD
    487   rcDP.bUseNSHAD  = bUseNSHAD;
    488468#endif
    489469}
     
    506486    }
    507487  }
    508   else if ( ( (iWidth % 4) == 0 ) && ( (iHeight % 4) == 0 ) )
    509   {
     488  else
     489  {
     490    assert(iWidth % 4 == 0 && iHeight % 4 == 0);
     491   
    510492    for ( y=0; y<iHeight; y+= 4 )
    511493    {
     
    518500    }
    519501  }
    520   else
    521   {
    522     for ( y=0; y<iHeight; y+= 2 )
    523     {
    524       for ( x=0; x<iWidth; x+= 2 )
    525       {
    526         uiSum += xCalcHADs8x8( &pi0[x], &pi1[x], iStride0, iStride1, 1 );
    527       }
    528       pi0 += iStride0*2;
    529       pi1 += iStride1*2;
    530     }
    531   }
    532502 
    533503  return uiSum >> DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
     
    572542
    573543
    574 #if WEIGHTED_CHROMA_DISTORTION
    575544UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText, DFunc eDFunc)
    576 #else
    577 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc )
    578 #endif
    579545{
    580546  DistParam cDtParam;
     
    596562  cDtParam.bUseSDCMRSAD = false;
    597563#endif
    598 #if WEIGHTED_CHROMA_DISTORTION
    599564  if (eText == TEXT_CHROMA_U)
    600565  {
     
    609574    return cDtParam.DistFunc( &cDtParam );
    610575  }
    611 #else
    612   return cDtParam.DistFunc( &cDtParam );
    613 #endif
    614576}
    615577#if H_3D_VSO
     
    664626#endif
    665627
    666 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
     628#if KWU_RC_MADPRED_E0227
    667629UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height )
    668630{
     
    908870}
    909871#endif
    910 
    911872// --------------------------------------------------------------------------------------------------------------------
    912873// SAD
     
    34673428}
    34683429
    3469 #if NS_HAD
    3470 UInt TComRdCost::xCalcHADs16x4( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )
    3471 {
    3472   Int k, i, j, jj, sad=0;
    3473   Int diff[64], m1[4][16], m2[4][16];
    3474   assert( iStep == 1 );
    3475   for( k = 0; k < 64; k += 16 )
    3476   {
    3477     diff[k+0] = piOrg[0] - piCur[0];
    3478     diff[k+1] = piOrg[1] - piCur[1];
    3479     diff[k+2] = piOrg[2] - piCur[2];
    3480     diff[k+3] = piOrg[3] - piCur[3];
    3481     diff[k+4] = piOrg[4] - piCur[4];
    3482     diff[k+5] = piOrg[5] - piCur[5];
    3483     diff[k+6] = piOrg[6] - piCur[6];
    3484     diff[k+7] = piOrg[7] - piCur[7];
    3485 
    3486     diff[k+8]  = piOrg[8]  - piCur[8] ;
    3487     diff[k+9]  = piOrg[9]  - piCur[9] ;
    3488     diff[k+10] = piOrg[10] - piCur[10];
    3489     diff[k+11] = piOrg[11] - piCur[11];
    3490     diff[k+12] = piOrg[12] - piCur[12];
    3491     diff[k+13] = piOrg[13] - piCur[13];
    3492     diff[k+14] = piOrg[14] - piCur[14];
    3493     diff[k+15] = piOrg[15] - piCur[15];
    3494 
    3495     piCur += iStrideCur;
    3496     piOrg += iStrideOrg;
    3497   }
    3498 
    3499   //horizontal
    3500   for (j=0; j < 4; j++)
    3501   {
    3502     jj = j << 4;
    3503 
    3504     m2[j][0]  = diff[jj  ] + diff[jj+8];
    3505     m2[j][1]  = diff[jj+1] + diff[jj+9];
    3506     m2[j][2]  = diff[jj+2] + diff[jj+10];
    3507     m2[j][3]  = diff[jj+3] + diff[jj+11];
    3508     m2[j][4]  = diff[jj+4] + diff[jj+12];
    3509     m2[j][5]  = diff[jj+5] + diff[jj+13];
    3510     m2[j][6]  = diff[jj+6] + diff[jj+14];
    3511     m2[j][7]  = diff[jj+7] + diff[jj+15];
    3512     m2[j][8]  = diff[jj  ] - diff[jj+8];
    3513     m2[j][9]  = diff[jj+1] - diff[jj+9];
    3514     m2[j][10] = diff[jj+2] - diff[jj+10];
    3515     m2[j][11] = diff[jj+3] - diff[jj+11];
    3516     m2[j][12] = diff[jj+4] - diff[jj+12];
    3517     m2[j][13] = diff[jj+5] - diff[jj+13];
    3518     m2[j][14] = diff[jj+6] - diff[jj+14];
    3519     m2[j][15] = diff[jj+7] - diff[jj+15];
    3520 
    3521     m1[j][0]  = m2[j][0]  + m2[j][4];
    3522     m1[j][1]  = m2[j][1]  + m2[j][5];
    3523     m1[j][2]  = m2[j][2]  + m2[j][6];
    3524     m1[j][3]  = m2[j][3]  + m2[j][7];
    3525     m1[j][4]  = m2[j][0]  - m2[j][4];
    3526     m1[j][5]  = m2[j][1]  - m2[j][5];
    3527     m1[j][6]  = m2[j][2]  - m2[j][6];
    3528     m1[j][7]  = m2[j][3]  - m2[j][7];
    3529     m1[j][8]  = m2[j][8]  + m2[j][12];
    3530     m1[j][9]  = m2[j][9]  + m2[j][13];
    3531     m1[j][10] = m2[j][10] + m2[j][14];
    3532     m1[j][11] = m2[j][11] + m2[j][15];
    3533     m1[j][12] = m2[j][8]  - m2[j][12];
    3534     m1[j][13] = m2[j][9]  - m2[j][13];
    3535     m1[j][14] = m2[j][10] - m2[j][14];
    3536     m1[j][15] = m2[j][11] - m2[j][15];
    3537 
    3538     m2[j][0]  = m1[j][0]  + m1[j][2];
    3539     m2[j][1]  = m1[j][1]  + m1[j][3];
    3540     m2[j][2]  = m1[j][0]  - m1[j][2];
    3541     m2[j][3]  = m1[j][1]  - m1[j][3];
    3542     m2[j][4]  = m1[j][4]  + m1[j][6];
    3543     m2[j][5]  = m1[j][5]  + m1[j][7];
    3544     m2[j][6]  = m1[j][4]  - m1[j][6];
    3545     m2[j][7]  = m1[j][5]  - m1[j][7];
    3546     m2[j][8]  = m1[j][8]  + m1[j][10];
    3547     m2[j][9]  = m1[j][9]  + m1[j][11];
    3548     m2[j][10] = m1[j][8]  - m1[j][10];
    3549     m2[j][11] = m1[j][9]  - m1[j][11];
    3550     m2[j][12] = m1[j][12] + m1[j][14];
    3551     m2[j][13] = m1[j][13] + m1[j][15];
    3552     m2[j][14] = m1[j][12] - m1[j][14];
    3553     m2[j][15] = m1[j][13] - m1[j][15];
    3554 
    3555     m1[j][0]  = m2[j][0]  + m2[j][1];
    3556     m1[j][1]  = m2[j][0]  - m2[j][1];
    3557     m1[j][2]  = m2[j][2]  + m2[j][3];
    3558     m1[j][3]  = m2[j][2]  - m2[j][3];
    3559     m1[j][4]  = m2[j][4]  + m2[j][5];
    3560     m1[j][5]  = m2[j][4]  - m2[j][5];
    3561     m1[j][6]  = m2[j][6]  + m2[j][7];
    3562     m1[j][7]  = m2[j][6]  - m2[j][7];
    3563     m1[j][8]  = m2[j][8]  + m2[j][9];
    3564     m1[j][9]  = m2[j][8]  - m2[j][9];
    3565     m1[j][10] = m2[j][10] + m2[j][11];
    3566     m1[j][11] = m2[j][10] - m2[j][11];
    3567     m1[j][12] = m2[j][12] + m2[j][13];
    3568     m1[j][13] = m2[j][12] - m2[j][13];
    3569     m1[j][14] = m2[j][14] + m2[j][15];
    3570     m1[j][15] = m2[j][14] - m2[j][15];
    3571   }
    3572 
    3573   //vertical
    3574   for (i=0; i < 16; i++)
    3575   {   
    3576     m2[0][i] = m1[0][i] + m1[2][i];
    3577     m2[1][i] = m1[1][i] + m1[3][i];
    3578     m2[2][i] = m1[0][i] - m1[2][i];
    3579     m2[3][i] = m1[1][i] - m1[3][i];
    3580 
    3581     m1[0][i] = m2[0][i] + m2[1][i];
    3582     m1[1][i] = m2[0][i] - m2[1][i];
    3583     m1[2][i] = m2[2][i] + m2[3][i];
    3584     m1[3][i] = m2[2][i] - m2[3][i];
    3585   }
    3586 
    3587   for (i = 0; i < 4; i++)
    3588   {
    3589     for (j = 0; j < 16; j++)
    3590     {
    3591       sad += abs(m1[i][j]);
    3592     }
    3593   }
    3594 
    3595   sad=((sad+2)>>2);
    3596 
    3597   return sad;
    3598 }
    3599 
    3600 UInt TComRdCost::xCalcHADs4x16( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )
    3601 {
    3602   Int k, i, j, jj, sad=0;
    3603   Int diff[64], m1[16][4], m2[16][4], m3[16][4];
    3604   assert( iStep == 1 );
    3605   for( k = 0; k < 64; k += 4 )
    3606   {
    3607     diff[k+0] = piOrg[0] - piCur[0];
    3608     diff[k+1] = piOrg[1] - piCur[1];
    3609     diff[k+2] = piOrg[2] - piCur[2];
    3610     diff[k+3] = piOrg[3] - piCur[3];
    3611 
    3612     piCur += iStrideCur;
    3613     piOrg += iStrideOrg;
    3614   }
    3615 
    3616   //horizontal
    3617   for (j=0; j < 16; j++)
    3618   {
    3619     jj = j << 2;
    3620     m2[j][0] = diff[jj  ] + diff[jj+2];
    3621     m2[j][1] = diff[jj+1] + diff[jj+3];
    3622     m2[j][2] = diff[jj  ] - diff[jj+2];
    3623     m2[j][3] = diff[jj+1] - diff[jj+3];
    3624 
    3625     m1[j][0] = m2[j][0] + m2[j][1];
    3626     m1[j][1] = m2[j][0] - m2[j][1];
    3627     m1[j][2] = m2[j][2] + m2[j][3];
    3628     m1[j][3] = m2[j][2] - m2[j][3];
    3629   }
    3630 
    3631   //vertical
    3632   for (i=0; i < 4; i++)
    3633   {
    3634     m2[0][i]  = m1[0][i] + m1[8][i];
    3635     m2[1][i]  = m1[1][i] + m1[9][i];
    3636     m2[2][i]  = m1[2][i] + m1[10][i];
    3637     m2[3][i]  = m1[3][i] + m1[11][i];
    3638     m2[4][i]  = m1[4][i] + m1[12][i];
    3639     m2[5][i]  = m1[5][i] + m1[13][i];
    3640     m2[6][i]  = m1[6][i] + m1[14][i];
    3641     m2[7][i]  = m1[7][i] + m1[15][i];
    3642     m2[8][i]  = m1[0][i] - m1[8][i];
    3643     m2[9][i]  = m1[1][i] - m1[9][i];
    3644     m2[10][i] = m1[2][i] - m1[10][i];
    3645     m2[11][i] = m1[3][i] - m1[11][i];
    3646     m2[12][i] = m1[4][i] - m1[12][i];
    3647     m2[13][i] = m1[5][i] - m1[13][i];
    3648     m2[14][i] = m1[6][i] - m1[14][i];
    3649     m2[15][i] = m1[7][i] - m1[15][i];
    3650 
    3651     m3[0][i]  = m2[0][i]  + m2[4][i];
    3652     m3[1][i]  = m2[1][i]  + m2[5][i];
    3653     m3[2][i]  = m2[2][i]  + m2[6][i];
    3654     m3[3][i]  = m2[3][i]  + m2[7][i];
    3655     m3[4][i]  = m2[0][i]  - m2[4][i];
    3656     m3[5][i]  = m2[1][i]  - m2[5][i];
    3657     m3[6][i]  = m2[2][i]  - m2[6][i];
    3658     m3[7][i]  = m2[3][i]  - m2[7][i];
    3659     m3[8][i]  = m2[8][i]  + m2[12][i];
    3660     m3[9][i]  = m2[9][i]  + m2[13][i];
    3661     m3[10][i] = m2[10][i] + m2[14][i];
    3662     m3[11][i] = m2[11][i] + m2[15][i];
    3663     m3[12][i] = m2[8][i]  - m2[12][i];
    3664     m3[13][i] = m2[9][i]  - m2[13][i];
    3665     m3[14][i] = m2[10][i] - m2[14][i];
    3666     m3[15][i] = m2[11][i] - m2[15][i];
    3667 
    3668     m1[0][i]  = m3[0][i]  + m3[2][i];
    3669     m1[1][i]  = m3[1][i]  + m3[3][i];
    3670     m1[2][i]  = m3[0][i]  - m3[2][i];
    3671     m1[3][i]  = m3[1][i]  - m3[3][i];
    3672     m1[4][i]  = m3[4][i]  + m3[6][i];
    3673     m1[5][i]  = m3[5][i]  + m3[7][i];
    3674     m1[6][i]  = m3[4][i]  - m3[6][i];
    3675     m1[7][i]  = m3[5][i]  - m3[7][i];
    3676     m1[8][i]  = m3[8][i]  + m3[10][i];
    3677     m1[9][i]  = m3[9][i]  + m3[11][i];
    3678     m1[10][i] = m3[8][i]  - m3[10][i];
    3679     m1[11][i] = m3[9][i]  - m3[11][i];
    3680     m1[12][i] = m3[12][i] + m3[14][i];
    3681     m1[13][i] = m3[13][i] + m3[15][i];
    3682     m1[14][i] = m3[12][i] - m3[14][i];
    3683     m1[15][i] = m3[13][i] - m3[15][i];
    3684 
    3685     m2[0][i]  = m1[0][i]  + m1[1][i];
    3686     m2[1][i]  = m1[0][i]  - m1[1][i];
    3687     m2[2][i]  = m1[2][i]  + m1[3][i];
    3688     m2[3][i]  = m1[2][i]  - m1[3][i];
    3689     m2[4][i]  = m1[4][i]  + m1[5][i];
    3690     m2[5][i]  = m1[4][i]  - m1[5][i];
    3691     m2[6][i]  = m1[6][i]  + m1[7][i];
    3692     m2[7][i]  = m1[6][i]  - m1[7][i];
    3693     m2[8][i]  = m1[8][i]  + m1[9][i];
    3694     m2[9][i]  = m1[8][i]  - m1[9][i];
    3695     m2[10][i] = m1[10][i] + m1[11][i];
    3696     m2[11][i] = m1[10][i] - m1[11][i];
    3697     m2[12][i] = m1[12][i] + m1[13][i];
    3698     m2[13][i] = m1[12][i] - m1[13][i];
    3699     m2[14][i] = m1[14][i] + m1[15][i];
    3700     m2[15][i] = m1[14][i] - m1[15][i];
    3701   }
    3702 
    3703   for (i = 0; i < 16; i++)
    3704   {
    3705     for (j = 0; j < 4; j++)
    3706     {
    3707       sad += abs(m2[i][j]);
    3708     }
    3709   }
    3710 
    3711   sad=((sad+2)>>2);
    3712 
    3713   return sad;
    3714 }
    3715 #endif
    3716 
    37173430UInt TComRdCost::xGetHADs4( DistParam* pcDtParam )
    37183431{
     
    38093522  UInt uiSum = 0;
    38103523 
    3811 #if NS_HAD
    3812   if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )
    3813 #else
    38143524  if( ( iRows % 8 == 0) && (iCols % 8 == 0) )
    3815 #endif
    38163525  {
    38173526    Int  iOffsetOrg = iStrideOrg<<3;
     
    38273536    }
    38283537  }
    3829 #if NS_HAD
    3830   else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )
    3831   {
    3832     Int  iOffsetOrg = iStrideOrg<<2;
    3833     Int  iOffsetCur = iStrideCur<<2;
    3834     for ( y=0; y<iRows; y+= 4 )
    3835     {
    3836       for ( x=0; x<iCols; x+= 16 )
    3837       {
    3838         uiSum += xCalcHADs16x4( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );
    3839       }
    3840       piOrg += iOffsetOrg;
    3841       piCur += iOffsetCur;
    3842     }
    3843   }
    3844   else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )
    3845   {
    3846     Int  iOffsetOrg = iStrideOrg<<4;
    3847     Int  iOffsetCur = iStrideCur<<4;
    3848     for ( y=0; y<iRows; y+= 16 )
    3849     {
    3850       for ( x=0; x<iCols; x+= 4 )
    3851       {
    3852         uiSum += xCalcHADs4x16( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );
    3853       }
    3854       piOrg += iOffsetOrg;
    3855       piCur += iOffsetCur;
    3856     }
    3857   }
    3858 #endif
    38593538  else if( ( iRows % 4 == 0) && (iCols % 4 == 0) )
    38603539  {
  • trunk/source/Lib/TLibCommon/TComRdCost.h

    r833 r872  
    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 *
     
    107107  UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)
    108108
    109 #if NS_HAD
    110   Bool            bUseNSHAD;
    111 #endif
    112 
    113109  // (vertical) subsampling shift (for reducing complexity)
    114110  // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.
     
    127123    iSubShift = 0;
    128124    bitDepth = 0;
    129 #if NS_HAD
    130     bUseNSHAD = false;
    131 #endif
    132125#if H_3D_VSO
    133126    // SAIT_VSO_EST_A0033
     
    155148#endif 
    156149 
    157 #if WEIGHTED_CHROMA_DISTORTION
    158150  Double                  m_cbDistortionWeight;
    159151  Double                  m_crDistortionWeight;
    160 #endif
    161152  Double                  m_dLambda;
    162153  Double                  m_sqrtLambda;
     
    201192
    202193 
    203 #if WEIGHTED_CHROMA_DISTORTION
    204194  Void    setCbDistortionWeight      ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; };
    205195  Void    setCrDistortionWeight      ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; };
    206 #endif
    207196  Void    setLambda      ( Double dLambda );
    208197  Void    setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; }
     
    215204#endif
    216205
    217 #if RATE_CONTROL_LAMBDA_DOMAIN
    218206  Double  getLambda() { return m_dLambda; }
    219 #if M0036_RC_IMPROVEMENT
    220207  Double  getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);}
    221 #endif
    222 #endif
    223208 
    224209  // Distortion Functions
     
    227212  Void    setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam );
    228213  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride,            DistParam& rcDistParam );
    229 #if NS_HAD
    230   Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );
    231   Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );
    232 #else
    233214  Void    setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false );
    234215  Void    setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false );
    235 #endif
    236216 
    237217#if H_3D_DBBP
     
    337317  static UInt xCalcHADs4x4      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    338318  static UInt xCalcHADs8x8      ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    339 #if NS_HAD
    340   static UInt xCalcHADs16x4     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    341   static UInt xCalcHADs4x16     ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );
    342 #endif
    343  
    344319#if H_3D_DBBP
    345320  static UInt xGetMaskedSSE     ( DistParam* pcDtParam );
     
    350325 
    351326public:
    352 #if WEIGHTED_CHROMA_DISTORTION
    353327  UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE );
    354 #else
    355   UInt   getDistPart(Int bitDepth, Pel* piCur, Int iCurStride,  Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE );
    356 #endif
    357 
    358 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
     328
     329#if KWU_RC_MADPRED_E0227
    359330  UInt   getSADPart ( Int bitDepth, Pel* pelCur, Int curStride,  Pel* pelOrg, Int orgStride, UInt width, UInt height );
    360331#endif
  • trunk/source/Lib/TLibCommon/TComRdCostWeightPrediction.cpp

    r608 r872  
    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/TLibCommon/TComRdCostWeightPrediction.h

    r608 r872  
    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/TLibCommon/TComRom.cpp

    r773 r872  
    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 *
     
    327327UInt g_uiPCMBitDepthChroma   = 8;    // PCM bit-depth
    328328
     329#if H_3D_DIM_DMM
    329330// ====================================================================================================================
    330331// Depth coding modes
    331332// ====================================================================================================================
    332 #if H_3D_DIM_DMM
    333333const WedgeResolution g_dmmWedgeResolution[6] =
    334334{
     
    372372Bool g_traceTU = true;
    373373Bool g_disableHLSTrace = false;
    374 UInt64 g_stopAtCounter       = 48;
     374UInt64 g_stopAtCounter       = 0;
    375375Bool g_traceCopyBack         = false;
    376376Bool g_decTraceDispDer       = false;
    377377Bool g_decTraceMvFromMerge   = false;
     378Bool g_stopAtPos             = false;
     379Bool g_outputPos             = false;
    378380#endif
    379381#endif
     
    395397const UInt g_uiMinInGroup[ 10 ] = {0,1,2,3,4,6,8,12,16,24};
    396398const UInt g_uiGroupIdx[ 32 ]   = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9};
    397 
    398 // Rice parameters for absolute transform levels
    399 const UInt g_auiGoRiceRange[5] =
    400 {
    401   7, 14, 26, 46, 78
    402 };
    403 
    404 const UInt g_auiGoRicePrefixLen[5] =
    405 {
    406   8, 7, 6, 5, 4
    407 };
    408399
    409400Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight)
     
    573564#if H_MV_ENC_DEC_TRAC
    574565#if ENC_DEC_TRACE
     566Void stopAtPos( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight )
     567{
     568
     569  if ( g_outputPos )
     570  {
     571    std::cout << "POC\t"        << poc
     572              << "\tLayerId\t"  << layerId
     573              << "\tCuPelX\t"   << cuPelX 
     574              << "\tCuPelY\t"   << cuPelY
     575              << "\tCuWidth\t"  << cuWidth
     576              << "\tCuHeight\t" << cuHeight
     577              << std::endl;
     578  }
     579
     580  Bool stopFlag = false;
     581  if ( g_stopAtPos && poc == 0 && layerId == 1 )
     582  {
     583    Bool stopAtCU = true;
     584    if ( stopAtCU )        // Stop at CU with specific size
     585    {   
     586      stopFlag = ( cuPelX  == 888 ) && ( cuPelY  == 248 ) && ( cuWidth == 8 ) && ( cuHeight == 8);
     587    }
     588    else
     589    {                     // Stop at specific position
     590      Int xPos = 888;
     591      Int yPos = 248;
     592
     593      Int cuPelXEnd = cuPelX + cuWidth  - 1;
     594      Int cuPelYEnd = cuPelY + cuHeight - 1;
     595
     596      stopFlag = (cuPelX <= xPos ) && (cuPelXEnd >= xPos ) && (cuPelY <= yPos ) && (cuPelYEnd >= yPos );
     597    }
     598  }
     599 
     600  if ( stopFlag )
     601  { // Set breakpoint here.
     602    std::cout << "Stop position. Break point here." << std::endl;
     603  } 
     604}
     605
    575606Void writeToTraceFile( const Char* symbolName, Int val, Bool doIt )
    576607{
  • trunk/source/Lib/TLibCommon/TComRom.h

    r773 r872  
    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 *
     
    126126extern const UInt   g_uiMinInGroup[ 10 ];
    127127
    128 extern const UInt   g_auiGoRiceRange[5];                  //!< maximum value coded with Rice codes
    129 extern const UInt   g_auiGoRicePrefixLen[5];              //!< prefix length for each maximum value
    130  
    131128extern const UInt   g_sigLastScan8x8[ 3 ][ 4 ];           //!< coefficient group scan order for 8x8 TUs
    132129extern       UInt   g_sigLastScanCG32x32[ 64 ];
     
    224221 extern Bool   g_decTraceDispDer; // Trace derived disparity vectors (decoder only)
    225222 extern Bool   g_decTraceMvFromMerge;   // Trace motion vectors obtained from merge (decoder only)
     223 extern Bool   g_stopAtPos;             // Stop at position
     224 extern Bool   g_outputPos;             // Output position
    226225
    227226#define DTRACE_CU(x,y)             writeToTraceFile( x,y, g_traceCU );
     
    235234 Void           writeToTraceFile( const Char* symbolName, Int val, Bool doIt );
    236235 Void           writeToTraceFile( const Char* symbolName, Bool doIt );
     236 Void           stopAtPos       ( Int poc, Int layerId, Int cuPelX, Int cuPelY, Int cuWidth, Int cuHeight );
    237237#endif
    238238#else
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp

    r608 r872  
    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 *
     
    4444//! \ingroup TLibCommon
    4545//! \{
    46 
    47 SAOParam::~SAOParam()
    48 {
    49   for (Int i = 0 ; i<3; i++)
    50   {
    51     if (psSaoPart[i])
    52     {
    53       delete [] psSaoPart[i];
    54     }
    55   }
    56 }
    57 
    58 // ====================================================================================================================
    59 // Tables
    60 // ====================================================================================================================
     46UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];
     47
     48SAOOffset::SAOOffset()
     49{
     50  reset();
     51}
     52
     53SAOOffset::~SAOOffset()
     54{
     55
     56}
     57
     58Void SAOOffset::reset()
     59{
     60  modeIdc = SAO_MODE_OFF;
     61  typeIdc = -1;
     62  typeAuxInfo = -1;
     63  ::memset(offset, 0, sizeof(Int)* MAX_NUM_SAO_CLASSES);
     64}
     65
     66const SAOOffset& SAOOffset::operator= (const SAOOffset& src)
     67{
     68  modeIdc = src.modeIdc;
     69  typeIdc = src.typeIdc;
     70  typeAuxInfo = src.typeAuxInfo;
     71  ::memcpy(offset, src.offset, sizeof(Int)* MAX_NUM_SAO_CLASSES);
     72
     73  return *this;
     74}
     75
     76
     77SAOBlkParam::SAOBlkParam()
     78{
     79  reset();
     80}
     81
     82SAOBlkParam::~SAOBlkParam()
     83{
     84
     85}
     86
     87Void SAOBlkParam::reset()
     88{
     89  for(Int compIdx=0; compIdx< 3; compIdx++)
     90  {
     91    offsetParam[compIdx].reset();
     92  }
     93}
     94
     95const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src)
     96{
     97  for(Int compIdx=0; compIdx< 3; compIdx++)
     98  {
     99    offsetParam[compIdx] = src.offsetParam[compIdx];
     100  }
     101  return *this;
     102
     103}
    61104
    62105TComSampleAdaptiveOffset::TComSampleAdaptiveOffset()
    63106{
    64   m_pClipTable = NULL;
    65   m_pClipTableBase = NULL;
    66   m_pChromaClipTable = NULL;
    67   m_pChromaClipTableBase = NULL;
    68   m_iOffsetBo = NULL;
    69   m_iChromaOffsetBo = NULL;
    70   m_lumaTableBo = NULL;
    71   m_chromaTableBo = NULL;
    72   m_iUpBuff1 = NULL;
    73   m_iUpBuff2 = NULL;
    74   m_iUpBufft = NULL;
    75   ipSwap = NULL;
    76 
    77   m_pTmpU1 = NULL;
    78   m_pTmpU2 = NULL;
    79   m_pTmpL1 = NULL;
    80   m_pTmpL2 = NULL;
    81 }
     107  m_tempPicYuv = NULL;
     108  for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     109  {
     110    m_offsetClipTable[compIdx] = NULL;
     111  }
     112  m_signTable = NULL;
     113
     114 
     115  m_lineBufWidth = 0;
     116  m_signLineBuf1 = NULL;
     117  m_signLineBuf2 = NULL;
     118}
     119
    82120
    83121TComSampleAdaptiveOffset::~TComSampleAdaptiveOffset()
    84122{
    85 
    86 }
    87 
    88 const Int TComSampleAdaptiveOffset::m_aiNumCulPartsLevel[5] =
    89 {
    90   1,   //level 0
    91   5,   //level 1
    92   21,  //level 2
    93   85,  //level 3
    94   341, //level 4
    95 };
    96 
    97 const UInt TComSampleAdaptiveOffset::m_auiEoTable[9] =
    98 {
    99   1, //0   
    100   2, //1   
    101   0, //2
    102   3, //3
    103   4, //4
    104   0, //5 
    105   0, //6 
    106   0, //7
    107   0
    108 };
    109 
    110 const Int TComSampleAdaptiveOffset::m_iNumClass[MAX_NUM_SAO_TYPE] =
    111 {
    112   SAO_EO_LEN,
    113   SAO_EO_LEN,
    114   SAO_EO_LEN,
    115   SAO_EO_LEN,
    116   SAO_BO_LEN
    117 };
    118 
    119 const UInt TComSampleAdaptiveOffset::m_uiMaxDepth = SAO_MAX_DEPTH;
    120 
    121 
    122 /** convert Level Row Col to Idx
    123  * \param   level,  row,  col
    124  */
    125 Int  TComSampleAdaptiveOffset::convertLevelRowCol2Idx(Int level, Int row, Int col)
    126 {
    127   Int idx;
    128   if (level == 0)
    129   {
    130     idx = 0;
    131   }
    132   else if (level == 1)
    133   {
    134     idx = 1 + row*2 + col;
    135   }
    136   else if (level == 2)
    137   {
    138     idx = 5 + row*4 + col;
    139   }
    140   else if (level == 3)
    141   {
    142     idx = 21 + row*8 + col;
    143   }
    144   else // (level == 4)
    145   {
    146     idx = 85 + row*16 + col;
    147   }
    148   return idx;
    149 }
    150 
    151 /** create SampleAdaptiveOffset memory.
    152  * \param
    153  */
    154 Void TComSampleAdaptiveOffset::create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight )
    155 {
    156   m_iPicWidth  = uiSourceWidth;
    157   m_iPicHeight = uiSourceHeight;
    158 
    159   m_uiMaxCUWidth  = uiMaxCUWidth;
    160   m_uiMaxCUHeight = uiMaxCUHeight;
    161 
    162   m_iNumCuInWidth  = m_iPicWidth / m_uiMaxCUWidth;
    163   m_iNumCuInWidth += ( m_iPicWidth % m_uiMaxCUWidth ) ? 1 : 0;
    164 
    165   m_iNumCuInHeight  = m_iPicHeight / m_uiMaxCUHeight;
    166   m_iNumCuInHeight += ( m_iPicHeight % m_uiMaxCUHeight ) ? 1 : 0;
    167 
    168   Int iMaxSplitLevelHeight = (Int)(logf((Float)m_iNumCuInHeight)/logf(2.0));
    169   Int iMaxSplitLevelWidth  = (Int)(logf((Float)m_iNumCuInWidth )/logf(2.0));
    170 
    171   m_uiMaxSplitLevel = (iMaxSplitLevelHeight < iMaxSplitLevelWidth)?(iMaxSplitLevelHeight):(iMaxSplitLevelWidth);
    172   m_uiMaxSplitLevel = (m_uiMaxSplitLevel< m_uiMaxDepth)?(m_uiMaxSplitLevel):(m_uiMaxDepth);
    173   /* various structures are overloaded to store per component data.
    174    * m_iNumTotalParts must allow for sufficient storage in any allocated arrays */
    175   m_iNumTotalParts  = max(3,m_aiNumCulPartsLevel[m_uiMaxSplitLevel]);
    176 
    177   UInt uiPixelRangeY = 1 << g_bitDepthY;
    178   UInt uiBoRangeShiftY = g_bitDepthY - SAO_BO_BITS;
    179 
    180   m_lumaTableBo = new Pel [uiPixelRangeY];
    181   for (Int k2=0; k2<uiPixelRangeY; k2++)
    182   {
    183     m_lumaTableBo[k2] = 1 + (k2>>uiBoRangeShiftY);
    184   }
    185 
    186   UInt uiPixelRangeC = 1 << g_bitDepthC;
    187   UInt uiBoRangeShiftC = g_bitDepthC - SAO_BO_BITS;
    188 
    189   m_chromaTableBo = new Pel [uiPixelRangeC];
    190   for (Int k2=0; k2<uiPixelRangeC; k2++)
    191   {
    192     m_chromaTableBo[k2] = 1 + (k2>>uiBoRangeShiftC);
    193   }
    194 
    195   m_iUpBuff1 = new Int[m_iPicWidth+2];
    196   m_iUpBuff2 = new Int[m_iPicWidth+2];
    197   m_iUpBufft = new Int[m_iPicWidth+2];
    198 
    199   m_iUpBuff1++;
    200   m_iUpBuff2++;
    201   m_iUpBufft++;
    202   Pel i;
    203 
    204   UInt uiMaxY  = (1 << g_bitDepthY) - 1;;
    205   UInt uiMinY  = 0;
    206 
    207   Int iCRangeExt = uiMaxY>>1;
    208 
    209   m_pClipTableBase = new Pel[uiMaxY+2*iCRangeExt];
    210   m_iOffsetBo      = new Int[uiMaxY+2*iCRangeExt];
    211 
    212   for(i=0;i<(uiMinY+iCRangeExt);i++)
    213   {
    214     m_pClipTableBase[i] = uiMinY;
    215   }
    216 
    217   for(i=uiMinY+iCRangeExt;i<(uiMaxY+  iCRangeExt);i++)
    218   {
    219     m_pClipTableBase[i] = i-iCRangeExt;
    220   }
    221 
    222   for(i=uiMaxY+iCRangeExt;i<(uiMaxY+2*iCRangeExt);i++)
    223   {
    224     m_pClipTableBase[i] = uiMaxY;
    225   }
    226 
    227   m_pClipTable = &(m_pClipTableBase[iCRangeExt]);
    228 
    229   UInt uiMaxC  = (1 << g_bitDepthC) - 1;
    230   UInt uiMinC  = 0;
    231 
    232   Int iCRangeExtC = uiMaxC>>1;
    233 
    234   m_pChromaClipTableBase = new Pel[uiMaxC+2*iCRangeExtC];
    235   m_iChromaOffsetBo      = new Int[uiMaxC+2*iCRangeExtC];
    236 
    237   for(i=0;i<(uiMinC+iCRangeExtC);i++)
    238   {
    239     m_pChromaClipTableBase[i] = uiMinC;
    240   }
    241 
    242   for(i=uiMinC+iCRangeExtC;i<(uiMaxC+  iCRangeExtC);i++)
    243   {
    244     m_pChromaClipTableBase[i] = i-iCRangeExtC;
    245   }
    246 
    247   for(i=uiMaxC+iCRangeExtC;i<(uiMaxC+2*iCRangeExtC);i++)
    248   {
    249     m_pChromaClipTableBase[i] = uiMaxC;
    250   }
    251 
    252   m_pChromaClipTable = &(m_pChromaClipTableBase[iCRangeExtC]);
    253 
    254   m_pTmpL1 = new Pel [m_uiMaxCUHeight+1];
    255   m_pTmpL2 = new Pel [m_uiMaxCUHeight+1];
    256   m_pTmpU1 = new Pel [m_iPicWidth];
    257   m_pTmpU2 = new Pel [m_iPicWidth];
    258 }
    259 
    260 /** destroy SampleAdaptiveOffset memory.
    261  * \param
    262  */
     123  destroy();
     124 
     125  if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     126  if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     127}
     128
     129Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth )
     130{
     131  destroy();
     132
     133  m_picWidth = picWidth;   
     134  m_picHeight= picHeight;
     135  m_maxCUWidth= maxCUWidth;
     136  m_maxCUHeight= maxCUHeight;
     137
     138  m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0);
     139  m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0);
     140  m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth;
     141
     142  //temporary picture buffer
     143  if ( !m_tempPicYuv )
     144  {
     145    m_tempPicYuv = new TComPicYuv;
     146    m_tempPicYuv->create( m_picWidth, m_picHeight, m_maxCUWidth, m_maxCUHeight, maxCUDepth );
     147  }
     148
     149  //bit-depth related
     150  for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     151  {
     152    Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC;
     153    m_offsetStepLog2  [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0);
     154    g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive
     155  }
     156
     157  //look-up table for clipping
     158  for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     159  {
     160    Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive
     161    Int maxSampleValue = (1<< bitDepthSample); //exclusive
     162    Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]);
     163
     164    m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0
     165    m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]);
     166
     167    //assign clipped values
     168    Int* offsetClipPtr = m_offsetClip[compIdx];
     169    for(Int k=0; k< maxSampleValue; k++)
     170    {
     171      *(offsetClipPtr + k) = k;
     172    }
     173    for(Int k=0; k< maxOffsetValue; k++ )
     174    {
     175      *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1;
     176      *(offsetClipPtr -k -1 )              = 0;
     177    }
     178    if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC
     179    {
     180      m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ];
     181      m_sign = &(m_signTable[maxSampleValue-1]);
     182
     183      m_sign[0] = 0;
     184      for(Int k=1; k< maxSampleValue; k++)
     185      {
     186        m_sign[k] = 1;
     187        m_sign[-k]= -1;
     188      }
     189    }
     190  } 
     191
     192}
     193
    263194Void TComSampleAdaptiveOffset::destroy()
    264195{
    265   if (m_pClipTableBase)
    266   {
    267     delete [] m_pClipTableBase; m_pClipTableBase = NULL;
    268   }
    269   if (m_iOffsetBo)
    270   {
    271     delete [] m_iOffsetBo; m_iOffsetBo = NULL;
    272   }
    273   if (m_lumaTableBo)
    274   {
    275     delete[] m_lumaTableBo; m_lumaTableBo = NULL;
    276   }
    277 
    278   if (m_pChromaClipTableBase)
    279   {
    280     delete [] m_pChromaClipTableBase; m_pChromaClipTableBase = NULL;
    281   }
    282   if (m_iChromaOffsetBo)
    283   {
    284     delete [] m_iChromaOffsetBo; m_iChromaOffsetBo = NULL;
    285   }
    286   if (m_chromaTableBo)
    287   {
    288     delete[] m_chromaTableBo; m_chromaTableBo = NULL;
    289   }
    290 
    291   if (m_iUpBuff1)
    292   {
    293     m_iUpBuff1--;
    294     delete [] m_iUpBuff1; m_iUpBuff1 = NULL;
    295   }
    296   if (m_iUpBuff2)
    297   {
    298     m_iUpBuff2--;
    299     delete [] m_iUpBuff2; m_iUpBuff2 = NULL;
    300   }
    301   if (m_iUpBufft)
    302   {
    303     m_iUpBufft--;
    304     delete [] m_iUpBufft; m_iUpBufft = NULL;
    305   }
    306   if (m_pTmpL1)
    307   {
    308     delete [] m_pTmpL1; m_pTmpL1 = NULL;
    309   }
    310   if (m_pTmpL2)
    311   {
    312     delete [] m_pTmpL2; m_pTmpL2 = NULL;
    313   }
    314   if (m_pTmpU1)
    315   {
    316     delete [] m_pTmpU1; m_pTmpU1 = NULL;
    317   }
    318   if (m_pTmpU2)
    319   {
    320     delete [] m_pTmpU2; m_pTmpU2 = NULL;
    321   }
    322 }
    323 
    324 /** allocate memory for SAO parameters
    325  * \param    *pcSaoParam
    326  */
    327 Void TComSampleAdaptiveOffset::allocSaoParam(SAOParam *pcSaoParam)
    328 {
    329   pcSaoParam->iMaxSplitLevel = m_uiMaxSplitLevel;
    330   pcSaoParam->psSaoPart[0] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
    331   initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,0);
    332   pcSaoParam->psSaoPart[1] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
    333   pcSaoParam->psSaoPart[2] = new SAOQTPart[ m_aiNumCulPartsLevel[pcSaoParam->iMaxSplitLevel] ];
    334   initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,1);
    335   initSAOParam(pcSaoParam, 0, 0, 0, -1, 0, m_iNumCuInWidth-1,  0, m_iNumCuInHeight-1,2);
    336   pcSaoParam->numCuInWidth  = m_iNumCuInWidth;
    337   pcSaoParam->numCuInHeight = m_iNumCuInHeight;
    338   pcSaoParam->saoLcuParam[0] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
    339   pcSaoParam->saoLcuParam[1] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
    340   pcSaoParam->saoLcuParam[2] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
    341 }
    342 
    343 /** initialize SAO parameters
    344  * \param    *pcSaoParam,  iPartLevel,  iPartRow,  iPartCol,  iParentPartIdx,  StartCUX,  EndCUX,  StartCUY,  EndCUY,  iYCbCr
    345  */
    346 Void TComSampleAdaptiveOffset::initSAOParam(SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr)
    347 {
    348   Int j;
    349   Int iPartIdx = convertLevelRowCol2Idx(iPartLevel, iPartRow, iPartCol);
    350 
    351   SAOQTPart* pSaoPart;
    352 
    353   pSaoPart = &(pcSaoParam->psSaoPart[iYCbCr][iPartIdx]);
    354 
    355   pSaoPart->PartIdx   = iPartIdx;
    356   pSaoPart->PartLevel = iPartLevel;
    357   pSaoPart->PartRow   = iPartRow;
    358   pSaoPart->PartCol   = iPartCol;
    359 
    360   pSaoPart->StartCUX  = StartCUX;
    361   pSaoPart->EndCUX    = EndCUX;
    362   pSaoPart->StartCUY  = StartCUY;
    363   pSaoPart->EndCUY    = EndCUY;
    364 
    365   pSaoPart->UpPartIdx = iParentPartIdx;
    366   pSaoPart->iBestType   = -1;
    367   pSaoPart->iLength     =  0;
    368 
    369   pSaoPart->subTypeIdx = 0;
    370 
    371   for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    372   {
    373     pSaoPart->iOffset[j] = 0;
    374   }
    375 
    376   if(pSaoPart->PartLevel != m_uiMaxSplitLevel)
    377   {
    378     Int DownLevel    = (iPartLevel+1 );
    379     Int DownRowStart = (iPartRow << 1);
    380     Int DownColStart = (iPartCol << 1);
    381 
    382     Int iDownRowIdx, iDownColIdx;
    383     Int NumCUWidth,  NumCUHeight;
    384     Int NumCULeft;
    385     Int NumCUTop;
    386 
    387     Int DownStartCUX, DownStartCUY;
    388     Int DownEndCUX, DownEndCUY;
    389 
    390     NumCUWidth  = EndCUX - StartCUX +1;
    391     NumCUHeight = EndCUY - StartCUY +1;
    392     NumCULeft   = (NumCUWidth  >> 1);
    393     NumCUTop    = (NumCUHeight >> 1);
    394 
    395     DownStartCUX= StartCUX;
    396     DownEndCUX  = DownStartCUX + NumCULeft - 1;
    397     DownStartCUY= StartCUY;
    398     DownEndCUY  = DownStartCUY + NumCUTop  - 1;
    399     iDownRowIdx = DownRowStart + 0;
    400     iDownColIdx = DownColStart + 0;
    401 
    402     pSaoPart->DownPartsIdx[0]= convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
    403 
    404     initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
    405 
    406     DownStartCUX = StartCUX + NumCULeft;
    407     DownEndCUX   = EndCUX;
    408     DownStartCUY = StartCUY;
    409     DownEndCUY   = DownStartCUY + NumCUTop -1;
    410     iDownRowIdx  = DownRowStart + 0;
    411     iDownColIdx  = DownColStart + 1;
    412 
    413     pSaoPart->DownPartsIdx[1] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
    414 
    415     initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx,  DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
    416 
    417     DownStartCUX = StartCUX;
    418     DownEndCUX   = DownStartCUX + NumCULeft -1;
    419     DownStartCUY = StartCUY + NumCUTop;
    420     DownEndCUY   = EndCUY;
    421     iDownRowIdx  = DownRowStart + 1;
    422     iDownColIdx  = DownColStart + 0;
    423 
    424     pSaoPart->DownPartsIdx[2] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
    425 
    426     initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx, DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
    427 
    428     DownStartCUX = StartCUX+ NumCULeft;
    429     DownEndCUX   = EndCUX;
    430     DownStartCUY = StartCUY + NumCUTop;
    431     DownEndCUY   = EndCUY;
    432     iDownRowIdx  = DownRowStart + 1;
    433     iDownColIdx  = DownColStart + 1;
    434 
    435     pSaoPart->DownPartsIdx[3] = convertLevelRowCol2Idx(DownLevel, iDownRowIdx, iDownColIdx);
    436 
    437     initSAOParam(pcSaoParam, DownLevel, iDownRowIdx, iDownColIdx, iPartIdx,DownStartCUX, DownEndCUX, DownStartCUY, DownEndCUY, iYCbCr);
    438   }
    439   else
    440   {
    441     pSaoPart->DownPartsIdx[0]=pSaoPart->DownPartsIdx[1]= pSaoPart->DownPartsIdx[2]= pSaoPart->DownPartsIdx[3]= -1;
    442   }
    443 }
    444 
    445 /** free memory of SAO parameters
    446  * \param   pcSaoParam
    447  */
    448 Void TComSampleAdaptiveOffset::freeSaoParam(SAOParam *pcSaoParam)
    449 {
    450   delete [] pcSaoParam->psSaoPart[0];
    451   delete [] pcSaoParam->psSaoPart[1];
    452   delete [] pcSaoParam->psSaoPart[2];
    453   pcSaoParam->psSaoPart[0] = 0;
    454   pcSaoParam->psSaoPart[1] = 0;
    455   pcSaoParam->psSaoPart[2] = 0;
    456   if( pcSaoParam->saoLcuParam[0])
    457   {
    458     delete [] pcSaoParam->saoLcuParam[0]; pcSaoParam->saoLcuParam[0] = NULL;
    459   }
    460   if( pcSaoParam->saoLcuParam[1])
    461   {
    462     delete [] pcSaoParam->saoLcuParam[1]; pcSaoParam->saoLcuParam[1] = NULL;
    463   }
    464   if( pcSaoParam->saoLcuParam[2])
    465   {
    466     delete [] pcSaoParam->saoLcuParam[2]; pcSaoParam->saoLcuParam[2] = NULL;
    467   }
    468 }
    469 
    470 /** reset SAO parameters
    471  * \param   pcSaoParam
    472  */
    473 Void TComSampleAdaptiveOffset::resetSAOParam(SAOParam *pcSaoParam)
    474 {
    475   Int iNumComponet = 3;
    476   for(Int c=0; c<iNumComponet; c++)
    477   {
    478 if (c<2)
    479   {
    480     pcSaoParam->bSaoFlag[c] = 0;
    481   }
    482     for(Int i=0; i< m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; i++)
    483     {
    484       pcSaoParam->psSaoPart[c][i].iBestType     = -1;
    485       pcSaoParam->psSaoPart[c][i].iLength       =  0;
    486       pcSaoParam->psSaoPart[c][i].bSplit        = false;
    487       pcSaoParam->psSaoPart[c][i].bProcessed    = false;
    488       pcSaoParam->psSaoPart[c][i].dMinCost      = MAX_DOUBLE;
    489       pcSaoParam->psSaoPart[c][i].iMinDist      = MAX_INT;
    490       pcSaoParam->psSaoPart[c][i].iMinRate      = MAX_INT;
    491       pcSaoParam->psSaoPart[c][i].subTypeIdx    = 0;
    492       for (Int j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    493       {
    494         pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
    495         pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
    496         pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
    497       }
    498     }
    499     pcSaoParam->oneUnitFlag[0]   = 0;
    500     pcSaoParam->oneUnitFlag[1]   = 0;
    501     pcSaoParam->oneUnitFlag[2]   = 0;
    502     resetLcuPart(pcSaoParam->saoLcuParam[0]);
    503     resetLcuPart(pcSaoParam->saoLcuParam[1]);
    504     resetLcuPart(pcSaoParam->saoLcuParam[2]);
    505   }
    506 }
    507 
    508 /** get the sign of input variable
    509  * \param   x
    510  */
    511 inline Int xSign(Int x)
    512 {
    513   return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31)));
    514 }
    515 
    516 /** initialize variables for SAO process
    517  * \param  pcPic picture data pointer
    518  */
    519 Void TComSampleAdaptiveOffset::createPicSaoInfo(TComPic* pcPic)
    520 {
    521   m_pcPic   = pcPic;
    522   m_bUseNIF = ( pcPic->getIndependentSliceBoundaryForNDBFilter() || pcPic->getIndependentTileBoundaryForNDBFilter() );
    523   if(m_bUseNIF)
    524   {
    525     m_pcYuvTmp = pcPic->getYuvPicBufferForIndependentBoundaryProcessing();
    526   }
    527 }
    528 
    529 Void TComSampleAdaptiveOffset::destroyPicSaoInfo()
    530 {
    531 
    532 }
    533 
    534 /** sample adaptive offset process for one LCU
    535  * \param   iAddr, iSaoType, iYCbCr
    536  */
    537 Void TComSampleAdaptiveOffset::processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr)
    538 {
    539   if(!m_bUseNIF)
    540   {
    541     processSaoCuOrg( iAddr, iSaoType, iYCbCr);
    542   }
    543   else
    544   { 
    545     Int  isChroma = (iYCbCr != 0)? 1:0;
    546     Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
    547     Pel* pPicRest = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr);
    548     Pel* pPicDec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
    549 
    550     std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
    551 
    552     //variables
    553     UInt  xPos, yPos, width, height;
    554     Bool* pbBorderAvail;
    555     UInt  posOffset;
    556 
    557     for(Int i=0; i< vFilterBlocks.size(); i++)
    558     {
    559       xPos        = vFilterBlocks[i].posX   >> isChroma;
    560       yPos        = vFilterBlocks[i].posY   >> isChroma;
    561       width       = vFilterBlocks[i].width  >> isChroma;
    562       height      = vFilterBlocks[i].height >> isChroma;
    563       pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
    564 
    565       posOffset = (yPos* stride) + xPos;
    566 
    567       processSaoBlock(pPicDec+ posOffset, pPicRest+ posOffset, stride, iSaoType, width, height, pbBorderAvail, iYCbCr);
    568     }
    569   }
    570 }
    571 
    572 /** Perform SAO for non-cross-slice or non-cross-tile process
    573  * \param  pDec to-be-filtered block buffer pointer
    574  * \param  pRest filtered block buffer pointer
    575  * \param  stride picture buffer stride
    576  * \param  saoType SAO offset type
    577  * \param  xPos x coordinate
    578  * \param  yPos y coordinate
    579  * \param  width block width
    580  * \param  height block height
    581  * \param  pbBorderAvail availabilities of block border pixels
    582  */
    583 Void TComSampleAdaptiveOffset::processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int saoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr)
    584 {
    585   //variables
    586   Int startX, startY, endX, endY, x, y;
    587   Int signLeft,signRight,signDown,signDown1;
    588   UInt edgeType;
    589   Pel *pClipTbl = (iYCbCr==0)?m_pClipTable:m_pChromaClipTable;
    590   Int *pOffsetBo = (iYCbCr==0)?m_iOffsetBo: m_iChromaOffsetBo;
    591 
    592   switch (saoType)
    593   {
    594   case SAO_EO_0: // dir: -
    595     {
    596 
    597       startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    598       endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     196  if ( m_tempPicYuv )
     197  {
     198    m_tempPicYuv->destroy();
     199    delete m_tempPicYuv;
     200    m_tempPicYuv = NULL;
     201  }
     202
     203  for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     204  {
     205    if(m_offsetClipTable[compIdx])
     206    {
     207      delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL;
     208    }
     209  }
     210  if( m_signTable )
     211  {
     212    delete[] m_signTable; m_signTable = NULL;
     213  }
     214}
     215
     216Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets)
     217{
     218  Int codedOffset[MAX_NUM_SAO_CLASSES];
     219
     220  ::memcpy(codedOffset, srcOffsets, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     221  ::memset(dstOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     222
     223  if(typeIdc == SAO_TYPE_START_BO)
     224  {
     225    for(Int i=0; i< 4; i++)
     226    {
     227      dstOffsets[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES] = codedOffset[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES]*(1<<m_offsetStepLog2[compIdx]);
     228    }
     229  }
     230  else //EO
     231  {
     232    for(Int i=0; i< NUM_SAO_EO_CLASSES; i++)
     233    {
     234      dstOffsets[i] = codedOffset[i] *(1<<m_offsetStepLog2[compIdx]);
     235    }
     236    assert(dstOffsets[SAO_CLASS_EO_PLAIN] == 0); //keep EO plain offset as zero
     237  }
     238
     239}
     240
     241Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList)
     242{
     243  Int ctuX = ctu % m_numCTUInWidth;
     244  Int ctuY = ctu / m_numCTUInWidth;
     245  Int mergedCTUPos;
     246  Int numValidMergeCandidates = 0;
     247
     248  for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++)
     249  {
     250    SAOBlkParam* mergeCandidate = NULL;
     251
     252    switch(mergeType)
     253    {
     254    case SAO_MERGE_ABOVE:
     255      {
     256        if(ctuY > 0)
     257        {
     258          mergedCTUPos = ctu- m_numCTUInWidth;
     259          if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     260          {
     261            mergeCandidate = &(blkParams[mergedCTUPos]);
     262          }
     263        }
     264      }
     265      break;
     266    case SAO_MERGE_LEFT:
     267      {
     268        if(ctuX > 0)
     269        {
     270          mergedCTUPos = ctu- 1;
     271          if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) )
     272          {
     273            mergeCandidate = &(blkParams[mergedCTUPos]);
     274          }
     275        }
     276      }
     277      break;
     278    default:
     279      {
     280        printf("not a supported merge type");
     281        assert(0);
     282        exit(-1);
     283      }
     284    }
     285
     286    mergeList.push_back(mergeCandidate);
     287    if (mergeCandidate != NULL)
     288    {
     289      numValidMergeCandidates++;
     290    }
     291  }
     292
     293  return numValidMergeCandidates;
     294}
     295
     296
     297Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList)
     298{
     299  for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     300  {
     301    SAOOffset& offsetParam = recParam[compIdx];
     302
     303    if(offsetParam.modeIdc == SAO_MODE_OFF)
     304    {
     305      continue;
     306    }
     307
     308    switch(offsetParam.modeIdc)
     309    {
     310    case SAO_MODE_NEW:
     311      {
     312        invertQuantOffsets(compIdx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset);
     313      }
     314      break;
     315    case SAO_MODE_MERGE:
     316      {
     317        SAOBlkParam* mergeTarget = mergeList[offsetParam.typeIdc];
     318        assert(mergeTarget != NULL);
     319
     320        offsetParam = (*mergeTarget)[compIdx];
     321      }
     322      break;
     323    default:
     324      {
     325        printf("Not a supported mode");
     326        assert(0);
     327        exit(-1);
     328      }
     329    }
     330  }
     331}
     332
     333Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams)
     334{
     335  m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false;
     336
     337  for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     338  {
     339    std::vector<SAOBlkParam*> mergeList;
     340    getMergeList(pic, ctu, saoBlkParams, mergeList);
     341
     342    reconstructBlkSAOParam(saoBlkParams[ctu], mergeList);
     343
     344    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     345    {
     346      if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF)
     347      {
     348        m_picSAOEnabled[compIdx] = true;
     349      }
     350    }
     351  }
     352
     353
     354}
     355
     356
     357Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 
     358                                          , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
     359                                          , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail)
     360{
     361  if(m_lineBufWidth != m_maxCUWidth)
     362  {
     363    m_lineBufWidth = m_maxCUWidth;
     364   
     365    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     366    m_signLineBuf1 = new Char[m_lineBufWidth+1];
     367   
     368    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     369    m_signLineBuf2 = new Char[m_lineBufWidth+1];
     370  }
     371
     372  Int* offsetClip = m_offsetClip[compIdx];
     373
     374  Int x,y, startX, startY, endX, endY, edgeType;
     375  Int firstLineStartX, firstLineEndX, lastLineStartX, lastLineEndX;
     376  Char signLeft, signRight, signDown;
     377
     378  Pel* srcLine = srcBlk;
     379  Pel* resLine = resBlk;
     380
     381  switch(typeIdx)
     382  {
     383  case SAO_TYPE_EO_0:
     384    {
     385      offset += 2;
     386      startX = isLeftAvail ? 0 : 1;
     387      endX   = isRightAvail ? width : (width -1);
    599388      for (y=0; y< height; y++)
    600389      {
    601         signLeft = xSign(pDec[startX] - pDec[startX-1]);
     390        signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
    602391        for (x=startX; x< endX; x++)
    603392        {
    604           signRight =  xSign(pDec[x] - pDec[x+1]);
    605           edgeType =  signRight + signLeft + 2;
     393          signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]];
     394          edgeType =  signRight + signLeft;
    606395          signLeft  = -signRight;
    607396
    608           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
     397          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
    609398        }
    610         pDec  += stride;
    611         pRest += stride;
    612       }
    613       break;
    614     }
    615   case SAO_EO_1: // dir: |
    616     {
    617       startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
    618       endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
    619       if (!pbBorderAvail[SGU_T])
    620       {
    621         pDec  += stride;
    622         pRest += stride;
    623       }
     399        srcLine  += srcStride;
     400        resLine += resStride;
     401      }
     402
     403    }
     404    break;
     405  case SAO_TYPE_EO_90:
     406    {
     407      offset += 2;
     408      Char *signUpLine = m_signLineBuf1;
     409
     410      startY = isAboveAvail ? 0 : 1;
     411      endY   = isBelowAvail ? height : height-1;
     412      if (!isAboveAvail)
     413      {
     414        srcLine += srcStride;
     415        resLine += resStride;
     416      }
     417
     418      Pel* srcLineAbove= srcLine- srcStride;
    624419      for (x=0; x< width; x++)
    625420      {
    626         m_iUpBuff1[x] = xSign(pDec[x] - pDec[x-stride]);
    627       }
     421        signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
     422      }
     423
     424      Pel* srcLineBelow;
    628425      for (y=startY; y<endY; y++)
    629426      {
     427        srcLineBelow= srcLine+ srcStride;
     428
    630429        for (x=0; x< width; x++)
    631430        {
    632           signDown  = xSign(pDec[x] - pDec[x+stride]);
    633           edgeType = signDown + m_iUpBuff1[x] + 2;
    634           m_iUpBuff1[x]= -signDown;
    635 
    636           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
     431          signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
     432          edgeType = signDown + signUpLine[x];
     433          signUpLine[x]= -signDown;
     434
     435          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
    637436        }
    638         pDec  += stride;
    639         pRest += stride;
    640       }
    641       break;
    642     }
    643   case SAO_EO_2: // dir: 135
    644     {
    645       Int posShift= stride + 1;
    646 
    647       startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
    648       endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
    649 
    650       //prepare 2nd line upper sign
    651       pDec += stride;
     437        srcLine += srcStride;
     438        resLine += resStride;
     439      }
     440
     441    }
     442    break;
     443  case SAO_TYPE_EO_135:
     444    {
     445      offset += 2;
     446      Char *signUpLine, *signDownLine, *signTmpLine;
     447
     448      signUpLine  = m_signLineBuf1;
     449      signDownLine= m_signLineBuf2;
     450
     451      startX = isLeftAvail ? 0 : 1 ;
     452      endX   = isRightAvail ? width : (width-1);
     453
     454      //prepare 2nd line's upper sign
     455      Pel* srcLineBelow= srcLine+ srcStride;
    652456      for (x=startX; x< endX+1; x++)
    653457      {
    654         m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);
     458        signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]];
    655459      }
    656460
    657461      //1st line
    658       pDec -= stride;
    659       if(pbBorderAvail[SGU_TL])
    660       {
    661         x= 0;
    662         edgeType      =  xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    663         pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    664 
    665       }
    666       if(pbBorderAvail[SGU_T])
    667       {
    668         for(x= 1; x< endX; x++)
    669         {
    670           edgeType      =  xSign(pDec[x] - pDec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    671           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    672         }
    673       }
    674       pDec   += stride;
    675       pRest  += stride;
     462      Pel* srcLineAbove= srcLine- srcStride;
     463      firstLineStartX = isAboveLeftAvail ? 0 : 1;
     464      firstLineEndX   = isAboveAvail? endX: 1;
     465      for(x= firstLineStartX; x< firstLineEndX; x++)
     466      {
     467        edgeType  =  m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1];
     468        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     469      }
     470      srcLine  += srcStride;
     471      resLine  += resStride;
    676472
    677473
     
    679475      for (y= 1; y< height-1; y++)
    680476      {
     477        srcLineBelow= srcLine+ srcStride;
     478
    681479        for (x=startX; x<endX; x++)
    682480        {
    683           signDown1      =  xSign(pDec[x] - pDec[x+ posShift]) ;
    684           edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    685           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    686 
    687           m_iUpBufft[x+1] = -signDown1;
     481          signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ;
     482          edgeType =  signDown + signUpLine[x];
     483          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     484
     485          signDownLine[x+1] = -signDown;
    688486        }
    689         m_iUpBufft[startX] = xSign(pDec[stride+startX] - pDec[startX-1]);
    690 
    691         ipSwap     = m_iUpBuff1;
    692         m_iUpBuff1 = m_iUpBufft;
    693         m_iUpBufft = ipSwap;
    694 
    695         pDec  += stride;
    696         pRest += stride;
     487        signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
     488
     489        signTmpLine  = signUpLine;
     490        signUpLine   = signDownLine;
     491        signDownLine = signTmpLine;
     492
     493        srcLine += srcStride;
     494        resLine += resStride;
    697495      }
    698496
    699497      //last line
    700       if(pbBorderAvail[SGU_B])
    701       {
    702         for(x= startX; x< width-1; x++)
    703         {
    704           edgeType =  xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
    705           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    706         }
    707       }
    708       if(pbBorderAvail[SGU_BR])
    709       {
    710         x= width -1;
    711         edgeType =  xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
    712         pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    713       }
    714       break;
    715     }
    716   case SAO_EO_3: // dir: 45
    717     {
    718       Int  posShift     = stride - 1;
    719       startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    720       endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
     498      srcLineBelow= srcLine+ srcStride;
     499      lastLineStartX = isBelowAvail ? startX : (width -1);
     500      lastLineEndX   = isBelowRightAvail ? width : (width -1);
     501      for(x= lastLineStartX; x< lastLineEndX; x++)
     502      {
     503        edgeType =  m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x];
     504        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     505
     506      }
     507    }
     508    break;
     509  case SAO_TYPE_EO_45:
     510    {
     511      offset += 2;
     512      Char *signUpLine = m_signLineBuf1+1;
     513
     514      startX = isLeftAvail ? 0 : 1;
     515      endX   = isRightAvail ? width : (width -1);
    721516
    722517      //prepare 2nd line upper sign
    723       pDec += stride;
     518      Pel* srcLineBelow= srcLine+ srcStride;
    724519      for (x=startX-1; x< endX; x++)
    725520      {
    726         m_iUpBuff1[x] = xSign(pDec[x] - pDec[x- posShift]);
     521        signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
    727522      }
    728523
    729524
    730525      //first line
    731       pDec -= stride;
    732       if(pbBorderAvail[SGU_T])
    733       {
    734         for(x= startX; x< width -1; x++)
    735         {
    736           edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    737           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    738         }
    739       }
    740       if(pbBorderAvail[SGU_TR])
    741       {
    742         x= width-1;
    743         edgeType = xSign(pDec[x] - pDec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    744         pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    745       }
    746       pDec  += stride;
    747       pRest += stride;
     526      Pel* srcLineAbove= srcLine- srcStride;
     527      firstLineStartX = isAboveAvail ? startX : (width -1 );
     528      firstLineEndX   = isAboveRightAvail ? width : (width-1);
     529      for(x= firstLineStartX; x< firstLineEndX; x++)
     530      {
     531        edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1];
     532        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     533      }
     534      srcLine += srcStride;
     535      resLine += resStride;
    748536
    749537      //middle lines
    750538      for (y= 1; y< height-1; y++)
    751539      {
     540        srcLineBelow= srcLine+ srcStride;
     541
    752542        for(x= startX; x< endX; x++)
    753543        {
    754           signDown1      =  xSign(pDec[x] - pDec[x+ posShift]) ;
    755           edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    756 
    757           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    758           m_iUpBuff1[x-1] = -signDown1;
     544          signDown =  (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
     545          edgeType =  signDown + signUpLine[x];
     546          resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     547          signUpLine[x-1] = -signDown;
    759548        }
    760         m_iUpBuff1[endX-1] = xSign(pDec[endX-1 + stride] - pDec[endX]);
    761 
    762         pDec  += stride;
    763         pRest += stride;
     549        signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
     550        srcLine  += srcStride;
     551        resLine += resStride;
    764552      }
    765553
    766554      //last line
    767       if(pbBorderAvail[SGU_BL])
    768       {
    769         x= 0;
    770         edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
    771         pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    772 
    773       }
    774       if(pbBorderAvail[SGU_B])
    775       {
    776         for(x= 1; x< endX; x++)
    777         {
    778           edgeType = xSign(pDec[x] - pDec[x+ posShift]) + m_iUpBuff1[x] + 2;
    779           pRest[x] = pClipTbl[pDec[x] + m_iOffsetEo[edgeType]];
    780         }
    781       }
    782       break;
    783     }   
    784   case SAO_BO:
    785     {
     555      srcLineBelow= srcLine+ srcStride;
     556      lastLineStartX = isBelowLeftAvail ? 0 : 1;
     557      lastLineEndX   = isBelowAvail ? endX : 1;
     558      for(x= lastLineStartX; x< lastLineEndX; x++)
     559      {
     560        edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x];
     561        resLine[x] = offsetClip[srcLine[x] + offset[edgeType]];
     562
     563      }
     564    }
     565    break;
     566  case SAO_TYPE_BO:
     567    {
     568      Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
    786569      for (y=0; y< height; y++)
    787570      {
    788571        for (x=0; x< width; x++)
    789572        {
    790           pRest[x] = pOffsetBo[pDec[x]];
     573          resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ];
    791574        }
    792         pRest += stride;
    793         pDec  += stride;
    794       }
    795       break;
    796     }
    797   default: break;
    798   }
    799 
    800 }
    801 
    802 /** sample adaptive offset process for one LCU crossing LCU boundary
    803  * \param   iAddr, iSaoType, iYCbCr
    804  */
    805 Void TComSampleAdaptiveOffset::processSaoCuOrg(Int iAddr, Int iSaoType, Int iYCbCr)
    806 {
    807   Int x,y;
    808   TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
    809   Pel* pRec;
    810   Int  iStride;
    811   Int  iLcuWidth  = m_uiMaxCUWidth;
    812   Int  iLcuHeight = m_uiMaxCUHeight;
    813   UInt uiLPelX    = pTmpCu->getCUPelX();
    814   UInt uiTPelY    = pTmpCu->getCUPelY();
    815   UInt uiRPelX;
    816   UInt uiBPelY;
    817   Int  iSignLeft;
    818   Int  iSignRight;
    819   Int  iSignDown;
    820   Int  iSignDown1;
    821   Int  iSignDown2;
    822   UInt uiEdgeType;
    823   Int iPicWidthTmp;
    824   Int iPicHeightTmp;
    825   Int iStartX;
    826   Int iStartY;
    827   Int iEndX;
    828   Int iEndY;
    829   Int iIsChroma = (iYCbCr!=0)? 1:0;
    830   Int iShift;
    831   Int iCuHeightTmp;
    832   Pel *pTmpLSwap;
    833   Pel *pTmpL;
    834   Pel *pTmpU;
    835   Pel *pClipTbl = NULL;
    836   Int *pOffsetBo = NULL;
    837 
    838   iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
    839   iPicHeightTmp = m_iPicHeight >> iIsChroma;
    840   iLcuWidth     = iLcuWidth    >> iIsChroma;
    841   iLcuHeight    = iLcuHeight   >> iIsChroma;
    842   uiLPelX       = uiLPelX      >> iIsChroma;
    843   uiTPelY       = uiTPelY      >> iIsChroma;
    844   uiRPelX       = uiLPelX + iLcuWidth  ;
    845   uiBPelY       = uiTPelY + iLcuHeight ;
    846   uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
    847   uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
    848   iLcuWidth     = uiRPelX - uiLPelX;
    849   iLcuHeight    = uiBPelY - uiTPelY;
    850 
    851   if(pTmpCu->getPic()==0)
    852   {
    853     return;
    854   }
    855   if (iYCbCr == 0)
    856   {
    857     pRec       = m_pcPic->getPicYuvRec()->getLumaAddr(iAddr);
    858     iStride    = m_pcPic->getStride();
    859   }
    860   else if (iYCbCr == 1)
    861   {
    862     pRec       = m_pcPic->getPicYuvRec()->getCbAddr(iAddr);
    863     iStride    = m_pcPic->getCStride();
    864   }
    865   else
    866   {
    867     pRec       = m_pcPic->getPicYuvRec()->getCrAddr(iAddr);
    868     iStride    = m_pcPic->getCStride();
    869   }
    870 
    871 //   if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1)
    872   {
    873     iCuHeightTmp = (m_uiMaxCUHeight >> iIsChroma);
    874     iShift = (m_uiMaxCUWidth>> iIsChroma)-1;
    875     for (Int i=0;i<iCuHeightTmp+1;i++)
    876     {
    877       m_pTmpL2[i] = pRec[iShift];
    878       pRec += iStride;
    879     }
    880     pRec -= (iStride*(iCuHeightTmp+1));
    881 
    882     pTmpL = m_pTmpL1;
    883     pTmpU = &(m_pTmpU1[uiLPelX]);
    884   }
    885 
    886   pClipTbl = (iYCbCr==0)? m_pClipTable:m_pChromaClipTable;
    887   pOffsetBo = (iYCbCr==0)? m_iOffsetBo:m_iChromaOffsetBo;
    888 
    889   switch (iSaoType)
    890   {
    891   case SAO_EO_0: // dir: -
    892     {
    893       iStartX = (uiLPelX == 0) ? 1 : 0;
    894       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
    895       for (y=0; y<iLcuHeight; y++)
    896       {
    897         iSignLeft = xSign(pRec[iStartX] - pTmpL[y]);
    898         for (x=iStartX; x< iEndX; x++)
    899         {
    900           iSignRight =  xSign(pRec[x] - pRec[x+1]);
    901           uiEdgeType =  iSignRight + iSignLeft + 2;
    902           iSignLeft  = -iSignRight;
    903 
    904           pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
    905         }
    906         pRec += iStride;
    907       }
    908       break;
    909     }
    910   case SAO_EO_1: // dir: |
    911     {
    912       iStartY = (uiTPelY == 0) ? 1 : 0;
    913       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
    914       if (uiTPelY == 0)
    915       {
    916         pRec += iStride;
    917       }
    918       for (x=0; x< iLcuWidth; x++)
    919       {
    920         m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x]);
    921       }
    922       for (y=iStartY; y<iEndY; y++)
    923       {
    924         for (x=0; x<iLcuWidth; x++)
    925         {
    926           iSignDown  = xSign(pRec[x] - pRec[x+iStride]);
    927           uiEdgeType = iSignDown + m_iUpBuff1[x] + 2;
    928           m_iUpBuff1[x]= -iSignDown;
    929 
    930           pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
    931         }
    932         pRec += iStride;
    933       }
    934       break;
    935     }
    936   case SAO_EO_2: // dir: 135
    937     {
    938       iStartX = (uiLPelX == 0)            ? 1 : 0;
    939       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
    940 
    941       iStartY = (uiTPelY == 0) ?             1 : 0;
    942       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
    943 
    944       if (uiTPelY == 0)
    945       {
    946         pRec += iStride;
    947       }
    948 
    949       for (x=iStartX; x<iEndX; x++)
    950       {
    951         m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x-1]);
    952       }
    953       for (y=iStartY; y<iEndY; y++)
    954       {
    955         iSignDown2 = xSign(pRec[iStride+iStartX] - pTmpL[y]);
    956         for (x=iStartX; x<iEndX; x++)
    957         {
    958           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
    959           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    960           m_iUpBufft[x+1] = -iSignDown1;
    961           pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
    962         }
    963         m_iUpBufft[iStartX] = iSignDown2;
    964 
    965         ipSwap     = m_iUpBuff1;
    966         m_iUpBuff1 = m_iUpBufft;
    967         m_iUpBufft = ipSwap;
    968 
    969         pRec += iStride;
    970       }
    971       break;
    972     }
    973   case SAO_EO_3: // dir: 45
    974     {
    975       iStartX = (uiLPelX == 0) ? 1 : 0;
    976       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth;
    977 
    978       iStartY = (uiTPelY == 0) ? 1 : 0;
    979       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight;
    980 
    981       if (iStartY == 1)
    982       {
    983         pRec += iStride;
    984       }
    985 
    986       for (x=iStartX-1; x<iEndX; x++)
    987       {
    988         m_iUpBuff1[x] = xSign(pRec[x] - pTmpU[x+1]);
    989       }
    990       for (y=iStartY; y<iEndY; y++)
    991       {
    992         x=iStartX;
    993         iSignDown1      =  xSign(pRec[x] - pTmpL[y+1]) ;
    994         uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    995         m_iUpBuff1[x-1] = -iSignDown1;
    996         pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
    997         for (x=iStartX+1; x<iEndX; x++)
    998         {
    999           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
    1000           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    1001           m_iUpBuff1[x-1] = -iSignDown1;
    1002           pRec[x] = pClipTbl[pRec[x] + m_iOffsetEo[uiEdgeType]];
    1003         }
    1004         m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
    1005 
    1006         pRec += iStride;
    1007       }
    1008       break;
    1009     }   
    1010   case SAO_BO:
    1011     {
    1012       for (y=0; y<iLcuHeight; y++)
    1013       {
    1014         for (x=0; x<iLcuWidth; x++)
    1015         {
    1016           pRec[x] = pOffsetBo[pRec[x]];
    1017         }
    1018         pRec += iStride;
    1019       }
    1020       break;
    1021     }
    1022   default: break;
    1023   }
    1024 //   if (iSaoType!=SAO_BO_0 || iSaoType!=SAO_BO_1)
    1025   {
    1026     pTmpLSwap = m_pTmpL1;
    1027     m_pTmpL1  = m_pTmpL2;
    1028     m_pTmpL2  = pTmpLSwap;
    1029   }
    1030 }
    1031 /** Sample adaptive offset process
    1032  * \param pcPic, pcSaoParam 
    1033  */
    1034 Void TComSampleAdaptiveOffset::SAOProcess(SAOParam* pcSaoParam)
    1035 {
    1036   {
    1037     m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0);
    1038     m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0);
    1039 
    1040     if(m_bUseNIF)
    1041     {
    1042       m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
    1043     }
    1044     if (m_saoLcuBasedOptimization)
    1045     {
    1046       pcSaoParam->oneUnitFlag[0] = 0; 
    1047       pcSaoParam->oneUnitFlag[1] = 0; 
    1048       pcSaoParam->oneUnitFlag[2] = 0; 
    1049     }
    1050     Int iY  = 0;
    1051     {
    1052       processSaoUnitAll( pcSaoParam->saoLcuParam[iY], pcSaoParam->oneUnitFlag[iY], iY);
    1053     }
    1054     {
    1055        processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);//Cb
    1056        processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);//Cr
    1057     }
    1058     m_pcPic = NULL;
    1059   }
    1060 }
    1061 
    1062 Pel* TComSampleAdaptiveOffset::getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr, Int iAddr)
    1063 {
    1064   switch (iYCbCr)
    1065   {
    1066   case 0:
    1067     return pcPicYuv->getLumaAddr(iAddr);
    1068     break;
    1069   case 1:
    1070     return pcPicYuv->getCbAddr(iAddr);
    1071     break;
    1072   case 2:
    1073     return pcPicYuv->getCrAddr(iAddr);
     575        srcLine += srcStride;
     576        resLine += resStride;
     577      }
     578    }
    1074579    break;
    1075580  default:
    1076     return NULL;
     581    {
     582      printf("Not a supported SAO types\n");
     583      assert(0);
     584      exit(-1);
     585    }
     586  }
     587
     588
     589}
     590
     591Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic)
     592{
     593  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
     594
     595  if(
     596    (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) &&
     597    (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) &&
     598    (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF)
     599    )
     600  {
     601    return;
     602  }
     603
     604  //block boundary availability
     605  pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     606
     607  Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
     608  Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     609  Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
     610  Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
     611
     612  for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     613  {
     614    SAOOffset& ctbOffset = saoblkParam[compIdx];
     615
     616    if(ctbOffset.modeIdc != SAO_MODE_OFF)
     617    {
     618      Bool isLuma     = (compIdx == SAO_Y);
     619      Int  formatShift= isLuma?0:1;
     620
     621      Int  blkWidth   = (width  >> formatShift);
     622      Int  blkHeight  = (height >> formatShift);
     623      Int  blkYPos    = (yPos   >> formatShift);
     624      Int  blkXPos    = (xPos   >> formatShift);
     625
     626      Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
     627      Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
     628
     629      Int  resStride  = isLuma?resYuv->getStride():resYuv->getCStride();
     630      Pel* resBlk     = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos;
     631
     632      offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset
     633                  , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight
     634                  , isLeftAvail, isRightAvail
     635                  , isAboveAvail, isBelowAvail
     636                  , isAboveLeftAvail, isAboveRightAvail
     637                  , isBelowLeftAvail, isBelowRightAvail
     638                  );
     639    }
     640  } //compIdx
     641
     642}
     643
     644
     645Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic)
     646{
     647  if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr])
     648  {
     649    return;
     650  }
     651  TComPicYuv* resYuv = pDecPic->getPicYuvRec();
     652  TComPicYuv* srcYuv = m_tempPicYuv;
     653  resYuv->copyToPic(srcYuv);
     654  for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
     655  {
     656    offsetCTU(ctu, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic);
     657  } //ctu
     658}
     659
     660
     661Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx)
     662{
     663  Pel* pBuf = NULL;
     664  switch(compIdx)
     665  {
     666  case SAO_Y:
     667    {
     668      pBuf = pPicYuv->getLumaAddr();
     669    }
    1077670    break;
    1078   }
    1079 }
    1080 /** Process SAO all units
    1081  * \param saoLcuParam SAO LCU parameters
    1082  * \param oneUnitFlag one unit flag
    1083  * \param yCbCr color componet index
    1084  */
    1085 Void TComSampleAdaptiveOffset::processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr)
    1086 {
    1087   Pel *pRec;
    1088   Int picWidthTmp;
    1089 
    1090   if (yCbCr == 0)
    1091   {
    1092     pRec        = m_pcPic->getPicYuvRec()->getLumaAddr();
    1093     picWidthTmp = m_iPicWidth;
    1094   }
    1095   else if (yCbCr == 1)
    1096   {
    1097     pRec        = m_pcPic->getPicYuvRec()->getCbAddr();
    1098     picWidthTmp = m_iPicWidth>>1;
    1099   }
    1100   else
    1101   {
    1102     pRec        = m_pcPic->getPicYuvRec()->getCrAddr();
    1103     picWidthTmp = m_iPicWidth>>1;
    1104   }
    1105 
    1106   memcpy(m_pTmpU1, pRec, sizeof(Pel)*picWidthTmp);
    1107 
    1108   Int  i;
    1109   UInt edgeType;
    1110   Pel* ppLumaTable = NULL;
    1111   Pel* pClipTable = NULL;
    1112   Int* pOffsetBo = NULL;
    1113   Int  typeIdx;
    1114 
    1115   Int offset[LUMA_GROUP_NUM+1];
    1116   Int idxX;
    1117   Int idxY;
    1118   Int addr;
    1119   Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
    1120   Int frameHeightInCU = m_pcPic->getFrameHeightInCU();
    1121   Int stride;
    1122   Pel *tmpUSwap;
    1123   Int isChroma = (yCbCr == 0) ? 0:1;
    1124   Bool mergeLeftFlag;
    1125   Int saoBitIncrease = (yCbCr == 0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC;
    1126 
    1127   pOffsetBo = (yCbCr==0) ? m_iOffsetBo : m_iChromaOffsetBo;
    1128 
    1129   offset[0] = 0;
    1130   for (idxY = 0; idxY< frameHeightInCU; idxY++)
    1131   {
    1132     addr = idxY * frameWidthInCU;
    1133     if (yCbCr == 0)
    1134     {
    1135       pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(addr);
    1136       stride = m_pcPic->getStride();
    1137       picWidthTmp = m_iPicWidth;
    1138     }
    1139     else if (yCbCr == 1)
    1140     {
    1141       pRec  = m_pcPic->getPicYuvRec()->getCbAddr(addr);
    1142       stride = m_pcPic->getCStride();
    1143       picWidthTmp = m_iPicWidth>>1;
    1144     }
    1145     else
    1146     {
    1147       pRec  = m_pcPic->getPicYuvRec()->getCrAddr(addr);
    1148       stride = m_pcPic->getCStride();
    1149       picWidthTmp = m_iPicWidth>>1;
    1150     }
    1151 
    1152     //     pRec += iStride*(m_uiMaxCUHeight-1);
    1153     for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++)
    1154     {
    1155       m_pTmpL1[i] = pRec[0];
    1156       pRec+=stride;
    1157     }
    1158     pRec-=(stride<<1);
    1159 
    1160     memcpy(m_pTmpU2, pRec, sizeof(Pel)*picWidthTmp);
    1161 
    1162     for (idxX = 0; idxX < frameWidthInCU; idxX++)
    1163     {
    1164       addr = idxY * frameWidthInCU + idxX;
    1165 
    1166       if (oneUnitFlag)
    1167       {
    1168         typeIdx = saoLcuParam[0].typeIdx;
    1169         mergeLeftFlag = (addr == 0)? 0:1;
    1170       }
    1171       else
    1172       {
    1173         typeIdx = saoLcuParam[addr].typeIdx;
    1174         mergeLeftFlag = saoLcuParam[addr].mergeLeftFlag;
    1175       }
    1176       if (typeIdx>=0)
    1177       {
    1178         if (!mergeLeftFlag)
    1179         {
    1180 
    1181           if (typeIdx == SAO_BO)
    1182           {
    1183             for (i=0; i<SAO_MAX_BO_CLASSES+1;i++)
    1184             {
    1185               offset[i] = 0;
    1186             }
    1187             for (i=0; i<saoLcuParam[addr].length; i++)
    1188             {
    1189               offset[ (saoLcuParam[addr].subTypeIdx +i)%SAO_MAX_BO_CLASSES  +1] = saoLcuParam[addr].offset[i] << saoBitIncrease;
    1190             }
    1191 
    1192             ppLumaTable = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    1193             pClipTable = (yCbCr==0)?m_pClipTable:m_pChromaClipTable;
    1194 
    1195             Int bitDepth = (yCbCr==0) ? g_bitDepthY : g_bitDepthC;
    1196             for (i=0;i<(1<<bitDepth);i++)
    1197             {
    1198               pOffsetBo[i] = pClipTable[i + offset[ppLumaTable[i]]];
    1199             }
    1200 
    1201           }
    1202           if (typeIdx == SAO_EO_0 || typeIdx == SAO_EO_1 || typeIdx == SAO_EO_2 || typeIdx == SAO_EO_3)
    1203           {
    1204             for (i=0;i<saoLcuParam[addr].length;i++)
    1205             {
    1206               offset[i+1] = saoLcuParam[addr].offset[i] << saoBitIncrease;
    1207             }
    1208             for (edgeType=0;edgeType<6;edgeType++)
    1209             {
    1210               m_iOffsetEo[edgeType]= offset[m_auiEoTable[edgeType]];
    1211             }
    1212           }
    1213         }
    1214         processSaoCu(addr, typeIdx, yCbCr);
    1215       }
    1216       else
    1217       {
    1218         if (idxX != (frameWidthInCU-1))
    1219         {
    1220           if (yCbCr == 0)
    1221           {
    1222             pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(addr);
    1223             stride = m_pcPic->getStride();
    1224           }
    1225           else if (yCbCr == 1)
    1226           {
    1227             pRec  = m_pcPic->getPicYuvRec()->getCbAddr(addr);
    1228             stride = m_pcPic->getCStride();
    1229           }
    1230           else
    1231           {
    1232             pRec  = m_pcPic->getPicYuvRec()->getCrAddr(addr);
    1233             stride = m_pcPic->getCStride();
    1234           }
    1235           Int widthShift = m_uiMaxCUWidth>>isChroma;
    1236           for (i=0;i<(m_uiMaxCUHeight>>isChroma)+1;i++)
    1237           {
    1238             m_pTmpL1[i] = pRec[widthShift-1];
    1239             pRec+=stride;
    1240           }
    1241         }
    1242       }
    1243     }
    1244     tmpUSwap = m_pTmpU1;
    1245     m_pTmpU1 = m_pTmpU2;
    1246     m_pTmpU2 = tmpUSwap;
    1247   }
    1248 
    1249 }
    1250 /** Reset SAO LCU part
    1251  * \param saoLcuParam
    1252  */
    1253 Void TComSampleAdaptiveOffset::resetLcuPart(SaoLcuParam* saoLcuParam)
    1254 {
    1255   Int i,j;
    1256   for (i=0;i<m_iNumCuInWidth*m_iNumCuInHeight;i++)
    1257   {
    1258     saoLcuParam[i].mergeUpFlag     =  1;
    1259     saoLcuParam[i].mergeLeftFlag =  0;
    1260     saoLcuParam[i].partIdx   =  0;
    1261     saoLcuParam[i].typeIdx      = -1;
    1262     for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    1263     {
    1264       saoLcuParam[i].offset[j] = 0;
    1265     }
    1266     saoLcuParam[i].subTypeIdx = 0;
    1267   }
    1268 }
    1269 
    1270 /** convert QP part to SAO unit
    1271 * \param saoParam SAO parameter
    1272 * \param partIdx SAO part index
    1273 * \param yCbCr color component index
    1274  */
    1275 Void TComSampleAdaptiveOffset::convertQT2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr)
    1276 {
    1277 
    1278   SAOQTPart*  saoPart= &(saoParam->psSaoPart[yCbCr][partIdx]);
    1279   if (!saoPart->bSplit)
    1280   {
    1281     convertOnePart2SaoUnit(saoParam, partIdx, yCbCr);
    1282     return;
    1283   }
    1284 
    1285   if (saoPart->PartLevel < m_uiMaxSplitLevel)
    1286   {
    1287     convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[0], yCbCr);
    1288     convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[1], yCbCr);
    1289     convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[2], yCbCr);
    1290     convertQT2SaoUnit(saoParam, saoPart->DownPartsIdx[3], yCbCr);
    1291   }
    1292 }
    1293 /** convert one SAO part to SAO unit
    1294 * \param saoParam SAO parameter
    1295 * \param partIdx SAO part index
    1296 * \param yCbCr color component index
    1297  */
    1298 Void TComSampleAdaptiveOffset::convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr)
    1299 {
    1300   Int j;
    1301   Int idxX;
    1302   Int idxY;
    1303   Int addr;
    1304   Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
    1305   SAOQTPart* saoQTPart = saoParam->psSaoPart[yCbCr];
    1306   SaoLcuParam* saoLcuParam = saoParam->saoLcuParam[yCbCr];
    1307 
    1308   for (idxY = saoQTPart[partIdx].StartCUY; idxY<= saoQTPart[partIdx].EndCUY; idxY++)
    1309   {
    1310     for (idxX = saoQTPart[partIdx].StartCUX; idxX<= saoQTPart[partIdx].EndCUX; idxX++)
    1311     {
    1312       addr = idxY * frameWidthInCU + idxX;
    1313       saoLcuParam[addr].partIdxTmp = (Int)partIdx;
    1314       saoLcuParam[addr].typeIdx    = saoQTPart[partIdx].iBestType;
    1315       saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx;
    1316       if (saoLcuParam[addr].typeIdx!=-1)
    1317       {
    1318         saoLcuParam[addr].length    = saoQTPart[partIdx].iLength;
    1319         for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    1320         {
    1321           saoLcuParam[addr].offset[j] = saoQTPart[partIdx].iOffset[j];
    1322         }
    1323       }
    1324       else
    1325       {
    1326         saoLcuParam[addr].length    = 0;
    1327         saoLcuParam[addr].subTypeIdx = saoQTPart[partIdx].subTypeIdx;
    1328         for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    1329         {
    1330           saoLcuParam[addr].offset[j] = 0;
    1331         }
    1332       }
    1333     }
    1334   }
    1335 }
    1336 
    1337 Void TComSampleAdaptiveOffset::resetSaoUnit(SaoLcuParam* saoUnit)
    1338 {
    1339   saoUnit->partIdx       = 0;
    1340   saoUnit->partIdxTmp    = 0;
    1341   saoUnit->mergeLeftFlag = 0;
    1342   saoUnit->mergeUpFlag   = 0;
    1343   saoUnit->typeIdx       = -1;
    1344   saoUnit->length        = 0;
    1345   saoUnit->subTypeIdx    = 0;
    1346 
    1347   for (Int i=0;i<4;i++)
    1348   {
    1349     saoUnit->offset[i] = 0;
    1350   }
    1351 }
    1352 
    1353 Void TComSampleAdaptiveOffset::copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc )
    1354 {
    1355   saoUnitDst->mergeLeftFlag = saoUnitSrc->mergeLeftFlag;
    1356   saoUnitDst->mergeUpFlag   = saoUnitSrc->mergeUpFlag;
    1357   saoUnitDst->typeIdx       = saoUnitSrc->typeIdx;
    1358   saoUnitDst->length        = saoUnitSrc->length;
    1359 
    1360   saoUnitDst->subTypeIdx  = saoUnitSrc->subTypeIdx;
    1361   for (Int i=0;i<4;i++)
    1362   {
    1363     saoUnitDst->offset[i] = saoUnitSrc->offset[i];
    1364   }
    1365 }
    1366 
    1367 /** PCM LF disable process.
     671  case SAO_Cb:
     672    {
     673      pBuf = pPicYuv->getCbAddr();
     674    }
     675    break;
     676  case SAO_Cr:
     677    {
     678      pBuf = pPicYuv->getCrAddr();
     679    }
     680    break;
     681  default:
     682    {
     683      printf("Not a legal component ID for SAO\n");
     684      assert(0);
     685      exit(-1);
     686    }
     687  }
     688
     689  return pBuf;
     690}
     691
     692/** PCM LF disable process.
    1368693 * \param pcPic picture (TComPic) pointer
    1369694 * \returns Void
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h

    r608 r872  
    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 *
     
    4949// ====================================================================================================================
    5050
    51 #define SAO_MAX_DEPTH                 4
    52 #define SAO_BO_BITS                   5
    53 #define LUMA_GROUP_NUM                (1<<SAO_BO_BITS)
    54 #define MAX_NUM_SAO_OFFSETS           4
    55 #define MAX_NUM_SAO_CLASS             33
     51#define MAX_SAO_TRUNCATED_BITDEPTH     10
    5652// ====================================================================================================================
    5753// Class definition
    5854// ====================================================================================================================
     55extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS];
    5956
    60 /// Sample Adaptive Offset class
    6157class TComSampleAdaptiveOffset
    6258{
     59public:
     60  TComSampleAdaptiveOffset();
     61  virtual ~TComSampleAdaptiveOffset();
     62  Void SAOProcess(TComPic* pDecPic);
     63  Void create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth );
     64  Void destroy();
     65  Void reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams);
     66  Void PCMLFDisableProcess (TComPic* pcPic);
    6367protected:
    64   TComPic*          m_pcPic;
     68  Void offsetBlock(Int compIdx, Int typeIdx, Int* offset, Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride,  Int width, Int height
     69                  , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail);
     70  Pel* getPicBuf(TComPicYuv* pPicYuv, Int compIdx);
     71  Void invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets);
     72  Void reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList);
     73  Int  getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList);
     74  Void offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic);
     75  Void xPCMRestoration(TComPic* pcPic);
     76  Void xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth );
     77  Void xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
     78protected:
     79  UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step 
     80  Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation
     81  Short* m_sign; //sign table for fast operation
     82  TComPicYuv*   m_tempPicYuv; //temporary buffer
     83  Int m_picWidth;
     84  Int m_picHeight;
     85  Int m_maxCUWidth;
     86  Int m_maxCUHeight;
     87  Int m_numCTUInWidth;
     88  Int m_numCTUInHeight;
     89  Int m_numCTUsPic;
     90 
     91 
     92  Int m_lineBufWidth;
     93  Char* m_signLineBuf1;
     94  Char* m_signLineBuf2;
     95private:
     96  Bool m_picSAOEnabled[NUM_SAO_COMPONENTS];
     97  Int*   m_offsetClipTable[NUM_SAO_COMPONENTS];
     98  Short* m_signTable;
    6599
    66   static const UInt m_uiMaxDepth;
    67   static const Int m_aiNumCulPartsLevel[5];
    68   static const UInt m_auiEoTable[9];
    69   Int *m_iOffsetBo;
    70   Int *m_iChromaOffsetBo;
    71   Int m_iOffsetEo[LUMA_GROUP_NUM];
    72 
    73   Int  m_iPicWidth;
    74   Int  m_iPicHeight;
    75   UInt m_uiMaxSplitLevel;
    76   UInt m_uiMaxCUWidth;
    77   UInt m_uiMaxCUHeight;
    78   Int  m_iNumCuInWidth;
    79   Int  m_iNumCuInHeight;
    80   Int  m_iNumTotalParts;
    81   static const Int m_iNumClass[MAX_NUM_SAO_TYPE];
    82 
    83   UInt m_uiSaoBitIncreaseY;
    84   UInt m_uiSaoBitIncreaseC;  //for chroma
    85   UInt m_uiQP;
    86 
    87   Pel   *m_pClipTable;
    88   Pel   *m_pClipTableBase;
    89   Pel   *m_lumaTableBo;
    90   Pel   *m_pChromaClipTable;
    91   Pel   *m_pChromaClipTableBase;
    92   Pel   *m_chromaTableBo;
    93   Int   *m_iUpBuff1;
    94   Int   *m_iUpBuff2;
    95   Int   *m_iUpBufft;
    96   Int   *ipSwap;
    97   Bool  m_bUseNIF;       //!< true for performing non-cross slice boundary ALF
    98   TComPicYuv* m_pcYuvTmp;    //!< temporary picture buffer pointer when non-across slice/tile boundary SAO is enabled
    99 
    100   Pel* m_pTmpU1;
    101   Pel* m_pTmpU2;
    102   Pel* m_pTmpL1;
    103   Pel* m_pTmpL2;
    104   Int     m_maxNumOffsetsPerPic;
    105   Bool    m_saoLcuBoundary;
    106   Bool    m_saoLcuBasedOptimization;
    107 
    108   Void xPCMRestoration        (TComPic* pcPic);
    109   Void xPCMCURestoration      (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth);
    110   Void xPCMSampleRestoration  (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText);
    111 public:
    112   TComSampleAdaptiveOffset         ();
    113   virtual ~TComSampleAdaptiveOffset();
    114 
    115   Void create( UInt uiSourceWidth, UInt uiSourceHeight, UInt uiMaxCUWidth, UInt uiMaxCUHeight );
    116   Void destroy ();
    117 
    118   Int  convertLevelRowCol2Idx(Int level, Int row, Int col);
    119 
    120   Void initSAOParam   (SAOParam *pcSaoParam, Int iPartLevel, Int iPartRow, Int iPartCol, Int iParentPartIdx, Int StartCUX, Int EndCUX, Int StartCUY, Int EndCUY, Int iYCbCr);
    121   Void allocSaoParam  (SAOParam* pcSaoParam);
    122   Void resetSAOParam  (SAOParam *pcSaoParam);
    123   static Void freeSaoParam   (SAOParam *pcSaoParam);
    124  
    125   Void SAOProcess(SAOParam* pcSaoParam);
    126   Void processSaoCu(Int iAddr, Int iSaoType, Int iYCbCr);
    127   Pel* getPicYuvAddr(TComPicYuv* pcPicYuv, Int iYCbCr,Int iAddr = 0);
    128 
    129   Void processSaoCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);  //!< LCU-basd SAO process without slice granularity
    130   Void createPicSaoInfo(TComPic* pcPic);
    131   Void destroyPicSaoInfo();
    132   Void processSaoBlock(Pel* pDec, Pel* pRest, Int stride, Int iSaoType, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);
    133 
    134   Void resetLcuPart(SaoLcuParam* saoLcuParam);
    135   Void convertQT2SaoUnit(SAOParam* saoParam, UInt partIdx, Int yCbCr);
    136   Void convertOnePart2SaoUnit(SAOParam *saoParam, UInt partIdx, Int yCbCr);
    137   Void processSaoUnitAll(SaoLcuParam* saoLcuParam, Bool oneUnitFlag, Int yCbCr);
    138   Void setSaoLcuBoundary (Bool bVal)  {m_saoLcuBoundary = bVal;}
    139   Bool getSaoLcuBoundary ()           {return m_saoLcuBoundary;}
    140   Void setSaoLcuBasedOptimization (Bool bVal)  {m_saoLcuBasedOptimization = bVal;}
    141   Bool getSaoLcuBasedOptimization ()           {return m_saoLcuBasedOptimization;}
    142   Void resetSaoUnit(SaoLcuParam* saoUnit);
    143   Void copySaoUnit(SaoLcuParam* saoUnitDst, SaoLcuParam* saoUnitSrc );
    144   Void PCMLFDisableProcess    ( TComPic* pcPic);                        ///< interface function for ALF process
    145100};
    146101
  • trunk/source/Lib/TLibCommon/TComSlice.cpp

    r833 r872  
    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 *
     
    7171, m_colFromL0Flag                 ( 1 )
    7272, m_colRefIdx                     ( 0 )
    73 #if SAO_CHROMA_LAMBDA
    74 , m_dLambdaLuma( 0.0 )
    75 , m_dLambdaChroma( 0.0 )
    76 #else
    77 , m_dLambda                       ( 0.0 )
    78 #endif
    7973, m_uiTLayer                      ( 0 )
    8074, m_bTLayerSwitchingFlag          ( false )
     
    109103, m_isDepth                       (false)
    110104#endif
     105#if !H_MV_HLS7_GEN
    111106, m_pocResetFlag                  (false)
     107#endif
    112108#if H_MV
    113109, m_crossLayerBlaFlag             (false)
     
    116112, m_interLayerPredEnabledFlag     (false)
    117113, m_numInterLayerRefPicsMinus1    (0)
     114#if H_MV_HLS_7_POC_P0041
     115, m_sliceSegmentHeaderExtensionLength (0)
     116, m_pocResetIdc                       (0)
     117, m_pocResetPeriodId                  (0)
     118, m_fullPocResetFlag                  (false)
     119, m_pocLsbVal                         (0)
     120, m_pocMsbValPresentFlag              (false)
     121, m_pocMsbVal                         (0)
     122, m_pocMsbValRequiredFlag         ( false )
     123#endif
    118124#if H_3D_IC
    119125, m_bApplyIC                      ( false )
     
    129135 
    130136  initEqualRef();
     137 
     138  for (Int component = 0; component < 3; component++)
     139  {
     140    m_lambdas[component] = 0.0;
     141  }
    131142 
    132143  for ( Int idx = 0; idx < MAX_NUM_REF; idx++ )
     
    148159  initWpAcDcParam();
    149160  m_saoEnabledFlag = false;
     161  m_saoEnabledFlagChroma = false;
    150162#if H_MV
    151163  for (Int i = 0; i < MAX_NUM_LAYERS; i++ )
     
    370382  }
    371383}
     384
    372385#if !H_MV
    373 #if FIX1071
    374386Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr )
    375 #else
    376 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic )
    377 #endif
    378 {
    379 #if FIX1071
     387{
    380388  if (!checkNumPocTotalCurr)
    381 #endif
    382389  {
    383390    if (m_eSliceType == I_SLICE)
     
    449456  TComPic*  rpsCurrList1[MAX_NUM_REF+1];
    450457  Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr;
    451 
    452 #if FIX1071
    453458  if (checkNumPocTotalCurr)
    454459  {
     
    474479    m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1);
    475480  }
    476 #endif
    477481
    478482  Int cIdx = 0;
     
    873877{
    874878  TComPic*                 rpcPic;
     879#if !FIX1172
    875880  setAssociatedIRAPPOC(pocCRA);
     881#endif
    876882  Int pocCurr = getPOC();
    877883
     
    993999  m_colFromL0Flag        = pSrc->m_colFromL0Flag;
    9941000  m_colRefIdx            = pSrc->m_colRefIdx;
    995 #if SAO_CHROMA_LAMBDA
    996   m_dLambdaLuma          = pSrc->m_dLambdaLuma;
    997   m_dLambdaChroma        = pSrc->m_dLambdaChroma;
    998 #else
    999   m_dLambda              = pSrc->m_dLambda;
    1000 #endif
     1001  setLambdas(pSrc->getLambdas());
    10011002  for (i = 0; i < 2; i++)
    10021003  {
     
    10431044#if H_MV
    10441045  // Additional slice header syntax elements
     1046#if !H_MV_HLS7_GEN
    10451047  m_pocResetFlag               = pSrc->m_pocResetFlag;
     1048#endif
    10461049  m_discardableFlag            = pSrc->m_discardableFlag;
    10471050  m_interLayerPredEnabledFlag  = pSrc->m_interLayerPredEnabledFlag;
     
    11771180  {
    11781181    rpcPic = *(iterPic++);
     1182#if BUGFIX_INTRAPERIOD
     1183    if(!rpcPic->getReconMark())
     1184    {
     1185      continue;
     1186    }
     1187#endif
    11791188    if (rpcPic->getPOC() == this->getPOC())
    11801189    {
     
    13311340
    13321341    }
     1342#if H_MV_HLS_7_MISC_P0130_20
     1343    if( isReference ) // Current picture is in the temporal RPS
     1344    {
     1345      assert( rpcPic->getSlice(0)->getDiscardableFlag() == 0 ); // Temporal RPS shall not contain picture with discardable_flag equal to 1
     1346    }
     1347#endif
    13331348    // mark the picture as "unused for reference" if it is not in
    13341349    // the Reference Picture Set
     
    13421357    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
    13431358    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
    1344     if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     1359    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
    13451360    {
    13461361      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
     
    15011516/** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set
    15021517*/
    1503 #if FIX1071
    15041518Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP)
    1505 #else
    1506 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)
    1507 #endif
    15081519{
    15091520  TComPic* rpcPic;
     
    15301541        // and should be added to the explicit Reference Picture Set
    15311542        pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i));
    1532 #if FIX1071
    15331543        pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP));
    1534 #else
    1535         pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));
    1536 #endif
    15371544        if(pcRPS->getDeltaPOC(k) < 0)
    15381545        {
     
    17201727    }
    17211728  }
    1722 
     1729#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    17231730  m_vpsNumberLayerSetsMinus1     = -1;
     1731#endif
    17241732  m_vpsNumProfileTierLevelMinus1 = -1;
    17251733   
     1734#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    17261735  for ( Int i = 0; i < MAX_VPS_PROFILE_TIER_LEVEL; i++)
    17271736  {
     1737#if !H_MV_HLS_7_VPS_P0048_14
    17281738    m_profileRefMinus1[ i ] = -1;
     1739#endif
    17291740  }
    17301741   
     
    17321743  m_numAddOutputLayerSetsMinus1        = -1;   
    17331744  m_defaultOneTargetOutputLayerIdc     = 0;
     1745#else
     1746  m_numAddOutputLayerSets              = -1;   
     1747  m_defaultTargetOutputLayerIdc     = 0;
     1748#endif
    17341749 
    17351750  for ( Int i = 0; i < MAX_VPS_OUTPUTLAYER_SETS; i++)
     
    17411756      m_outputLayerFlag[i][j] = false;
    17421757    }
    1743   }
     1758#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1759    m_altOutputLayerFlag[ i ]       = false;
     1760#endif
     1761  }
     1762#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    17441763  m_altOutputLayerFlag       = false;
     1764#endif
    17451765  m_maxOneActiveRefLayerFlag = false;
    17461766  m_directDepTypeLenMinus2   = 0;         
     
    17481768
    17491769  m_avcBaseLayerFlag = false;
     1770#if H_MV_HLS_7_VPS_P0307_23
     1771  m_vpsNonVuiExtensionLength = 0;
     1772#else
    17501773  m_vpsVuiOffset     = 0;
     1774#endif
    17511775  m_splittingFlag    = false;
    17521776 
     
    17621786  {
    17631787    m_vpsProfilePresentFlag   [i] = false;
     1788#if !H_MV_HLS_7_VPS_P0048_14
    17641789    m_profileRefMinus1[i] = 0;
     1790#endif
    17651791    m_outputLayerSetIdxMinus1       [i] = 0;
    17661792    for( Int j = 0; j < MAX_VPS_NUH_LAYER_ID_PLUS1; j++ )
     
    19551981  for ( i = 0; i < iNumViews ; i++ )
    19561982  {
     1983    m_bCamParInSliceHeader[i] = false;
    19571984    m_aaaiCodedScale[i] = new Int*[ 2 ];
    19581985    m_aaaiCodedOffset[i] = new Int*[ 2 ];
     
    20722099Int    TComVPS::getNumOutputLayerSets()
    20732100{
     2101#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     2102  return getNumAddOutputLayerSets() + getVpsNumLayerSetsMinus1() + 1;
     2103#else
    20742104  Int numOutputLayerSets = getVpsNumberLayerSetsMinus1( ) + 1;
    20752105  if ( getMoreOutputLayerSetsThanDefaultFlag( ) )
     
    20782108}
    20792109  return numOutputLayerSets;
     2110#endif
    20802111}
    20812112
     
    21252156}
    21262157
    2127 Void TComVPS::deriveTargetLayerIdLists()
     2158#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     2159Void TComVPS::initTargetLayerIdLists()
    21282160{
    21292161  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() );
    21302162  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() );
     2163}
     2164
     2165Void TComVPS::deriveTargetLayerIdList( Int i )
     2166
     2167  Int lsIdx = getLayerSetIdxForOutputLayerSet( i );     
     2168 
     2169  for( Int j = 0; j < getNumLayersInIdList( lsIdx ); j++ )
     2170  {
     2171    m_targetDecLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
     2172    if( getOutputLayerFlag( i, j  ))
     2173    {
     2174      m_targetOptLayerIdLists[i].push_back( m_layerSetLayerIdList[ lsIdx ][ j ] );
     2175    }
     2176  } 
     2177}
     2178#else
     2179Void TComVPS::deriveTargetLayerIdLists()
     2180{
     2181  m_targetDecLayerIdLists.resize( getNumOutputLayerSets() );
     2182  m_targetOptLayerIdLists.resize( getNumOutputLayerSets() );
    21312183
    21322184  for (Int targetOptLayerSetIdx = 0; targetOptLayerSetIdx < getNumOutputLayerSets(); targetOptLayerSetIdx++ )
     
    21452197  }
    21462198}
     2199#endif
     2200
    21472201#endif // H_MV
    21482202
     
    21812235, m_qpBDOffsetY               (  0)
    21822236, m_qpBDOffsetC               (  0)
    2183 , m_useLossless               (false)
    21842237, m_uiPCMBitDepthLuma         (  8)
    21852238, m_uiPCMBitDepthChroma       (  8)
     
    23922445, m_ppsInferScalingListFlag(false)
    23932446, m_ppsScalingListRefLayerId(0)
     2447#if H_MV_HLS_7_POC_P0041
     2448, m_pocResetInfoPresentFlag(false)
     2449#endif
    23942450#if H_3D
    23952451, m_pcDLT(NULL)
     
    23982454{
    23992455  m_scalingList = new TComScalingList;
     2456
     2457#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION 
     2458  for( Int i = 0; i < PS_EX_T_MAX_NUM; i++ )
     2459  {
     2460    m_ppsExtensionTypeFlag[ i ] = false;
     2461  }
     2462#endif
     2463
    24002464}
    24012465
     
    28612925    for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++)
    28622926    {
    2863       getScalingList()->processDefaultMarix(sizeId, listId);
     2927      getScalingList()->processDefaultMatrix(sizeId, listId);
    28642928    }
    28652929  }
     
    28962960    Int layerIdRef = getRefPicLayerId( i );
    28972961    TComPic* picRef = ivPicLists->getPic( layerIdRef, getPOC() ) ;
    2898     assert ( picRef != 0 );
     2962    assert ( picRef != 0 ); // There shall be no entry equal to "no reference picture" in RefPicSetInterLayer0 or RefPicSetInterLayer1.
    28992963
    29002964    picRef->getPicYuvRec()->extendPicBorder();
     
    29162980    // Consider to check here:
    29172981    // "If the current picture is a RADL picture, there shall be no entry in the RefPicSetInterLayer0 and RefPicSetInterLayer1 that is a RASL picture. "   
     2982#if H_MV_HLS_7_MISC_P0130_20
     2983    assert( picRef->getSlice(0)->getDiscardableFlag() == false ); // "There shall be no picture that has discardable_flag equal to 1 in RefPicSetInterLayer0 or RefPicSetInterLayer1".       
     2984#endif
    29182985  }
    29192986}
     
    30903157  Int numActiveRefLayerPics;
    30913158
     3159#if H_MV_HLS_7_MISC_P0079_18
     3160  if( getLayerId() == 0 || getNumRefLayerPics() ==  0 )
     3161#else
    30923162  if( getLayerId() == 0 || getVPS()->getNumDirectRefLayers( getLayerId() ) ==  0 )
     3163#endif
    30933164  {
    30943165    numActiveRefLayerPics = 0;
     
    31043175  else if( getVPS()->getMaxOneActiveRefLayerFlag() || getVPS()->getNumDirectRefLayers( getLayerId() ) == 1 )
    31053176  {
     3177#if H_MV_HLS_7_MISC_P0079_18
     3178    numActiveRefLayerPics = 1;
     3179#else
    31063180    numActiveRefLayerPics = getRefLayerPicFlag( 0 ) ? 1 : 0;
     3181#endif
    31073182  }
    31083183  else
     
    35843659 * \param Index of input matrix
    35853660 */
    3586 Void TComScalingList::processDefaultMarix(UInt sizeId, UInt listId)
     3661Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId)
    35873662{
    35883663  ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]));
     
    36013676      if(getScalingListDC(sizeId,listId) == 0)
    36023677      {
    3603         processDefaultMarix(sizeId, listId);
     3678        processDefaultMatrix(sizeId, listId);
    36043679      }
    36053680    }
     
    37623837{
    37633838  m_crossLayerIrapAlignedFlag = true;
     3839#if H_MV_HLS_7_MISC_P0068_21
     3840  m_allLayersIdrAlignedFlag   = false;
     3841#endif
    37643842  m_bitRatePresentVpsFlag = false;
    37653843  m_picRatePresentVpsFlag = false;
     
    37883866      m_minHorizontalCtuOffsetPlus1 [i][j] = -1;
    37893867    }
     3868#if H_MV_HLS_7_MISC_P0182_13
     3869    m_baseLayerParameterSetCompatibilityFlag[i] = false;
     3870#endif
    37903871  }
    37913872  for ( Int i = 0; i < MAX_NUM_VIDEO_SIGNAL_INFO; i++ )
  • trunk/source/Lib/TLibCommon/TComSlice.h

    r833 r872  
    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 *
     
    161161  UInt     getRefMatrixId                 (UInt sizeId, UInt listId)           { return m_refMatrixId[sizeId][listId]; }     //!< get reference matrix ID
    162162  Int*     getScalingListDefaultAddress   (UInt sizeId, UInt listId);                                                        //!< get default matrix coefficient
    163   Void     processDefaultMarix            (UInt sizeId, UInt listId);
     163  Void     processDefaultMatrix            (UInt sizeId, UInt listId);
    164164  Void     setScalingListDC               (UInt sizeId, UInt listId, UInt u)   { m_scalingListDC[sizeId][listId] = u; }      //!< set DC value
    165165
     
    473473  Bool m_crossLayerPicTypeAlignedFlag;
    474474  Bool m_crossLayerIrapAlignedFlag;
     475#if H_MV_HLS_7_MISC_P0068_21
     476  Bool m_allLayersIdrAlignedFlag;
     477#endif
    475478  Bool m_bitRatePresentVpsFlag;
    476479  Bool m_picRatePresentVpsFlag;
     
    481484  Int  m_constantPicRateIdc          [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
    482485  Int  m_avgPicRate                  [MAX_VPS_OP_SETS_PLUS1][MAX_TLAYER];
     486#if H_MV_HLS_7_VPS_P0076_15
     487  Bool m_videoSignalInfoIdxPresentFlag;
     488  Int  m_vpsNumVideoSignalInfoMinus1;
     489  TComVideoSignalInfo* m_videoSignalInfo[MAX_NUM_VIDEO_SIGNAL_INFO];   
     490  Int  m_vpsVideoSignalInfoIdx       [MAX_NUM_VIDEO_SIGNAL_INFO];
     491#endif
    483492  Bool m_tilesNotInUseFlag;
    484493  Bool m_tilesInUseFlag              [MAX_NUM_LAYERS];
     
    491500  Bool m_ctuBasedOffsetEnabledFlag   [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
    492501  Int  m_minHorizontalCtuOffsetPlus1 [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
     502#if !H_MV_HLS_7_VPS_P0076_15
    493503  Bool m_videoSignalInfoIdxPresentFlag;
    494504  Int  m_vpsNumVideoSignalInfoMinus1;
    495505  TComVideoSignalInfo* m_videoSignalInfo[MAX_NUM_VIDEO_SIGNAL_INFO];   
    496506  Int  m_vpsVideoSignalInfoIdx       [MAX_NUM_VIDEO_SIGNAL_INFO];
     507#endif
    497508  Bool m_vpsVuiBspHrdPresentFlag;
    498509  TComVpsVuiBspHrdParameters* m_vpsVuiBspHrdParameters;
     510#if H_MV_HLS_7_MISC_P0182_13
     511  Bool m_baseLayerParameterSetCompatibilityFlag[MAX_NUM_LAYERS];
     512#endif
    499513
    500514public:
     
    507521  Bool getCrossLayerIrapAlignedFlag(  ) { return m_crossLayerIrapAlignedFlag; }
    508522
     523#if H_MV_HLS_7_MISC_P0068_21
     524  Void setAllLayersIdrAlignedFlag( Bool flag ) { m_allLayersIdrAlignedFlag = flag; }
     525  Bool getAllLayersIdrAlignedFlag(  ) { return m_allLayersIdrAlignedFlag; }
     526#endif
     527
    509528  Void setBitRatePresentVpsFlag( Bool flag ) { m_bitRatePresentVpsFlag = flag; }
    510529  Bool getBitRatePresentVpsFlag(  ) { return m_bitRatePresentVpsFlag; }
     
    531550  Int  getAvgPicRate( Int i, Int j ) { return m_avgPicRate[i][j]; }
    532551
     552#if H_MV_HLS_7_VPS_P0076_15
     553  Void setVideoSignalInfoIdxPresentFlag( Bool flag ) { m_videoSignalInfoIdxPresentFlag = flag; }
     554  Bool getVideoSignalInfoIdxPresentFlag(  ) { return m_videoSignalInfoIdxPresentFlag; }
     555
     556  Void    setVideoSignalInfo( Int i, TComVideoSignalInfo* val )                        { m_videoSignalInfo[i] = val;  } 
     557  TComVideoSignalInfo* getVideoSignalInfo( Int i )                                     { return m_videoSignalInfo[i]; }
     558
     559  Void setVpsNumVideoSignalInfoMinus1( Int  val ) { m_vpsNumVideoSignalInfoMinus1 = val; }
     560  Int  getVpsNumVideoSignalInfoMinus1(  ) { return m_vpsNumVideoSignalInfoMinus1; }
     561
     562  Void setVpsVideoSignalInfoIdx( Int i, Int  val ) { m_vpsVideoSignalInfoIdx[i] = val; }
     563  Int  getVpsVideoSignalInfoIdx( Int i ) { return m_vpsVideoSignalInfoIdx[i]; }
     564#endif
     565
    533566  Void setTilesNotInUseFlag( Bool flag ) { m_tilesNotInUseFlag = flag; }
    534567  Bool getTilesNotInUseFlag(  ) { return m_tilesNotInUseFlag; }
     
    560593  Void setMinHorizontalCtuOffsetPlus1( Int i, Int j, Int  val ) { m_minHorizontalCtuOffsetPlus1[i][j] = val; }
    561594  Int  getMinHorizontalCtuOffsetPlus1( Int i, Int j ) { return m_minHorizontalCtuOffsetPlus1[i][j]; }
    562 
     595#if !H_MV_HLS_7_VPS_P0076_15
    563596  Void setVideoSignalInfoIdxPresentFlag( Bool flag ) { m_videoSignalInfoIdxPresentFlag = flag; }
    564597  Bool getVideoSignalInfoIdxPresentFlag(  ) { return m_videoSignalInfoIdxPresentFlag; }
     
    572605  Void setVpsVideoSignalInfoIdx( Int i, Int  val ) { m_vpsVideoSignalInfoIdx[i] = val; }
    573606  Int  getVpsVideoSignalInfoIdx( Int i ) { return m_vpsVideoSignalInfoIdx[i]; }
    574 
     607#endif
    575608  Void setVpsVuiBspHrdPresentFlag( Bool flag ) { m_vpsVuiBspHrdPresentFlag = flag; }
    576609  Bool getVpsVuiBspHrdPresentFlag(  ) { return m_vpsVuiBspHrdPresentFlag; }
     
    578611  Void setVpsVuiBspHrdParameters( TComVpsVuiBspHrdParameters* val) {  m_vpsVuiBspHrdParameters = val; }
    579612  TComVpsVuiBspHrdParameters* getVpsVuiBspHrdParameters(  ) { return m_vpsVuiBspHrdParameters; }
     613
     614#if H_MV_HLS_7_MISC_P0182_13
     615  Void setBaseLayerParameterSetCompatibilityFlag( Int i, Bool flag ) { m_baseLayerParameterSetCompatibilityFlag[i] = flag; }
     616  Bool getBaseLayerParameterSetCompatibilityFlag( Int i ) { return m_baseLayerParameterSetCompatibilityFlag[i]; }
     617#endif
     618
     619#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
     620  Void inferVpsVui( Bool encoderFlag )
     621  {
     622    // inference of syntax elements that differ from default inference (as done in constructor), when VPS VUI is not present
     623    if (!encoderFlag )
     624    {
     625      setCrossLayerIrapAlignedFlag( false );
     626    }
     627    else
     628    {
     629      assert( !getCrossLayerIrapAlignedFlag() );
     630    }
     631
     632  }
     633#endif
    580634};
    581635
     
    626680  Int   m_maxVpsDecPicBufferingMinus1[MAX_VPS_OUTPUTLAYER_SETS][MAX_NUM_LAYER_IDS][MAX_TLAYER];;
    627681  Int   m_maxVpsNumReorderPics       [MAX_VPS_OUTPUTLAYER_SETS][MAX_TLAYER];
     682#if H_MV_HLS7_GEN
     683  Int  m_maxVpsLayerDecPicBuffMinus1[TO_BE_SPECIFIED][TO_BE_SPECIFIED][TO_BE_SPECIFIED];
     684#endif
    628685  Int   m_maxVpsLatencyIncreasePlus1 [MAX_VPS_OUTPUTLAYER_SETS][MAX_TLAYER];
    629686
     
    660717  Void setMaxVpsNumReorderPics( Int i, Int j, Int  val ) { m_maxVpsNumReorderPics[i][j] = val; }
    661718  Int  getMaxVpsNumReorderPics( Int i, Int j ) { return m_maxVpsNumReorderPics[i][j]; }
    662 
     719#if H_MV_HLS7_GEN
     720  Void setMaxVpsLayerDecPicBuffMinus1( Int i, Int k, Int j, Int  val ) { m_maxVpsLayerDecPicBuffMinus1[i][k][j] = val; }
     721  Int  getMaxVpsLayerDecPicBuffMinus1( Int i, Int k, Int j ) { return m_maxVpsLayerDecPicBuffMinus1[i][k][j]; }
     722#endif
    663723  Void setMaxVpsLatencyIncreasePlus1( Int i, Int j, Int  val ) { m_maxVpsLatencyIncreasePlus1[i][j] = val; }
    664724  Int  getMaxVpsLatencyIncreasePlus1( Int i, Int j ) { return m_maxVpsLatencyIncreasePlus1[i][j]; }
     
    708768  /// VPS EXTENSION SYNTAX ELEMENTS
    709769  Bool        m_avcBaseLayerFlag;
     770#if H_MV_HLS_7_VPS_P0307_23
     771  Int         m_vpsNonVuiExtensionLength;
     772#else
    710773  Int         m_vpsVuiOffset;
     774#endif
    711775  Bool        m_splittingFlag;
    712776  Bool        m_scalabilityMaskFlag          [MAX_NUM_SCALABILITY_TYPES];
     
    724788  Int         m_maxTidIlRefPicsPlus1     [MAX_NUM_LAYERS][MAX_NUM_LAYERS];
    725789  Bool        m_allRefLayersActiveFlag;
     790#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    726791  Int         m_vpsNumberLayerSetsMinus1;
     792#endif
    727793  Int         m_vpsNumProfileTierLevelMinus1;   
    728794  Bool        m_vpsProfilePresentFlag    [MAX_VPS_OP_SETS_PLUS1];
     795
     796#if !H_MV_HLS_7_VPS_P0048_14
    729797  Int         m_profileRefMinus1         [MAX_VPS_PROFILE_TIER_LEVEL];
     798#endif
     799#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     800  Int         m_numAddOutputLayerSets;   
     801  Int         m_defaultTargetOutputLayerIdc;
     802#else 
    730803  Bool        m_moreOutputLayerSetsThanDefaultFlag;
    731804  Int         m_numAddOutputLayerSetsMinus1;   
    732805  Int         m_defaultOneTargetOutputLayerIdc;
     806#endif
     807
    733808  Int         m_outputLayerSetIdxMinus1  [MAX_VPS_OUTPUTLAYER_SETS]; 
    734809  Bool        m_outputLayerFlag          [MAX_VPS_OUTPUTLAYER_SETS][MAX_VPS_NUH_LAYER_ID_PLUS1];
    735810  Int         m_profileLevelTierIdx      [MAX_VPS_OUTPUTLAYER_SETS ];
     811#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     812  Bool        m_altOutputLayerFlag       [MAX_VPS_OUTPUTLAYER_SETS];
     813#else
    736814  Bool        m_altOutputLayerFlag;
     815#endif
    737816  Bool        m_repFormatIdxPresentFlag;
    738817  Int         m_vpsNumRepFormatsMinus1;
     
    740819  TComRepFormat* m_repFormat             [MAX_NUM_LAYERS];
    741820  Bool        m_maxOneActiveRefLayerFlag;       
     821#if H_MV_HLS7_GEN
     822  Bool        m_vpsPocLsbAlignedFlag;
     823#endif
    742824  Bool        m_pocLsbNotPresentFlag     [MAX_NUM_LAYERS];
    743825
     
    746828  Bool        m_defaultDirectDependencyFlag;
    747829  Int         m_defaultDirectDependencyType;
     830 
     831#if H_MV_HLS7_GEN
     832  Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
     833#endif
    748834  Bool        m_vpsVuiPresentFlag;
    749835  TComVPSVUI* m_vpsVUI;
     836#if !H_MV_HLS7_GEN
    750837  Int         m_directDependencyType     [MAX_NUM_LAYERS] [MAX_NUM_LAYERS];
     838#endif
    751839
    752840  // VPS EXTENSION SEMANTICS VARIABLES
     
    851939  UInt    getNumReorderPics(UInt tLayer)                        { return m_numReorderPics[tLayer]; }
    852940 
    853   Void    setMaxDecPicBuffering(UInt v, UInt tLayer)            { m_uiMaxDecPicBuffering[tLayer] = v;    }
     941  Void    setMaxDecPicBuffering(UInt v, UInt tLayer)            { assert(tLayer < MAX_TLAYER); m_uiMaxDecPicBuffering[tLayer] = v;    }
    854942  UInt    getMaxDecPicBuffering(UInt tLayer)                    { return m_uiMaxDecPicBuffering[tLayer]; }
    855943 
     
    886974  Bool    getAvcBaseLayerFlag()                                            { return m_avcBaseLayerFlag; }
    887975
     976#if H_MV_HLS_7_VPS_P0307_23
     977  Void    setVpsNonVuiExtensionLength( Int  val )                          { m_vpsNonVuiExtensionLength = val; }
     978  Int     getVpsNonVuiExtensionLength(  )                                  { return m_vpsNonVuiExtensionLength; }
     979#else
    888980  Void    setVpsVuiOffset( Int  val )                                      { m_vpsVuiOffset = val; }
    889981  Int     getVpsVuiOffset(  )                                              { return m_vpsVuiOffset; }
     982#endif
    890983
    891984  Void    setSplittingFlag( Bool val )                                     { m_splittingFlag = val;  }
     
    9291022  Void    setAllRefLayersActiveFlag( Bool flag )                           { m_allRefLayersActiveFlag = flag; }
    9301023  Bool    getAllRefLayersActiveFlag(  )                                    { return m_allRefLayersActiveFlag; }
     1024 
     1025#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    9311026  Void    setVpsNumberLayerSetsMinus1( Int val )                           { m_vpsNumberLayerSetsMinus1 = val;  }
    9321027  Int     getVpsNumberLayerSetsMinus1( )                                   { return m_vpsNumberLayerSetsMinus1; }
     1028#endif
    9331029 
    9341030  Void    setVpsNumProfileTierLevelMinus1( Int val )                       { m_vpsNumProfileTierLevelMinus1 = val;  }
     
    9381034  Bool    getVpsProfilePresentFlag( Int idx )                              { return m_vpsProfilePresentFlag[idx]; }
    9391035
     1036#if !H_MV_HLS_7_VPS_P0048_14
    9401037  Void    setProfileRefMinus1( Int profileTierLevelIdx, Int val )          { m_profileRefMinus1[ profileTierLevelIdx ] = val;  }
    9411038  Int     getProfileRefMinus1( Int profileTierLevelIdx )                   { return m_profileRefMinus1[ profileTierLevelIdx ]; }
    9421039  Void    checkProfileRefMinus1( Int i )                                   { assert( getProfileRefMinus1( i ) + 1 <= i ); };  //  The value of profile_ref_minus1[ i ] + 1 shall be less than or equal to i.
     1040#endif
     1041
     1042#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    9431043  Void    setMoreOutputLayerSetsThanDefaultFlag( Bool flag )               { m_moreOutputLayerSetsThanDefaultFlag = flag; }
    9441044  Bool    getMoreOutputLayerSetsThanDefaultFlag()                          { return m_moreOutputLayerSetsThanDefaultFlag; }
    945  
     1045#endif
     1046 
     1047#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1048  Void    setNumAddOutputLayerSets( Int val )                              { m_numAddOutputLayerSets = val; }
     1049  Int     getNumAddOutputLayerSets( )                                      { return m_numAddOutputLayerSets; }
     1050#else
    9461051  Void    setNumAddOutputLayerSetsMinus1( Int val )                        { m_numAddOutputLayerSetsMinus1 = val; }
    9471052  Int     getNumAddOutputLayerSetsMinus1( )                                { return m_numAddOutputLayerSetsMinus1; }
    948  
     1053#endif
     1054 
     1055#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1056  Void    setDefaultTargetOutputLayerIdc( Int  val )                       { m_defaultTargetOutputLayerIdc = val; }
     1057  Int     getDefaultTargetOutputLayerIdc(  )                               { return m_defaultTargetOutputLayerIdc; }   
     1058#else
    9491059  Void    setDefaultOneTargetOutputLayerIdc( Int  val )                    { m_defaultOneTargetOutputLayerIdc = val; }
    9501060  Int     getDefaultOneTargetOutputLayerIdc(  )                            { return m_defaultOneTargetOutputLayerIdc; }
    9511061  Void    checkDefaultOneTargetOutputLayerIdc( )                           { assert( m_defaultOneTargetOutputLayerIdc >= 0 && m_defaultOneTargetOutputLayerIdc <= 1 ); }
     1062#endif
    9521063 
    9531064  Void    setOutputLayerSetIdxMinus1( Int outLayerSetIdx, Int val )        { m_outputLayerSetIdxMinus1[ outLayerSetIdx ]  = val; }
     
    9561067  Void    setOutputLayerFlag( Int outLayerSetIdx, Int i, Bool flag )       { m_outputLayerFlag[ outLayerSetIdx ][ i ] = flag; }
    9571068  Bool    getOutputLayerFlag( Int outLayerSetIdx, Int i )                  { return m_outputLayerFlag[ outLayerSetIdx ][ i ]; }
     1069#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1070  Bool    inferOutputLayerFlag( Int i, Int j )                             
     1071  {
     1072    Bool outputLayerFlag;
     1073    switch ( getDefaultTargetOutputLayerIdc( ) )
     1074    {
     1075    case 0:
     1076      outputLayerFlag = true;
     1077      break;
     1078    case 1:
     1079      outputLayerFlag = ( j == m_layerSetLayerIdList[ getLayerSetIdxForOutputLayerSet( i ) ].size() - 1 ); 
     1080      break;
     1081    case 2:
     1082      if ( i == 0 && j == 0)
     1083      {     
     1084        outputLayerFlag = true;  // This is a software only fix for a bug in the spec. In spec outputLayerFlag neither present nor inferred.
     1085      }
     1086      else
     1087      {
     1088        assert( 0 );
     1089      }
     1090      break;
     1091    default:     
     1092      assert( 0 );
     1093      break;
     1094    }
     1095    return outputLayerFlag;
     1096  }
     1097#else
    9581098  Bool    inferOutputLayerFlag( Int layerSetIdx, Int i )                   { return ( getDefaultOneTargetOutputLayerIdc( ) == 0 || ( ( getDefaultOneTargetOutputLayerIdc( ) == 1 ) && ( i == m_layerSetLayerIdList[layerSetIdx].size() - 1  ) ));  }
     1099#endif
    9591100
    9601101  Void    setProfileLevelTierIdx( Int outLayerSetIdx, Int val )            { m_profileLevelTierIdx[ outLayerSetIdx ] = val; }
    9611102  Int     getProfileLevelTierIdx( Int outLayerSetIdx )                     { return m_profileLevelTierIdx[ outLayerSetIdx ]; }
     1103 
     1104#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1105  Void    setAltOutputLayerFlag( Int i, Bool flag )                        { m_altOutputLayerFlag[i] = flag; }
     1106  Bool    getAltOutputLayerFlag( Int i )                                   { return m_altOutputLayerFlag[i]; }
     1107#else
    9621108  Void    setAltOutputLayerFlag( Bool flag )                               { m_altOutputLayerFlag = flag; }
    9631109  Bool    getAltOutputLayerFlag(  )                                        { return m_altOutputLayerFlag; }
     1110#endif
    9641111
    9651112  Void    setRepFormatIdxPresentFlag( Bool flag )                          { m_repFormatIdxPresentFlag = flag; }
     
    9771124  Bool    getMaxOneActiveRefLayerFlag( )                                   { return m_maxOneActiveRefLayerFlag; }
    9781125
     1126#if H_MV_HLS7_GEN
     1127  Void    setVpsPocLsbAlignedFlag( Bool flag )                             { m_vpsPocLsbAlignedFlag = flag; }
     1128  Bool    getVpsPocLsbAlignedFlag(  )                                      { return m_vpsPocLsbAlignedFlag; }
     1129#endif
     1130
    9791131  Void    setDpbSize( TComDpbSize* val )                                   { assert( m_dpbSize != 0 ); m_dpbSize = val; }
    9801132  TComDpbSize* getDpbSize( )                                               { return m_dpbSize;}
     
    9921144  Void    setDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps, Int val) { m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ] = val; }
    9931145  Int     getDirectDependencyType( Int depLayeridInVps, Int refLayeridInVps)   { return m_directDependencyType[ depLayeridInVps ][ refLayeridInVps ]; }
     1146
    9941147  Void    setVpsVuiPresentFlag( Bool flag )                                { m_vpsVuiPresentFlag = flag; }
    9951148  Bool    getVpsVuiPresentFlag(  )                                         { return m_vpsVuiPresentFlag; }
     
    10131166  Int     scalTypeToScalIdx   ( ScalabilityType scalType );
    10141167
    1015 Int     getProfileLevelTierIdxLen()                                      { return gCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
    1016 
     1168  Int     getProfileLevelTierIdxLen()                                      { return gCeilLog2( getVpsNumProfileTierLevelMinus1() + 1 ); };       
     1169
     1170#if H_MV_HLS_7_VPS_P0306_22
     1171  Int     getVpsRepFormatIdxLen()                                          { return gCeilLog2( getVpsNumRepFormatsMinus1() + 1 ); };       
     1172#endif
    10171173  Int     getNumLayersInIdList ( Int lsIdx );
    10181174
     
    10211177  Bool    isOutputLayer( Int outLayerSetIdx, Int layerIdInNuh );   
    10221178  Void    deriveLayerSetLayerIdList();
     1179
     1180#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1181  Int     getLayerSetIdxForOutputLayerSet( Int i )                         { return ( i <= getVpsNumLayerSetsMinus1() ) ? i  : getOutputLayerSetIdxMinus1( i ) + 1 ; };
     1182
     1183  Void    initTargetLayerIdLists  ( );
     1184  Void    deriveTargetLayerIdList ( Int i );
     1185
     1186  std::vector<Int> getTargetDecLayerIdList( Int targetDecLayerSetIdx )     { return m_targetDecLayerIdLists[targetDecLayerSetIdx]; };
     1187  std::vector<Int> getTargetOptLayerIdList( Int targetOptLayerSetIdx )     { return m_targetOptLayerIdLists[targetOptLayerSetIdx]; };
     1188
     1189  Int     getNumOutputLayersInOutputLayerSet( Int i )                      { return (Int) getTargetOptLayerIdList( i ).size(); };
     1190  Int     getOlsHighestOutputLayerId( Int i )                              { return getTargetOptLayerIdList( i ).back(); }; 
     1191#else
    10231192  Void    deriveTargetLayerIdLists();
    10241193  std::vector<Int> getTargetDecLayerIdList( Int targetOptLayerSetIdx )     { return m_targetDecLayerIdLists[targetOptLayerSetIdx]; };
    10251194  std::vector<Int> getTargetOptLayerIdList( Int targetOptLayerSetIdx )     { return m_targetDecLayerIdLists[targetOptLayerSetIdx]; };
    1026 
     1195#endif
     1196
     1197#if H_MV_HLS_7_HRD_P0156_7
     1198  Int     getMaxSubLayersInLayerSetMinus1( Int i )
     1199  {
     1200    Int maxSLMinus1 = 0;
     1201    Int optLsIdx    = getLayerSetIdxForOutputLayerSet( i );
     1202    for( Int k = 0; k < getNumLayersInIdList( optLsIdx ); k++ )
     1203    {
     1204      Int lId = m_layerSetLayerIdList[optLsIdx][k];
     1205      maxSLMinus1 = std::max( maxSLMinus1, getSubLayersVpsMaxMinus1( getLayerIdInVps( lId ) ));
     1206    }
     1207    return maxSLMinus1;
     1208  }
     1209#endif
    10271210
    10281211  // inference
     
    10491232  UInt getCamParPrecision    ()  { return m_uiCamParPrecision; }
    10501233  Bool getCamParPresent      ( Int viewIndex )  { return m_bCamParPresent[viewIndex]; }
     1234#if FIX_CAM_PARS_COLLECTOR
     1235  Void setCamParPresent      ( Int viewIndex, Bool val )  { m_bCamParPresent[viewIndex] = val; }
     1236#endif
    10511237  Bool hasCamParInSliceHeader( Int viewIndex )  { return m_bCamParInSliceHeader[viewIndex]; }
    10521238  Void setHasCamParInSliceHeader( Int viewIndex, Bool b )  { m_bCamParInSliceHeader[viewIndex] = b; }
     
    14191605  Int         m_qpBDOffsetY;
    14201606  Int         m_qpBDOffsetC;
    1421 
    1422   Bool        m_useLossless;
    14231607
    14241608  UInt        m_uiPCMBitDepthLuma;
     
    15531737  UInt getMaxTrSize   ()         { return  m_uiMaxTrSize;   }
    15541738 
    1555   // Tool list
    1556   Bool getUseLossless ()         { return m_useLossless; }
    1557   Void setUseLossless ( Bool b ) { m_useLossless  = b; }
    1558  
    15591739  // AMP accuracy
    15601740  Int       getAMPAcc   ( UInt uiDepth ) { return m_iAMPAcc[uiDepth]; }
     
    15921772  TComScalingList* getScalingList ()       { return m_scalingList; }               //!< get ScalingList class pointer in SPS
    15931773  UInt getMaxDecPicBuffering  (UInt tlayer)            { return m_uiMaxDecPicBuffering[tlayer]; }
    1594   Void setMaxDecPicBuffering  ( UInt ui, UInt tlayer ) { m_uiMaxDecPicBuffering[tlayer] = ui;   }
     1774  Void setMaxDecPicBuffering  ( UInt ui, UInt tlayer ) { assert(tlayer < MAX_TLAYER);  m_uiMaxDecPicBuffering[tlayer] = ui;   }
    15951775  UInt getMaxLatencyIncrease  (UInt tlayer)            { return m_uiMaxLatencyIncrease[tlayer];   }
    15961776  Void setMaxLatencyIncrease  ( UInt ui , UInt tlayer) { m_uiMaxLatencyIncrease[tlayer] = ui;      }
     
    17591939  Bool m_ppsInferScalingListFlag;
    17601940  Int  m_ppsScalingListRefLayerId;
     1941
     1942#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     1943  Bool m_ppsExtensionTypeFlag[PS_EX_T_MAX_NUM];
     1944#endif
     1945#if H_MV_HLS_7_POC_P0041
     1946  Bool m_pocResetInfoPresentFlag;
     1947#endif
    17611948#endif
    17621949
     
    19002087  Void setPpsScalingListRefLayerId( Int  val ) { m_ppsScalingListRefLayerId = val; }
    19012088  Int  getPpsScalingListRefLayerId(  ) { return m_ppsScalingListRefLayerId; }
     2089
     2090#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     2091  Void setPpsExtensionTypeFlag( Int i, Bool flag ) { m_ppsExtensionTypeFlag[i] = flag; }
     2092  Bool getPpsExtensionTypeFlag( Int i ) { return m_ppsExtensionTypeFlag[i]; }
     2093#endif
     2094
     2095#if H_MV_HLS_7_POC_P0041
     2096  Void setPocResetInfoPresentFlag( Bool flag ) { m_pocResetInfoPresentFlag = flag; }
     2097  Bool getPocResetInfoPresentFlag(  ) { return m_pocResetInfoPresentFlag; }
     2098#endif
     2099
    19022100#endif
    19032101};
     
    19882186  UInt        m_maxNumMergeCand;
    19892187
    1990 
    1991 #if SAO_CHROMA_LAMBDA
    1992   Double      m_dLambdaLuma;
    1993   Double      m_dLambdaChroma;
    1994 #else
    1995   Double      m_dLambda;
    1996 #endif
     2188  Double      m_lambdas[3];
    19972189
    19982190  Bool        m_abEqualRef  [2][MAX_NUM_REF][MAX_NUM_REF];
     
    20422234
    20432235// Additional slice header syntax elements
     2236#if !H_MV_HLS7_GEN
    20442237  Bool       m_pocResetFlag;
     2238#endif
    20452239  Bool       m_crossLayerBlaFlag;
    20462240  Bool       m_discardableFlag;
     
    20482242  Int        m_numInterLayerRefPicsMinus1;
    20492243  Int        m_interLayerPredLayerIdc       [MAX_NUM_LAYERS];
     2244
     2245#if H_MV_HLS_7_POC_P0041
     2246  Int        m_sliceSegmentHeaderExtensionLength;
     2247  Int        m_pocResetIdc;
     2248  Int        m_pocResetPeriodId;
     2249  Bool       m_fullPocResetFlag;
     2250  Int        m_pocLsbVal;
     2251  Bool       m_pocMsbValPresentFlag;
     2252  Int        m_pocMsbVal;
     2253  Bool       m_pocMsbValRequiredFlag;
     2254#endif
     2255
     2256#if H_3D
    20502257  Int        m_aaiCodedScale [2][MAX_NUM_LAYERS];
    20512258  Int        m_aaiCodedOffset[2][MAX_NUM_LAYERS];
     2259#endif
    20522260#if H_3D_TMVP
    20532261  Int        m_aiAlterRefIdx   [2];
     
    22052413  Void      setRefPicList        ( std::vector<TComPic*> rpsCurrList[2], std::vector<Bool> usedAsLongTerm[2], Int numPocTotalCurr, Bool checkNumPocTotalCurr = false );
    22062414#else
    2207 #if FIX1071
    22082415  Void      setRefPicList       ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false );
    2209 #else
    2210   Void      setRefPicList       ( TComList<TComPic*>& rcListPic );
    2211 #endif
    22122416#endif
    22132417  Void      setRefPOCList       ();
     
    22212425  Bool      isInterP        ()                          { return  m_eSliceType == P_SLICE;  }
    22222426 
    2223 #if SAO_CHROMA_LAMBDA 
    2224   Void      setLambda( Double d, Double e ) { m_dLambdaLuma = d; m_dLambdaChroma = e;}
    2225   Double    getLambdaLuma() { return m_dLambdaLuma;        }
    2226   Double    getLambdaChroma() { return m_dLambdaChroma;        }
    2227 #else
    2228   Void      setLambda( Double d ) { m_dLambda = d; }
    2229   Double    getLambda() { return m_dLambda;        }
    2230 #endif
     2427  Void      setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; }
     2428  const Double* getLambdas() const { return m_lambdas; }
    22312429 
    22322430  Void      initEqualRef();
     
    22622460  Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic );
    22632461  Int       checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0);
    2264 #if FIX1071
    22652462  Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP);
    2266 #else
    2267   Void      createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet);
    2268 #endif
    22692463
    22702464  Void setMaxNumMergeCand               (UInt val )         { m_maxNumMergeCand = val;                    }
     
    23892583  }
    23902584
     2585#if !H_MV_HLS7_GEN
    23912586  Void setPocResetFlag( Bool flag ) { m_pocResetFlag = flag; }
    23922587  Bool getPocResetFlag(  ) { return m_pocResetFlag; }
     2588#endif
    23932589
    23942590  Void setDiscardableFlag( Bool flag ) { m_discardableFlag = flag; }
     
    24032599  Void setInterLayerPredLayerIdc( Int i, Int  val ) { m_interLayerPredLayerIdc[i] = val; }
    24042600  Int  getInterLayerPredLayerIdc( Int i ) { return m_interLayerPredLayerIdc[i]; }
     2601
     2602#if H_MV_HLS_7_POC_P0041
     2603  Void setSliceSegmentHeaderExtensionLength( Int  val ) { m_sliceSegmentHeaderExtensionLength = val; }
     2604  Int  getSliceSegmentHeaderExtensionLength(  ) { return m_sliceSegmentHeaderExtensionLength; }
     2605
     2606  Void setPocResetIdc( Int  val ) { m_pocResetIdc = val; }
     2607  Int  getPocResetIdc(  ) { return m_pocResetIdc; }
     2608
     2609  Void setPocResetPeriodId( Int  val ) { m_pocResetPeriodId = val; }
     2610  Int  getPocResetPeriodId(  ) { return m_pocResetPeriodId; }
     2611
     2612  Void setFullPocResetFlag( Bool flag ) { m_fullPocResetFlag = flag; }
     2613  Bool getFullPocResetFlag(  ) { return m_fullPocResetFlag; }
     2614
     2615  Void setPocLsbVal( Int  val ) { m_pocLsbVal = val; }
     2616  Int  getPocLsbVal(  ) { return m_pocLsbVal; }
     2617
     2618  Void setPocMsbValPresentFlag( Bool flag ) { m_pocMsbValPresentFlag = flag; }
     2619  Bool getPocMsbValPresentFlag(  ) { return m_pocMsbValPresentFlag; }
     2620
     2621  Void setPocMsbVal( Int  val ) { m_pocMsbVal = val; }
     2622  Int  getPocMsbVal(  ) { return m_pocMsbVal; }
     2623
     2624  Bool getPocMsbValRequiredFlag() { return m_pocMsbValRequiredFlag; }
     2625  Void setPocMsbValRequiredFlag(Bool x) { m_pocMsbValRequiredFlag = x; }
     2626
     2627  UInt getPocLsbValLen() { return getSPS()->getBitsForPOC(); }; //log2_max_pic_order_cnt_lsb_minus4 + 4 
     2628
     2629  Bool getBlaPicFlag       ()
     2630  {
     2631    return  getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     2632    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     2633    || getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP;
     2634  }
     2635  Bool getCraPicFlag       ()
     2636  {
     2637    return getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA;
     2638  }
     2639#endif
    24052640
    24062641  // Additional variables derived in slice header semantics
     
    24212656  Void     setRefPicSetInterLayer       ( std::vector<TComPic*>* refPicSetInterLayer0, std::vector<TComPic*>* refPicSetInterLayer1);
    24222657  TComPic* getPicFromRefPicSetInterLayer( Int setIdc, Int layerId );
    2423 #endif
    2424 
     2658
     2659#endif
    24252660#if MTK_DDD_G0063
    24262661  Void InitializeDDDPara( UInt uiCamParsCodedPrecision, Int  iCodedScale,Int  iCodedOffset, Int iBaseViewIdx );
  • trunk/source/Lib/TLibCommon/TComTrQuant.cpp

    r608 r872  
    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 *
     
    10681068    UInt uiLog2TrSize = g_aucConvertToBit[ iWidth ] + 2;
    10691069    Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType];
    1070     assert(scalingListType < 6);
     1070    assert(scalingListType < SCALING_LIST_NUM);
    10711071    Int *piQuantCoeff = 0;
    10721072    piQuantCoeff = getQuantCoeff(scalingListType,m_cQP.m_iRem,uiLog2TrSize-2);
     
    13071307    Pel* pResi = rpcResidual + uiAddr;
    13081308    Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTxt];
    1309     assert(scalingListType < 6);
     1309    assert(scalingListType < SCALING_LIST_NUM);
    13101310    invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eTxt, REG_DCT, pResi, uiStride, rpcCoeff, uiWidth, uiHeight, scalingListType, pcCU->getTransformSkip(uiAbsPartIdx, eTxt) );
    13111311  }
     
    15081508  const UInt uiMaxNumCoeff       = uiWidth * uiHeight;
    15091509  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eTType];
    1510   assert(scalingListType < 6);
     1510  assert(scalingListType < SCALING_LIST_NUM);
    15111511 
    15121512  Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                   // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
     
    19271927              Int64 costUp   = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
    19281928              Int64 costDown = rdFactor * (   deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos]
    1929               -   ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0 );
     1929              -   ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0);
    19301930             
    19311931              if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
     
    21462146  {
    21472147    Double dErr         = Double( lLevelDouble  - ( uiAbsLevel << iQBits ) );
    2148     Double dCurrCost    = dErr * dErr * dTemp + xGetICRateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx );
     2148    Double dCurrCost    = dErr * dErr * dTemp + xGetICost(xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx ));
    21492149    dCurrCost          += dCurrCostSig;
    21502150
     
    21672167 * \returns cost of given absolute transform level
    21682168 */
    2169 __inline Double TComTrQuant::xGetICRateCost  ( UInt                            uiAbsLevel,
     2169__inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
    21702170                                               UShort                          ui16CtxNumOne,
    21712171                                               UShort                          ui16CtxNumAbs,
     
    21752175                                               ) const
    21762176{
    2177   Double iRate = xGetIEPRate();
     2177  Int iRate = Int(xGetIEPRate());
    21782178  UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
    21792179
     
    22192219  else
    22202220  {
    2221     assert (0);
    2222   }
    2223   return xGetICost( iRate );
    2224 }
    2225 
    2226 __inline Int TComTrQuant::xGetICRate  ( UInt                            uiAbsLevel,
    2227                                        UShort                          ui16CtxNumOne,
    2228                                        UShort                          ui16CtxNumAbs,
    2229                                        UShort                          ui16AbsGoRice
    2230                                      , UInt                            c1Idx,
    2231                                        UInt                            c2Idx
    2232                                        ) const
    2233 {
    2234   Int iRate = 0;
    2235   UInt baseLevel  =  (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1;
    2236 
    2237   if ( uiAbsLevel >= baseLevel )
    2238   {
    2239     UInt uiSymbol     = uiAbsLevel - baseLevel;
    2240     UInt uiMaxVlc     = g_auiGoRiceRange[ ui16AbsGoRice ];
    2241     Bool bExpGolomb   = ( uiSymbol > uiMaxVlc );
    2242 
    2243     if( bExpGolomb )
    2244     {
    2245       uiAbsLevel  = uiSymbol - uiMaxVlc;
    2246       Int iEGS    = 1;  for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 );
    2247       iRate      += iEGS << 15;
    2248       uiSymbol    = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) );
    2249     }
    2250 
    2251     UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1;
    2252     UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice;
    2253 
    2254     iRate += ui16NumBins << 15;
    2255 
    2256     if (c1Idx < C1FLAG_NUMBER)
    2257     {
    2258       iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
    2259 
    2260       if (c2Idx < C2FLAG_NUMBER)
    2261       {
    2262         iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ];
    2263       }
    2264     }
    2265   }
    2266   else
    2267   if( uiAbsLevel == 0 )
    2268   {
    2269     return 0;
    2270   }
    2271   else if( uiAbsLevel == 1 )
    2272   {
    2273     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 0 ];
    2274   }
    2275   else if( uiAbsLevel == 2 )
    2276   {
    2277     iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ];
    2278     iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 0 ];
    2279   }
    2280   else
    2281   {
    2282     assert(0);
     2221    iRate = 0;
    22832222  }
    22842223  return iRate;
  • trunk/source/Lib/TLibCommon/TComTrQuant.h

    r608 r872  
    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 *
     
    150150
    151151#if RDOQ_CHROMA_LAMBDA
    152   Void setLambda(Double dLambdaLuma, Double dLambdaChroma) { m_dLambdaLuma = dLambdaLuma; m_dLambdaChroma = dLambdaChroma; }
    153   Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_dLambdaLuma : m_dLambdaChroma; }
     152  Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; }
     153  Void selectLambda(TextType eTType) { m_dLambda = (eTType == TEXT_LUMA) ? m_lambdas[0] : ((eTType == TEXT_CHROMA_U) ? m_lambdas[1] : m_lambdas[2]); }
    154154#else
    155155  Void setLambda(Double dLambda) { m_dLambda = dLambda;}
     
    207207  QpParam  m_cQP;
    208208#if RDOQ_CHROMA_LAMBDA
    209   Double   m_dLambdaLuma;
    210   Double   m_dLambdaChroma;
     209  Double   m_lambdas[3];
    211210#endif
    212211  Double   m_dLambda;
     
    273272                                             Double                          dTemp,
    274273                                             Bool                            bLast        ) const;
    275   __inline Double xGetICRateCost   ( UInt                            uiAbsLevel,
    276                                      UShort                          ui16CtxNumOne,
    277                                      UShort                          ui16CtxNumAbs,
    278                                      UShort                          ui16AbsGoRice
    279                                    , UInt                            c1Idx,
    280                                      UInt                            c2Idx
    281                                      ) const;
    282274__inline Int xGetICRate  ( UInt                            uiAbsLevel,
    283275                           UShort                          ui16CtxNumOne,
  • trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp

    r608 r872  
    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/TLibCommon/TComWeightPrediction.h

    r655 r872  
    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/TLibCommon/TComYuv.cpp

    r622 r872  
    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 *
     
    110110  {
    111111    ::memcpy( pDst, pSrc, sizeof(Pel)*iWidth);
    112 
    113112#if ENC_DEC_TRACE && H_MV_ENC_DEC_TRAC
    114113    if ( g_traceCopyBack && g_nSymbolCounter >= g_stopAtCounter )
     
    121120    }
    122121#endif
    123 
    124122    pDst += iDstStride;
    125123    pSrc += iSrcStride;
     
    616614    {
    617615#if DISABLING_CLIP_FOR_BIPREDME
    618       pDst[x ] = (pDst[x ]<<1) - pSrc[x ] ;
     616      pDst[x ] = 2 * pDst[x] - pSrc[x];
    619617#else
    620       pDst[x ] = Clip( (pDst[x ]<<1) - pSrc[x ] );
     618      pDst[x ] = ClipY(2 * pDst[x] - pSrc[x]);
    621619#endif
    622620    }
     
    636634    {
    637635#if DISABLING_CLIP_FOR_BIPREDME
    638       pDstU[x ] = (pDstU[x ]<<1) - pSrcU[x ] ;
    639       pDstV[x ] = (pDstV[x ]<<1) - pSrcV[x ] ;
     636      pDstU[x ] = 2 * pDstU[x] - pSrcU[x];
     637      pDstV[x ] = 2 * pDstV[x] - pSrcV[x];
    640638#else
    641       pDstU[x ] = Clip( (pDstU[x ]<<1) - pSrcU[x ] );
    642       pDstV[x ] = Clip( (pDstV[x ]<<1) - pSrcV[x ] );
     639      pDstU[x ] = ClipC(2 * pDstU[x] - pSrcU[x]);
     640      pDstV[x ] = ClipC(2 * pDstV[x] - pSrcV[x]);
    643641#endif
    644642    }
     
    649647  }
    650648}
    651 
    652649#if H_3D
    653650Void TComYuv::addClipPartLuma( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt uiTrUnitIdx, UInt uiPartSize )
     
    843840#endif
    844841#endif
     842
    845843//! \}
  • trunk/source/Lib/TLibCommon/TComYuv.h

    r608 r872  
    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/TLibCommon/TypeDef.h

    r863 r872  
    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 *
     
    325325#define MTK_NBDV_IVREF_FIX_G0067          1   // Disable IvMC, VSP when IVREF is not available, JCT3V-G0067
    326326#endif
     327
     328/////////////////////////////////////////////////////////////////////////////////////////
     329///////////////////////////////////   HTM-10.1 Integrations //////////////////////////////
     330/////////////////////////////////////////////////////////////////////////////////////////
     331
     332
     333// TBD
     334// #define H_MV_HLS_7_POC_P0041_3            0 // (POC/P0041/POC reset) #3 It was remarked that we should require each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture. This was agreed. Decision: Adopt (with constraint for discardable_flag as described above)
     335// #define H_MV_HLS_7_POC_P0041_FIXES        0 // (POC/P0041/Fixes) For each non-IRAP picture that has discardable_flag equal to 1 to have NUT value indicating that it is a sub-layer non-reference picture.
     336// #define H_MV_HLS_7_POC_P0056_4            0 // (POC/P0056/layer tree poc) #4 Proposal 1: If the POC reset approach is adopted as the basis for multi-layer POC derivation, it is proposed to derive the POC anchor picture from the previous TID0 picture (that is not a RASL picture, a RADL picture or a sub-layer non-reference picture and not with discardable_flag equal to 1) of  the current layer or any of its reference layer. This is asserted to improve loss resilience and reduce bit rate overhead. Decision: Adopt Proposal 1 (with the suggested modifications – with text provided as P0297).
     337
     338// #define H_MV_HLS_7_SEI_P0133_28           0 // (SEI/P0133/Recovery point SEI) #28 Decision: Adopt change to recover point semantics only (-v3)
     339// #define H_MV_HLS_7_SEI_P0123_25           0 // (SEI/P0123/Alpha channel info) #25 Add alpha channel information SEI message Decision: Adopt. Constrain the bit depth indicated to be equal to the coded bit depth of the aux picture.
     340
     341// #define H_MV_HLS_7_HRD_P0138_6            0 // (HRD/P0138/HRD parameters for bitstreams excluding) #6 Decision: Adopt (as revised in updated contribution, with the specification of a flag in the BP SEI (HRD/P0192/sub-DPB) #12 Establish sub-DPBs based on the representation format indicated at the VPS level. It was suggested that the expressed shared capacity limit would need to be less than or equal to the sum of the individual capacity limits. Decision: Adopt as modified. Further study is encouraged on profile/level constraint selections.
     342// #define H_MV_HLS_7_OTHER_P0187_1          0 // (OTHER/P0187/NoOutputOfPriorPicsFlag) #1 Inference of NoOutputOfPriorPicsFlag and proposes to take into account colour format and bit depth for the inference in addition to spatial resolution
     343// #define H_MV_HLS_7_VPS_P0300_27           0 // Output part only. (VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
     344
     345
     346#define H_MV_HLS_7_VPS_P0306_22                1 // (VPS/P0306/ue(v) coded syntax elements) #22 Several minor modifications to the VPS syntax, consistent with eliminating the previous intention to avoid ue(v) parsing in the VPS
     347#define H_MV_HLS_7_SEI_P0204_26                1 // (SEI/P0204/sub-bitstream SEI) #26 Add sub-bitstream property SEI message. Decision: Adopt
     348#define H_MV_HLS_7_MISC_P0130_20               1 // (MISC/P0130/discardable not in inter-layer RPS) #20 Add constraint restricting pictures marked as discardable from being present in the temporal or inter-layer RPS,
     349#define H_MV_HLS_7_VPS_P0125_24                1 // (VPS/P0125/VPS extension offset ) #24 Decision: Keep it as a reserved FFFF value.
     350#define H_MV_HLS_7_VPS_P0307_23                1 // (VPS/P0307/VPS VUI extension)  #23 Decision: Adopt modification in P0307.
     351#define H_MV_HLS_7_POC_P0041                   1 // Syntax related to POC reset
     352
     353
     354#define H_MV_HLS7_GEN                          0  // General changes (not tested)
     355#define H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27    1  // Output layer sets, various
     356                                                  // (VPS/P0300/alt output layer flag) #27 Change alt output layer flag to be signalled within the loop of output layer sets, from JCTVC-P0300-v2. Decision: Adopt.
     357                                                  // (VPS/P0156/Num of output_layer_flag) #10 Proposal 3: The output_layer_flag[ i ][ j ] is signalled for j equal to 0 to NumLayersInIdList[ lsIdx ] inclusive. It was remarked that we might be able to just assume that the top layer is always output; however, this was not entirely clear , so the safe thing to do may be to also send the flag for this layer.
     358                                                  // (VPS/P0295/Default output layer sets) #5 Discussion from (P0110). Decision: Three-state approach (text in P0295, decoder shall allow 3 to be present and shall treat 3 the same as the value 2).
     359
     360
     361#define H_MV_HLS_7_HRD_P0156_7                 1  // (HRD/P0156/MaxSubLayersInLayerSetMinus1) #7 Proposal 1: signal, in the VPS extension, the DPB parameters for an output layer set for sub-DPBs only up to the maximum temporal sub-layers in the corresponding layer set
     362#define H_MV_HLS_7_VPS_P0048_14                1  // (VPS/P0048/profile_ref_minus1 rem) #14 Remove profile_ref_minus1 from the VPS extension, from JCTVC-P0048
     363#define H_MV_HLS_7_VPS_P0076_15                1  // (VPS/P0076/video signal info move) #15 Move video signal information syntax structure earlier in the VPS VUI.
     364#define H_MV_HLS_7_SPS_P0155_16_32             1  // (SPS/P0155/sps_sub_layer_ordering_info) #16, #32 Not signal the sps_max_num_reorder_pics[], sps_max_latency_increase_plus1[], and sps_max_dec_pic_buffering_minus1[] syntax elements in the SPS when nuh_layer_id > 0.
     365#define H_MV_HLS_7_GEN_P0166_PPS_EXTENSION     1  // (GEN/P0166/pps_extension) #17 Add PPS extension type flags for conditional presence of syntax extensions per extension type, aligned with the SPS extension type flags, from JCTVC-P0166. Further align the SPS extension type flags syntax between RExt and MV-HEVC/SHVC
     366#define H_MV_HLS_7_FIX_SET_DPB_SIZE            1  // Fix derivation dpb size parameters
     367#define H_MV_HLS_7_RESERVED_FLAGS              1  // Added flags
     368                                                  // (SPS/P0312/SHVC reserved flag) The flag will be used for the syntax vert_phase_position_enable_flag in SHVC draft
     369                                                  // (VPS/O0215/SHVC reserved flag): this flag will be used for the syntax cross_layer_phase_alignment_flag in SHVC draft.
     370                                                  // (VPS VUI/O0199,P0312/SHVC reserved flags) the 3 reserved bits will be used for the syntaxes single_layer_for_non_irap_flag, higher_layer_irap_skip_flag and vert_phase_position_not_in_use_flag in SHVC draft.
     371#define H_MV_FIX_VPS_LAYER_ID_NOT_EQUAL_ZERO   1  // Discard VPS with nuh_layer_Id > 0
     372#define H_MV_HLS_7_MISC_P0130_EOS              1  // (MISC/P0130/EOS NAL layer id) #19 Require that end of bitstream NAL unit shall have nuh_layer_id equal to 0, from JCTVC-P0130. Decoders shall allow an end of bitstream NAL unit with nuh_layer_id > 0 to be present, and shall ignore the NAL unit.
     373#define H_MV_HLS_7_MISC_P0182_13               1  // (MISC/P0182/BL PS Compatibility flag) #13 Define the flag (in VPS VUI) with the proposed semantics, without specifying an associated extraction process. Editors to select the position in the VPS VUI.
     374#define H_MV_HLS_7_MISC_P0068_21               1  // (MISC/P0068/all irap idr flag) #21 Add flag in VUI to indicate that all IRAP pictures are IDRs and that all layer pictures in an AU are IDR aligned, from JCTVC-P0068 proposal 1.
     375#define H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG               1  // Fix inference of cross_layer_irap_aligned_flag
     376#define H_MV_HLS_7_MISC_P0079_18               1  // (MISC/P0079/NumActiveRefLayerPics) #18 Modification of derivation of variable NumActiveRefLayerPics.
     377#define FIX_CAM_PARS_COLLECTOR                 1
     378#define UPDATE_HM13                            1  // Only some parts in H_3D parts are marked!
     379#if H_3D
     380#define H_3D_FIX_G0148_BRACE                   1
     381#endif
    327382/////////////////////////////////////////////////////////////////////////////////////////
    328383///////////////////////////////////   HM RELATED DEFINES ////////////////////////////////
    329384/////////////////////////////////////////////////////////////////////////////////////////
    330 
    331 #define FIX1071 1 ///< fix for issue #1071
     385#define BUGFIX_INTRAPERIOD 1
     386#define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1
     387
     388#define FIX1172 1 ///< fix ticket #1172
    332389
    333390#define MAX_NUM_PICS_IN_SOP           1024
     
    344401#else
    345402#define MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1  1
    346 #endif
    347 
    348 #define RATE_CONTROL_LAMBDA_DOMAIN                  1  ///< JCTVC-K0103, rate control by R-lambda model
    349 #define M0036_RC_IMPROVEMENT                        1  ///< JCTVC-M0036, improvement for R-lambda model based rate control
    350 #define TICKET_1090_FIX                             1
    351 
    352 #if KWU_FIX_URQ
    353 #if RATE_CONTROL_LAMBDA_DOMAIN
    354 #define RC_FIX                                      1  /// suggested fix for M0036
    355 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra
    356 #endif
    357 #else
    358 #define RC_FIX                                      1  /// suggested fix for M0036
    359 #define RATE_CONTROL_INTRA                          1  ///< JCTVC-M0257, rate control for intra
    360403#endif
    361404
     
    373416#define MAX_NUM_BITSTREAM_PARTITIONS    100 ///< Maximum value is actually not specified
    374417#define MAX_NUM_BSP_SCHED_COMBINATION   100 ///< Maximum value is actually not specified
     418#if H_MV_HLS_7_SEI_P0204_26
     419#define MAX_SUB_STREAMS                 1024
     420#endif
    375421#else
    376422#define MAX_NUM_LAYER_IDS                64
     
    391437#define C1FLAG_NUMBER               8 // maximum number of largerThan1 flag coded in one chunk :  16 in HM5
    392438#define C2FLAG_NUMBER               1 // maximum number of largerThan2 flag coded in one chunk:  16 in HM5
    393 
    394 #define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1  ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode
    395 
    396439#define SAO_ENCODING_CHOICE              1  ///< I0184: picture early termination
    397440#if SAO_ENCODING_CHOICE
     
    407450#define MAX_NUM_PPS                64
    408451
    409 
    410 
    411 #define WEIGHTED_CHROMA_DISTORTION  1   ///< F386: weighting of chroma for RDO
    412452#define RDOQ_CHROMA_LAMBDA          1   ///< F386: weighting of chroma for RDOQ
    413 #define SAO_CHROMA_LAMBDA           1   ///< F386: weighting of chroma for SAO
    414453
    415454#define MIN_SCAN_POS_CROSS          4
     
    425464#define LEVEL_RANGE                         30     ///< G382: max coefficient level in statistics collection
    426465#endif
    427 
    428 #define NS_HAD                               0
    429466
    430467#define HHI_RQT_INTRA_SPEEDUP             1           ///< tests one best mode with full rqt
     
    494531#endif
    495532
    496 #define SCALING_LIST_OUTPUT_RESULT    0 //JCTVC-G880/JCTVC-G1016 quantization matrices
    497 
    498533#define CABAC_INIT_PRESENT_FLAG     1
    499534
     
    505540typedef       bool                Bool;
    506541
     542#ifdef __arm__
     543typedef       signed char         Char;
     544#else
    507545typedef       char                Char;
     546#endif
    508547typedef       unsigned char       UChar;
    509548typedef       short               Short;
     
    572611};
    573612
    574 #define NUM_DOWN_PART 4
    575 
    576 enum SAOTypeLen
    577 {
    578   SAO_EO_LEN    = 4,
    579   SAO_BO_LEN    = 4,
    580   SAO_MAX_BO_CLASSES = 32
    581 };
    582 
    583 enum SAOType
    584 {
    585   SAO_EO_0 = 0,
    586   SAO_EO_1,
    587   SAO_EO_2,
    588   SAO_EO_3,
    589   SAO_BO,
    590   MAX_NUM_SAO_TYPE
    591 };
    592 
    593 typedef struct _SaoQTPart
    594 {
    595   Int         iBestType;
    596   Int         iLength;
    597   Int         subTypeIdx ;                 ///< indicates EO class or BO band position
    598   Int         iOffset[4];
    599   Int         StartCUX;
    600   Int         StartCUY;
    601   Int         EndCUX;
    602   Int         EndCUY;
    603 
    604   Int         PartIdx;
    605   Int         PartLevel;
    606   Int         PartCol;
    607   Int         PartRow;
    608 
    609   Int         DownPartsIdx[NUM_DOWN_PART];
    610   Int         UpPartIdx;
    611 
    612   Bool        bSplit;
    613 
    614   //---- encoder only start -----//
    615   Bool        bProcessed;
    616   Double      dMinCost;
    617   Int64       iMinDist;
    618   Int         iMinRate;
    619   //---- encoder only end -----//
    620 } SAOQTPart;
    621 
    622 typedef struct _SaoLcuParam
    623 {
    624   Bool       mergeUpFlag;
    625   Bool       mergeLeftFlag;
    626   Int        typeIdx;
    627   Int        subTypeIdx;                  ///< indicates EO class or BO band position
    628   Int        offset[4];
    629   Int        partIdx;
    630   Int        partIdxTmp;
    631   Int        length;
    632 } SaoLcuParam;
    633 
    634 struct SAOParam
    635 {
    636   Bool       bSaoFlag[2];
    637   SAOQTPart* psSaoPart[3];
    638   Int        iMaxSplitLevel;
    639   Bool         oneUnitFlag[3];
    640   SaoLcuParam* saoLcuParam[3];
    641   Int          numCuInHeight;
    642   Int          numCuInWidth;
    643   ~SAOParam();
     613enum SAOComponentIdx
     614{
     615  SAO_Y =0,
     616  SAO_Cb,
     617  SAO_Cr,
     618  NUM_SAO_COMPONENTS
     619};
     620
     621enum SAOMode //mode
     622{
     623  SAO_MODE_OFF = 0,
     624  SAO_MODE_NEW,
     625  SAO_MODE_MERGE,
     626  NUM_SAO_MODES
     627};
     628
     629enum SAOModeMergeTypes
     630{
     631  SAO_MERGE_LEFT =0,
     632  SAO_MERGE_ABOVE,
     633  NUM_SAO_MERGE_TYPES
     634};
     635
     636
     637enum SAOModeNewTypes
     638{
     639  SAO_TYPE_START_EO =0,
     640  SAO_TYPE_EO_0 = SAO_TYPE_START_EO,
     641  SAO_TYPE_EO_90,
     642  SAO_TYPE_EO_135,
     643  SAO_TYPE_EO_45,
     644
     645  SAO_TYPE_START_BO,
     646  SAO_TYPE_BO = SAO_TYPE_START_BO,
     647
     648  NUM_SAO_NEW_TYPES
     649};
     650#define NUM_SAO_EO_TYPES_LOG2 2
     651
     652enum SAOEOClasses
     653{
     654  SAO_CLASS_EO_FULL_VALLEY = 0,
     655  SAO_CLASS_EO_HALF_VALLEY = 1,
     656  SAO_CLASS_EO_PLAIN       = 2,
     657  SAO_CLASS_EO_HALF_PEAK   = 3,
     658  SAO_CLASS_EO_FULL_PEAK   = 4,
     659  NUM_SAO_EO_CLASSES,
     660};
     661
     662
     663#define NUM_SAO_BO_CLASSES_LOG2  5
     664enum SAOBOClasses
     665{
     666  //SAO_CLASS_BO_BAND0 = 0,
     667  //SAO_CLASS_BO_BAND1,
     668  //SAO_CLASS_BO_BAND2,
     669  //...
     670  //SAO_CLASS_BO_BAND31,
     671
     672  NUM_SAO_BO_CLASSES = (1<<NUM_SAO_BO_CLASSES_LOG2),
     673};
     674#define MAX_NUM_SAO_CLASSES  32  //(NUM_SAO_EO_GROUPS > NUM_SAO_BO_GROUPS)?NUM_SAO_EO_GROUPS:NUM_SAO_BO_GROUPS
     675
     676struct SAOOffset
     677{
     678  Int modeIdc; //NEW, MERGE, OFF
     679  Int typeIdc; //NEW: EO_0, EO_90, EO_135, EO_45, BO. MERGE: left, above
     680  Int typeAuxInfo; //BO: starting band index
     681  Int offset[MAX_NUM_SAO_CLASSES];
     682
     683  SAOOffset();
     684  ~SAOOffset();
     685  Void reset();
     686
     687  const SAOOffset& operator= (const SAOOffset& src);
     688};
     689
     690struct SAOBlkParam
     691{
     692
     693  SAOBlkParam();
     694  ~SAOBlkParam();
     695  Void reset();
     696  const SAOBlkParam& operator= (const SAOBlkParam& src);
     697  SAOOffset& operator[](Int compIdx){ return offsetParam[compIdx];}
     698private:
     699  SAOOffset offsetParam[NUM_SAO_COMPONENTS];
     700
    644701};
    645702
     
    852909#if H_MV
    853910
     911#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     912enum PpsExtensionTypes
     913{
     914  PPS_EX_T_MV      = 0,
     915#if H_3D
     916  PPS_EX_T_3D      = 3,
     917#endif
     918  PPS_EX_T_ESC     = 7,
     919  PPS_EX_T_MAX_NUM = 8
     920};
     921
     922//Below for sps, would be good if this could be aligned
     923#endif
     924
    854925  enum PsExtensionTypes
    855926  {
  • trunk/source/Lib/TLibDecoder/AnnexBread.cpp

    r608 r872  
    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/TLibDecoder/AnnexBread.h

    r608 r872  
    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/TLibDecoder/NALread.cpp

    r608 r872  
    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 *
     
    7070        break;
    7171      }
     72      assert(*it_read <= 0x03);
    7273    }
    7374    zeroCount = (*it_read == 0x00) ? zeroCount+1 : 0;
     
    126127  else
    127128  {
    128     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
     129    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
    129130         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    130131         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
  • trunk/source/Lib/TLibDecoder/NALread.h

    r608 r872  
    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/TLibDecoder/SEIread.cpp

    r655 r872  
    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 *
     
    9999    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    100100    break;
     101#if H_MV_HLS_7_SEI_P0204_26
     102  case SEI::SUB_BITSTREAM_PROPERTY:
     103    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
     104    break;
     105#endif
    101106  default:
    102107    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
     
    240245      xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps);
    241246      break;
     247#if H_MV_HLS_7_SEI_P0204_26
     248     case SEI::SUB_BITSTREAM_PROPERTY:
     249       sei = new SEISubBitstreamProperty;
     250       xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei);
     251       break;
     252#endif
    242253    default:
    243254      for (UInt i = 0; i < payloadSize; i++)
     
    443454  if( !pHRD->getSubPicCpbParamsPresentFlag() )
    444455  {
    445     READ_FLAG( code, "rap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
     456    READ_FLAG( code, "irap_cpb_params_present_flag" );                   sei.m_rapCpbParamsPresentFlag = code;
     457  }
     458  if( sei.m_rapCpbParamsPresentFlag )
     459  {
     460    READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
     461    READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
    446462  }
    447463  //read splicing flag and cpb_removal_delay_delta
     
    450466  READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" );
    451467  sei.m_auCpbRemovalDelayDelta = code + 1;
    452   if( sei.m_rapCpbParamsPresentFlag )
    453   {
    454     READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" );      sei.m_cpbDelayOffset = code;
    455     READ_CODE( pHRD->getDpbOutputDelayLengthMinus1()  + 1, code, "dpb_delay_offset" );      sei.m_dpbDelayOffset = code;
    456   }
    457468  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    458469  {
     
    766777
    767778}
     779#if H_MV_HLS_7_SEI_P0204_26
     780Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei)
     781{
     782  UInt uiCode;
     783  READ_CODE( 4, uiCode, "active_vps_id" );                      sei.m_activeVpsId = uiCode;
     784  READ_UVLC(    uiCode, "num_additional_sub_streams_minus1" );  sei.m_numAdditionalSubStreams = uiCode + 1;
     785
     786  xResizeSubBitstreamPropertySeiArrays(sei);
     787  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
     788  {
     789    READ_CODE(  2, uiCode, "sub_bitstream_mode[i]"           ); sei.m_subBitstreamMode[i] = uiCode;
     790    READ_UVLC(     uiCode, "output_layer_set_idx_to_vps[i]"  ); sei.m_outputLayerSetIdxToVps[i] = uiCode;
     791    READ_CODE(  3, uiCode, "highest_sub_layer_id[i]"         ); sei.m_highestSublayerId[i] = uiCode;
     792    READ_CODE( 16, uiCode, "avg_bit_rate[i]"                 ); sei.m_avgBitRate[i] = uiCode;
     793    READ_CODE( 16, uiCode, "max_bit_rate[i]"                 ); sei.m_maxBitRate[i] = uiCode;
     794  }
     795  xParseByteAlign();
     796}
     797Void SEIReader::xResizeSubBitstreamPropertySeiArrays(SEISubBitstreamProperty &sei)
     798{
     799  sei.m_subBitstreamMode.resize( sei.m_numAdditionalSubStreams );
     800  sei.m_outputLayerSetIdxToVps.resize( sei.m_numAdditionalSubStreams );
     801  sei.m_highestSublayerId.resize( sei.m_numAdditionalSubStreams );
     802  sei.m_avgBitRate.resize( sei.m_numAdditionalSubStreams );
     803  sei.m_maxBitRate.resize( sei.m_numAdditionalSubStreams );
     804}
     805#endif
    768806
    769807Void SEIReader::xParseByteAlign()
  • trunk/source/Lib/TLibDecoder/SEIread.h

    r608 r872  
    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  Void xParseSEISOPDescription        (SEISOPDescription &sei, UInt payloadSize);
    7474  Void xParseSEIScalableNesting       (SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps);
     75#if H_MV_HLS_7_SEI_P0204_26
     76  Void  xParseSEISubBitstreamProperty   (SEISubBitstreamProperty &sei);
     77  Void  xResizeSubBitstreamPropertySeiArrays(SEISubBitstreamProperty &sei);
     78#endif
    7579  Void xParseByteAlign();
    7680};
  • trunk/source/Lib/TLibDecoder/SyntaxElementParser.cpp

    r655 r872  
    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/TLibDecoder/SyntaxElementParser.h

    r608 r872  
    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/TLibDecoder/TDecBinCoder.h

    r608 r872  
    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/TLibDecoder/TDecBinCoderCABAC.cpp

    r608 r872  
    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/TLibDecoder/TDecBinCoderCABAC.h

    r608 r872  
    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/TLibDecoder/TDecCAVLC.cpp

    r833 r872  
    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*
     
    366366
    367367  READ_FLAG( uiCode, "pps_extension_flag");
     368#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     369  if (uiCode)
     370  {
     371#if H_MV
     372    for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
     373    {
     374      READ_FLAG( uiCode, "pps_extension_type_flag" ); pcPPS->setPpsExtensionTypeFlag( i, uiCode == 1 );
     375#if H_3D
     376      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_3D || i == PPS_EX_T_ESC );
     377#else
     378      assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_ESC );
     379#endif
     380    }
     381   
     382
     383    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_MV ) )
     384    {
     385#if H_MV_HLS_7_POC_P0041
     386      READ_FLAG( uiCode, "poc_reset_info_present_flag" ); pcPPS->setPocResetInfoPresentFlag( uiCode == 1 );
     387#endif
     388    }
     389
     390#if H_3D
     391    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_3D ) ) // This probably needs to be aligned with Rext and SHVC
     392    {
     393      parsePPSExtension( pcPPS, pcVPS );
     394    }
     395#endif
     396
     397    if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_ESC ) )
     398    {
     399#endif
     400      while ( xMoreRbspData() )
     401      {
     402        READ_FLAG( uiCode, "pps_extension_data_flag");
     403      }
     404#if H_MV
     405    }
     406#endif
     407  }
     408#else
    368409  if (uiCode)
    369410  {
     
    382423#endif
    383424  }
     425#endif
    384426}
    385427
     
    807849  assert(uiCode <= 12);
    808850
     851#if H_MV_HLS_7_SPS_P0155_16_32
     852  if ( pcSPS->getLayerId() == 0 )
     853  { 
     854#endif
    809855  UInt subLayerOrderingInfoPresentFlag;
    810856  READ_FLAG(subLayerOrderingInfoPresentFlag, "sps_sub_layer_ordering_info_present_flag");
     
    842888    }
    843889  }
     890#if H_MV_HLS_7_SPS_P0155_16_32
     891  }
     892#endif
    844893
    845894  READ_UVLC( uiCode, "log2_min_coding_block_size_minus3" );
     
    848897  READ_UVLC( uiCode, "log2_diff_max_min_coding_block_size" );
    849898  pcSPS->setLog2DiffMaxMinCodingBlockSize(uiCode);
     899 
     900  if (pcSPS->getPTL()->getGeneralPTL()->getLevelIdc() >= Level::LEVEL5)
     901  {
     902    assert(log2MinCUSize + pcSPS->getLog2DiffMaxMinCodingBlockSize() >= 5);
     903  }
     904 
    850905  Int maxCUDepthDelta = uiCode;
    851906  pcSPS->setMaxCUWidth  ( 1<<(log2MinCUSize + maxCUDepthDelta) );
     
    9981053    READ_SVLC( iCode, "scaled_ref_layer_right_offset" ); pcSPS->setScaledRefLayerRightOffset( j, iCode );
    9991054    READ_SVLC( iCode, "scaled_ref_layer_bottom_offset" ); pcSPS->setScaledRefLayerBottomOffset( j, iCode );
     1055#if H_MV_HLS_7_RESERVED_FLAGS
     1056    READ_FLAG( uiCode, "sps_multilayer_ext_reserved_zero_flag[ i ]" );
     1057#endif
    10001058  }
    10011059}
     
    10331091  READ_FLAG(     uiCode,  "vps_temporal_id_nesting_flag" );       pcVPS->setTemporalNestingFlag( uiCode ? true:false );
    10341092  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
    1035 #if H_MV
     1093
     1094#if H_MV_HLS_7_VPS_P0125_24
     1095  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
     1096#else
     1097#if H_MV && !H_MV_HLS7_GEN
    10361098  READ_CODE( 16, uiCode,  "vps_extension_offset" );               
    10371099#else
    10381100  READ_CODE( 16, uiCode,  "vps_reserved_ffff_16bits" );           assert(uiCode == 0xffff);
     1101#endif
    10391102#endif
    10401103  parsePTL ( pcVPS->getPTL(), true, pcVPS->getMaxTLayers()-1);
     
    11481211  UInt uiCode;
    11491212  READ_FLAG( uiCode, "avc_base_layer_flag" );                     pcVPS->setAvcBaseLayerFlag( uiCode == 1 ? true : false );
    1150   READ_FLAG( uiCode, "vps_vui_present_flag" );                    pcVPS->setVpsVuiPresentFlag( uiCode == 1 );  if ( pcVPS->getVpsVuiPresentFlag() )
     1213
     1214#if !H_MV_HLS_7_VPS_P0307_23
     1215  READ_FLAG( uiCode, "vps_vui_present_flag" );                    pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
     1216  if ( pcVPS->getVpsVuiPresentFlag() )
    11511217  { 
    11521218  READ_CODE( 16, uiCode, "vps_vui_offset" );                      pcVPS->setVpsVuiOffset( uiCode );
    11531219  }
     1220#endif
    11541221
    11551222  READ_FLAG( uiCode, "splitting_flag" );                          pcVPS->setSplittingFlag( uiCode == 1 ? true : false );
     
    12271294  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
    12281295  {
    1229     for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
     1296    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    12301297    {
    12311298      READ_CODE( 3, uiCode, "sub_layers_vps_max_minus1" ); pcVPS->setSubLayersVpsMaxMinus1( i, uiCode );   
     
    12361303  else
    12371304  {
    1238     for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
     1305    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    12391306    {
    12401307      pcVPS->setSubLayersVpsMaxMinus1( i, pcVPS->getMaxTLayers( ) - 1);   
     
    12581325
    12591326  READ_FLAG( uiCode, "all_ref_layers_active_flag" );             pcVPS->setAllRefLayersActiveFlag( uiCode == 1 );
     1327#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    12601328  READ_CODE( 10, uiCode, "vps_number_layer_sets_minus1"      );  pcVPS->setVpsNumberLayerSetsMinus1    ( uiCode );
     1329#endif
     1330
     1331#if !H_MV_HLS_7_VPS_P0306_22
    12611332  READ_CODE( 6,  uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode );
    1262 
     1333#else
     1334  READ_UVLC( uiCode, "vps_num_profile_tier_level_minus1" );  pcVPS->setVpsNumProfileTierLevelMinus1( uiCode ); 
     1335#endif
    12631336  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
    12641337  {
    12651338    READ_FLAG(  uiCode, "vps_profile_present_flag[i]" );    pcVPS->setVpsProfilePresentFlag( i, uiCode == 1 );
     1339#if !H_MV_HLS_7_VPS_P0048_14
    12661340    if( !pcVPS->getVpsProfilePresentFlag( i ) )
    12671341    {
     
    12691343      pcVPS->checkProfileRefMinus1( i );     
    12701344    }
     1345#endif
    12711346    parsePTL ( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers()-1);
    12721347    if( !pcVPS->getVpsProfilePresentFlag( i ) )
    12731348    {
    12741349      TComPTL temp = *pcVPS->getPTL( i );
     1350#if H_MV_HLS_7_VPS_P0048_14
     1351      *pcVPS->getPTL( i ) = *pcVPS->getPTL( i - 1 );
     1352#else
    12751353      *pcVPS->getPTL( i ) = *pcVPS->getPTL( pcVPS->getProfileRefMinus1( i ) + 1 );
     1354#endif
    12761355      pcVPS->getPTL( i )->copyLevelFrom( &temp );
    12771356    }
    12781357  }
    12791358
     1359#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1360  READ_UVLC( uiCode, "num_add_output_layer_sets"      ); pcVPS->setNumAddOutputLayerSets( uiCode );
     1361  pcVPS->initTargetLayerIdLists( );
     1362  if( pcVPS->getNumOutputLayerSets() > 1)
     1363  {
     1364    READ_CODE( 2, uiCode, "default_target_output_layer_idc" ); pcVPS->setDefaultTargetOutputLayerIdc( std::min( uiCode, (UInt) 2 ) );   
     1365  } 
     1366
     1367#else
    12801368  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1;
    12811369
     
    12931381    pcVPS->checkDefaultOneTargetOutputLayerIdc();
    12941382  } 
     1383#endif
    12951384
    12961385  pcVPS->setOutputLayerFlag(0, 0, pcVPS->inferOutputLayerFlag( 0, 0 ));
    12971386  pcVPS->setOutputLayerSetIdxMinus1(0, -1);
     1387
     1388#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1389  pcVPS->deriveTargetLayerIdList( 0 );
     1390  for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
     1391  {
     1392    if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )   
     1393#else
    12981394  for( Int i = 1; i < numOutputLayerSets; i++ )
    12991395  {
    13001396    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
     1397#endif
    13011398    {       
    13021399      READ_UVLC( uiCode,      "output_layer_set_idx_minus1[i]" ); pcVPS->setOutputLayerSetIdxMinus1( i, uiCode );
     1400#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1401    }
     1402
     1403    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
     1404    {       
     1405      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
     1406      {
     1407        READ_FLAG( uiCode, "output_layer_flag" ); pcVPS->setOutputLayerFlag( i, j, uiCode == 1 );
     1408      }
     1409    }
     1410    else
     1411    {
     1412      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
     1413      {             
     1414        pcVPS->setOutputLayerFlag(i,j, pcVPS->inferOutputLayerFlag( i, j ));
     1415      }
     1416    }
     1417    pcVPS->deriveTargetLayerIdList( i );
     1418#else
    13031419      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1; j++ )
    13041420      {
     
    13141430      }
    13151431    }
    1316 
     1432#endif
    13171433    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
    13181434    {     
    13191435      READ_CODE( pcVPS->getProfileLevelTierIdxLen(), uiCode,"profile_level_tier_idx[ i ]" );   pcVPS->setProfileLevelTierIdx( i , uiCode );
    13201436    }
     1437
     1438#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1439    if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
     1440    {
     1441      READ_FLAG( uiCode, "alt_output_layer_flag[ i ]" ); pcVPS->setAltOutputLayerFlag( i, uiCode == 1 );
     1442    }
     1443  }
     1444#else
    13211445  }
    13221446  if( pcVPS->getMaxLayersMinus1() > 0 )
     
    13241448    READ_FLAG( uiCode, "alt_output_layer_flag" ); pcVPS->setAltOutputLayerFlag( uiCode == 1 );
    13251449  }
     1450#endif
     1451
     1452#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    13261453  pcVPS->deriveTargetLayerIdLists();
     1454#endif
     1455
    13271456  READ_FLAG( uiCode, "rep_format_idx_present_flag" ); pcVPS->setRepFormatIdxPresentFlag( uiCode == 1 );
    13281457  if ( pcVPS->getRepFormatIdxPresentFlag() )
    13291458  {
     1459#if H_MV_HLS_7_VPS_P0306_22
     1460    READ_UVLC( uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
     1461#else
    13301462    READ_CODE( 4, uiCode, "vps_num_rep_formats_minus1" ); pcVPS->setVpsNumRepFormatsMinus1( uiCode );
     1463#endif
    13311464  }
    13321465
     
    13461479      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
    13471480      {
     1481#if H_MV_HLS_7_VPS_P0306_22
     1482        READ_CODE( pcVPS->getVpsRepFormatIdxLen(), uiCode, "vps_rep_format_idx[i]" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
     1483#else
    13481484        READ_CODE( 8, uiCode, "vps_rep_format_idx" ); pcVPS->setVpsRepFormatIdx( i, uiCode );
     1485#endif
    13491486      }
    13501487    }
     
    13521489
    13531490  READ_FLAG( uiCode, "max_one_active_ref_layer_flag" ); pcVPS->setMaxOneActiveRefLayerFlag ( uiCode == 1 );
     1491#if H_MV_HLS7_GEN
     1492  READ_FLAG( uiCode, "vps_poc_lsb_aligned_flag" ); pcVPS->setVpsPocLsbAlignedFlag( uiCode == 1 );
     1493#endif
    13541494  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
    13551495  {
     
    13601500  }
    13611501
     1502#if H_MV_HLS_7_RESERVED_FLAGS
     1503  READ_FLAG( uiCode, "vps_reserved_zero_flag" );
     1504#endif
    13621505  parseDpbSize( pcVPS );
    13631506
     
    13881531  } 
    13891532
     1533#if H_MV_HLS_7_VPS_P0307_23
     1534  READ_UVLC( uiCode, "vps_non_vui_extension_length" ); pcVPS->setVpsNonVuiExtensionLength( uiCode );
     1535  for ( Int i = 1; i <= pcVPS->getVpsNonVuiExtensionLength(); i++ )
     1536  {
     1537    READ_CODE( 8, uiCode, "vps_non_vui_extension_data_byte" );
     1538  }
     1539  READ_FLAG( uiCode, "vps_vui_present_flag" );  pcVPS->setVpsVuiPresentFlag( uiCode == 1 );
     1540#endif
     1541#if !H_MV_HLS_7_RESERVED_FLAGS
    13901542  READ_FLAG( uiCode, "vps_shvc_reserved_zero_flag" );
    1391 
     1543#endif
    13921544  if( pcVPS->getVpsVuiPresentFlag() )
    13931545  {
     
    13951547    parseVPSVUI( pcVPS );
    13961548  }     
     1549#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
     1550  {
     1551    TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
     1552    assert( pcVPSVUI );
     1553    pcVPSVUI->inferVpsVui( false );
     1554  }
     1555#endif
    13971556
    13981557  pcVPS->checkVPSExtensionSyntax();
     
    14421601    READ_FLAG( uiCode, "cross_layer_irap_aligned_flag" ); pcVPSVUI->setCrossLayerIrapAlignedFlag( uiCode == 1 );
    14431602  }
     1603#if H_MV_HLS_7_MISC_P0068_21
     1604  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
     1605  {
     1606    READ_FLAG( uiCode, "all_layers_idr_aligned_flag" ); pcVPSVUI->setAllLayersIdrAlignedFlag( uiCode == 1 );
     1607  }
     1608#endif
    14441609  READ_FLAG( uiCode, "bit_rate_present_vps_flag" ); pcVPSVUI->setBitRatePresentVpsFlag( uiCode == 1 );
    14451610  READ_FLAG( uiCode, "pic_rate_present_vps_flag" ); pcVPSVUI->setPicRatePresentVpsFlag( uiCode == 1 );
    14461611  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
    14471612  {
     1613#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1614    for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
     1615#else
    14481616    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
     1617#endif
    14491618    {
    14501619      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ )
     
    14711640    }
    14721641  }
     1642
     1643#if H_MV_HLS_7_VPS_P0076_15
     1644  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
     1645  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     1646  {
     1647    READ_CODE( 4, uiCode, "vps_num_video_signal_info_minus1" ); pcVPSVUI->setVpsNumVideoSignalInfoMinus1( uiCode );
     1648  }
     1649  else
     1650  {
     1651    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() );
     1652  }
     1653
     1654  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
     1655  {
     1656    assert( pcVPSVUI->getVideoSignalInfo( i ) == NULL );
     1657    TComVideoSignalInfo* curVideoSignalInfo = new TComVideoSignalInfo();     
     1658    parseVideoSignalInfo( curVideoSignalInfo );
     1659    pcVPSVUI->setVideoSignalInfo(i, curVideoSignalInfo );
     1660  }
     1661
     1662  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
     1663  {
     1664    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
     1665    {
     1666      READ_CODE( 4, uiCode, "vps_video_signal_info_idx" ); pcVPSVUI->setVpsVideoSignalInfoIdx( i, uiCode );
     1667      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
     1668    }
     1669  }
     1670  else
     1671  {
     1672    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
     1673    {
     1674      pcVPSVUI->setVpsVideoSignalInfoIdx( i, pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i );
     1675    }
     1676  }
     1677#endif
    14731678
    14741679  READ_FLAG( uiCode, "tiles_not_in_use_flag" ); pcVPSVUI->setTilesNotInUseFlag( uiCode == 1 );
     
    15071712  }
    15081713
     1714#if H_MV_HLS_7_RESERVED_FLAGS
     1715  READ_CODE( 3, uiCode, "vps_vui_reserved_zero_3bits" );
     1716#endif
     1717
    15091718  READ_FLAG( uiCode, "ilp_restricted_ref_layers_flag" ); pcVPSVUI->setIlpRestrictedRefLayersFlag( uiCode == 1 );
    15101719
     
    15281737  }
    15291738
     1739#if !H_MV_HLS_7_VPS_P0076_15
    15301740  READ_FLAG( uiCode, "video_signal_info_idx_present_flag" ); pcVPSVUI->setVideoSignalInfoIdxPresentFlag( uiCode == 1 );
    15311741  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     
    15611771    }
    15621772  }
     1773#endif
    15631774  READ_FLAG( uiCode, "vps_vui_bsp_hrd_present_flag" ); pcVPSVUI->setVpsVuiBspHrdPresentFlag( uiCode == 1 );
    15641775  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
     
    15661777    parseVpsVuiBspHrdParameters( pcVPS );
    15671778}
     1779#if H_MV_HLS_7_MISC_P0182_13
     1780  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     1781  {
     1782    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 )
     1783    {
     1784      READ_FLAG( uiCode, "base_layer_parameter_set_compatibility_flag" ); pcVPSVUI->setBaseLayerParameterSetCompatibilityFlag( i, uiCode == 1 );
     1785    }
     1786  }
     1787#endif
    15681788}
    15691789
     
    16441864  { 
    16451865    READ_FLAG( uiCode, "sub_layer_flag_info_present_flag" ); dpbSize->setSubLayerFlagInfoPresentFlag( i, uiCode == 1 );
    1646 
     1866#if H_MV_HLS_7_HRD_P0156_7
     1867    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
     1868#else
    16471869    for( Int j = 0; j  <=  vps->getMaxTLayers() - 1 ; j++ )
     1870#endif
    16481871    { 
    16491872      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
     
    16531876      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
    16541877      { 
     1878#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1879        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
     1880#else
    16551881        for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
     1882#endif
    16561883        {
    16571884          READ_UVLC( uiCode, "max_vps_dec_pic_buffering_minus1" ); dpbSize->setMaxVpsDecPicBufferingMinus1( i, k, j, uiCode );
    16581885        }
    16591886        READ_UVLC( uiCode, "max_vps_num_reorder_pics" ); dpbSize->setMaxVpsNumReorderPics( i, j, uiCode );
     1887#if H_MV_HLS7_GEN
     1888        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) )
     1889        {
     1890          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
     1891          {
     1892            READ_UVLC( uiCode, "max_vps_layer_dec_pic_buff_minus1" ); dpbSize->setMaxVpsLayerDecPicBuffMinus1( i, k, j, uiCode );
     1893          }
     1894        }
     1895#endif
    16601896        READ_UVLC( uiCode, "max_vps_latency_increase_plus1" ); dpbSize->setMaxVpsLatencyIncreasePlus1( i, j, uiCode );
    16611897      }
     
    16981934#if H_3D_SPIVMP
    16991935#if SEC_SPIVMP_MCP_SIZE_G0077
    1700         READ_UVLC (uiCode, "log2_sub_PU_size_minus3");     pcVPS->setSubPULog2Size(i, uiCode+3);
     1936        READ_UVLC (uiCode, "log2_sub_PU_size_minus3[i]");     pcVPS->setSubPULog2Size(i, uiCode+3);
    17011937#else
    17021938        READ_UVLC (uiCode, "log2_sub_PU_size_minus2");     pcVPS->setSubPULog2Size(i, uiCode+2);
     
    17551991  for (UInt viewIndex=0; viewIndex<pcVPS->getNumViews(); viewIndex++)
    17561992  {
     1993#if FIX_CAM_PARS_COLLECTOR
     1994    pcVPS->setCamParPresent         ( viewIndex, false );
     1995    pcVPS->setHasCamParInSliceHeader( viewIndex, false );
     1996#endif
    17571997    READ_FLAG( uiCode, "cp_present_flag[i]" );                  bCamParPresentFlag = ( uiCode == 1);
    17581998    if ( bCamParPresentFlag )
     
    18842124    rpcSlice->checkCrossLayerBlaFlag( );
    18852125
     2126#if !H_MV_HLS7_GEN
    18862127    if ( rpcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
    18872128    {
     
    18892130      READ_FLAG( uiCode, "poc_reset_flag" ); rpcSlice->setPocResetFlag( uiCode == 1 );
    18902131    }
     2132#endif
    18912133
    18922134    for (; esb < rpcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
     
    24862728  if(pps->getSliceHeaderExtensionPresentFlag())
    24872729  {
     2730#if !H_MV_HLS_7_POC_P0041   
    24882731    READ_UVLC(uiCode,"slice_header_extension_length");
    2489 
    24902732    for(Int i=0; i<uiCode; i++)
    24912733    {
     
    24942736    }
    24952737  }
     2738#else
     2739#if H_MV
     2740    READ_UVLC( uiCode, "slice_segment_header_extension_length" ); rpcSlice->setSliceSegmentHeaderExtensionLength( uiCode );
     2741    UInt posFollSliceSegHeaderExtLen = m_pcBitstream->getNumBitsRead();
     2742
     2743    if( rpcSlice->getPPS()->getPocResetInfoPresentFlag() )
     2744    {
     2745      READ_CODE( 2, uiCode, "poc_reset_idc" ); rpcSlice->setPocResetIdc( uiCode );
     2746    }
     2747    else
     2748    {
     2749      rpcSlice->setPocResetIdc( 0 );
     2750    }
     2751
     2752    if( rpcSlice->getPocResetIdc() !=  0 )
     2753    {
     2754      READ_CODE( 6, uiCode, "poc_reset_period_id" ); rpcSlice->setPocResetPeriodId( uiCode );
     2755    }
     2756    else
     2757    {
     2758      // TODO Copy poc_reset_period from earlier picture
     2759      rpcSlice->setPocResetPeriodId( 0 );
     2760    }
     2761   
     2762    if( rpcSlice->getPocResetIdc() ==  3 )
     2763    {
     2764      READ_FLAG( uiCode, "full_poc_reset_flag" ); rpcSlice->setFullPocResetFlag( uiCode == 1 );
     2765      READ_CODE( rpcSlice->getPocLsbValLen() , uiCode, "poc_lsb_val" ); rpcSlice->setPocLsbVal( uiCode );
     2766    }         
     2767
     2768    // Derive the value of PocMsbValRequiredFlag
     2769    rpcSlice->setPocMsbValRequiredFlag( rpcSlice->getCraPicFlag() || rpcSlice->getBlaPicFlag()
     2770                                          /* || TODO related to vps_poc_lsb_aligned_flag */
     2771                                          );
     2772
     2773    if( !rpcSlice->getPocMsbValRequiredFlag() /* TODO &&  rpcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     2774    {
     2775      READ_FLAG( uiCode, "poc_msb_val_present_flag" ); rpcSlice->setPocMsbValPresentFlag( uiCode == 1 );
     2776    }
     2777    else
     2778    {
     2779      if( rpcSlice->getPocMsbValRequiredFlag() )
     2780      {
     2781        rpcSlice->setPocMsbValPresentFlag( true );
     2782      }
     2783      else
     2784      {
     2785        rpcSlice->setPocMsbValPresentFlag( false );
     2786      }
     2787    }
     2788
     2789   
     2790    if( rpcSlice->getPocMsbValPresentFlag() )
     2791    {
     2792      READ_UVLC( uiCode, "poc_msb_val" ); rpcSlice->setPocMsbVal( uiCode );
     2793    }
     2794
     2795    while( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) < rpcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
     2796    {
     2797     READ_FLAG( uiCode, "slice_segment_header_extension_data_bit" );
     2798    }
     2799    assert( ( m_pcBitstream->getNumBitsRead() - posFollSliceSegHeaderExtLen ) == rpcSlice->getSliceSegmentHeaderExtensionLength() * 8  );
     2800#else
     2801    READ_UVLC( uiCode, "slice_header_extension_length" );
     2802    for(Int i=0; i<uiCode; i++)
     2803    {
     2804      UInt ignore;
     2805      READ_CODE(8,ignore,"slice_header_extension_data_byte");
     2806    }
     2807  }
     2808#endif
     2809#endif
     2810  }
     2811
    24962812
    24972813  m_pcBitstream->readByteAlignment();
  • trunk/source/Lib/TLibDecoder/TDecCAVLC.h

    r833 r872  
    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/TLibDecoder/TDecCu.cpp

    r833 r872  
    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 *
     
    640640  m_ppcCU[uiDepth]->copySubCU( pcCU, uiAbsPartIdx, uiDepth );
    641641 
     642#if H_MV_ENC_DEC_TRAC
     643#if ENC_DEC_TRACE
     644  stopAtPos  ( m_ppcCU[uiDepth]->getSlice()->getPOC(),
     645    m_ppcCU[uiDepth]->getSlice()->getLayerId(),
     646    m_ppcCU[uiDepth]->getCUPelX(),
     647    m_ppcCU[uiDepth]->getCUPelY(),
     648    m_ppcCU[uiDepth]->getWidth(0),
     649    m_ppcCU[uiDepth]->getHeight(0) );
     650#endif
     651#endif
     652
    642653  switch( m_ppcCU[uiDepth]->getPredictionMode(0) )
    643654  {
     
    918929#endif
    919930 
     931#if H_3D && UPDATE_HM13
     932  Bool useDltFlag = (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps());
     933
     934  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) || useDltFlag )
     935#else
     936  if ( pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth ) )
     937#endif
     938  {
    920939  //===== inverse transform =====
    921940  m_pcTrQuant->setQPforQuant  ( pcCU->getQP(0), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
    922941
    923942  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)TEXT_LUMA];
    924   assert(scalingListType < 6);
     943    assert(scalingListType < SCALING_LIST_NUM);
    925944  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA, pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
    926945
     
    936955    {
    937956#if H_3D
     957#if UPDATE_HM13
     958      if ( useDltFlag )
     959#else
    938960      if( (isDimMode( uiLumaPredMode ) || uiLumaPredMode == HOR_IDX || uiLumaPredMode == VER_IDX || uiLumaPredMode == DC_IDX) && pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getPPS()->getDLT()->getUseDLTFlag(pcCU->getSlice()->getLayerIdInVps()) )
     961#endif
    939962      {
    940963        pReco    [ uiX ] = pcCU->getSlice()->getPPS()->getDLT()->idx2DepthValue( pcCU->getSlice()->getLayerIdInVps(), Clip3( 0, pcCU->getSlice()->getPPS()->getDLT()->getNumDepthValues( pcCU->getSlice()->getLayerIdInVps() ) - 1, pcCU->getSlice()->getPPS()->getDLT()->depthValue2idx( pcCU->getSlice()->getLayerIdInVps(), pPred[ uiX ] ) + pResi[ uiX ] ) );
     
    953976    pReco     += uiStride;
    954977    pRecIPred += uiRecIPredStride;
     978  }
     979}
     980  else
     981  {
     982    //===== reconstruction =====
     983    Pel* pPred      = piPred;
     984    Pel* pReco      = piReco;
     985    Pel* pRecIPred  = piRecIPred;
     986    for ( Int y = 0; y < uiHeight; y++ )
     987    {
     988      for ( Int x = 0; x < uiWidth; x++ )
     989      {
     990        pReco    [ x ] = pPred[ x ];
     991        pRecIPred[ x ] = pReco[ x ];
     992      }
     993      pPred     += uiStride;
     994      pReco     += uiStride;
     995      pRecIPred += uiRecIPredStride;
     996    }
    955997  }
    956998}
     
    10221064  }
    10231065
     1066  if ( pcCU->getCbf( uiAbsPartIdx, eText, uiTrDepth ) )
     1067  {
    10241068  //===== inverse transform =====
    10251069  Int curChromaQpOffset;
     
    10351079
    10361080  Int scalingListType = (pcCU->isIntra(uiAbsPartIdx) ? 0 : 3) + g_eTTable[(Int)eText];
    1037   assert(scalingListType < 6);
     1081    assert(scalingListType < SCALING_LIST_NUM);
    10381082  m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), eText, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
    10391083
     
    10541098    pReco     += uiStride;
    10551099    pRecIPred += uiRecIPredStride;
     1100  }
     1101}
     1102  else
     1103  {
     1104    //===== reconstruction =====
     1105    Pel* pPred      = piPred;
     1106    Pel* pReco      = piReco;
     1107    Pel* pRecIPred  = piRecIPred;
     1108    for ( Int y = 0; y < uiHeight; y++ )
     1109    {
     1110      for ( Int x = 0; x < uiWidth; x++ )
     1111      {
     1112        pReco    [ x ] = pPred[ x ];
     1113        pRecIPred[ x ] = pReco[ x ];
     1114      }
     1115      pPred     += uiStride;
     1116      pReco     += uiStride;
     1117      pRecIPred += uiRecIPredStride;
     1118    }   
    10561119  }
    10571120}
  • trunk/source/Lib/TLibDecoder/TDecCu.h

    r833 r872  
    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/TLibDecoder/TDecEntropy.cpp

    r833 r872  
    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 *
     
    580580}
    581581
    582 Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP)
     582Void TDecEntropy::xDecodeTransform( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int quadtreeTULog2MinSizeInCU)
    583583{
    584584  UInt uiSubdiv;
     
    604604  else if( (pcCU->getSlice()->getSPS()->getQuadtreeTUMaxDepthInter() == 1) && (pcCU->getPredictionMode(uiAbsPartIdx) == MODE_INTER) && ( pcCU->getPartitionSize(uiAbsPartIdx) != SIZE_2Nx2N ) && (uiDepth == pcCU->getDepth(uiAbsPartIdx)) )
    605605  {
    606     uiSubdiv = (uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx));
     606    uiSubdiv = (uiLog2TrafoSize > quadtreeTULog2MinSizeInCU);
    607607  }
    608608  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     
    614614    uiSubdiv = 0;
    615615  }
    616   else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     616  else if( uiLog2TrafoSize == quadtreeTULog2MinSizeInCU )
    617617  {
    618618    uiSubdiv = 0;
     
    620620  else
    621621  {
    622     assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     622    assert( uiLog2TrafoSize > quadtreeTULog2MinSizeInCU );
    623623    m_pcEntropyDecoderIf->parseTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    624624  }
     
    666666    for( Int i = 0; i < 4; i++ )
    667667    {
    668       xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP );
     668      xDecodeTransform( pcCU, offsetLuma, offsetChroma, uiAbsPartIdx, uiDepth, width, height, uiTrIdx, bCodeDQP, quadtreeTULog2MinSizeInCU );
    669669      uiYCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_LUMA, uiTrDepth+1 );
    670670      uiUCbf |= pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth+1 );
     
    886886   
    887887  }
    888   xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP );
     888
     889  Int getQuadtreeTULog2MinSizeInCU = pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx);
     890
     891  xDecodeTransform( pcCU, uiLumaOffset, uiChromaOffset, uiAbsPartIdx, uiDepth, uiWidth, uiHeight, 0, bCodeDQP, getQuadtreeTULog2MinSizeInCU );
    889892}
    890893
  • trunk/source/Lib/TLibDecoder/TDecEntropy.h

    r833 r872  
    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 *
     
    210210 
    211211private:
    212   Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP );
     212  Void xDecodeTransform        ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP, Int getQuadtreeTULog2MinSizeInCU );
    213213
    214214public:
  • trunk/source/Lib/TLibDecoder/TDecGop.cpp

    r655 r872  
    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 *
     
    112112  //-- For time output for each slice
    113113  long iBeforeTime = clock();
    114  
    115   UInt uiStartCUAddr   = pcSlice->getSliceSegmentCurStartCUAddr();
    116 
    117   UInt uiSliceStartCuAddr = pcSlice->getSliceCurStartCUAddr();
    118   if(uiSliceStartCuAddr == uiStartCUAddr)
    119   {
    120     m_sliceStartCUAddress.push_back(uiSliceStartCuAddr);
    121   }
    122 
    123114  m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC );
    124115  m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder);
     
    147138  m_pcEntropyDecoder->setBitstream      ( ppcSubstreams[0] );
    148139  m_pcEntropyDecoder->resetEntropy      (pcSlice);
    149 
    150   if(uiSliceStartCuAddr == uiStartCUAddr)
    151   {
    152     m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag());
    153   }
    154140#if H_3D_NBDV
    155141  if(pcSlice->getViewIndex() && !pcSlice->getIsDepth()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
     
    199185  m_pcLoopFilter->setCfg(bLFCrossTileBoundary);
    200186  m_pcLoopFilter->loopFilterPic( rpcPic );
    201 
    202   if(pcSlice->getSPS()->getUseSAO())
    203   {
    204     m_sliceStartCUAddress.push_back(rpcPic->getNumCUsInFrame()* rpcPic->getNumPartInCU());
    205     rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary);
    206   }
    207 
    208187  if( pcSlice->getSPS()->getUseSAO() )
    209188  {
    210     {
    211       SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
    212       saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
    213       saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
    214       m_pcSAO->setSaoLcuBasedOptimization(1);
    215       m_pcSAO->createPicSaoInfo(rpcPic);
    216       m_pcSAO->SAOProcess(saoParam);
    217       m_pcSAO->PCMLFDisableProcess(rpcPic);
    218       m_pcSAO->destroyPicSaoInfo();
    219     }
    220   }
    221 
    222   if(pcSlice->getSPS()->getUseSAO())
    223   {
    224     rpcPic->destroyNonDBFilterInfo();
     189    m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam());
     190    m_pcSAO->SAOProcess(rpcPic);
     191    m_pcSAO->PCMLFDisableProcess(rpcPic);
    225192  }
    226193#if H_3D
     
    284251  rpcPic->setOutputMark(true);
    285252  rpcPic->setReconMark(true);
    286   m_sliceStartCUAddress.clear();
    287   m_LFCrossSliceBoundaryFlag.clear();
    288253}
    289254
  • trunk/source/Lib/TLibDecoder/TDecGop.h

    r608 r872  
    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  Int                   m_decodedPictureHashSEIEnabled;  ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message
    8484
    85   //! list that contains the CU address of each slice plus the end address
    86   std::vector<Int> m_sliceStartCUAddress;
    87   std::vector<Bool> m_LFCrossSliceBoundaryFlag;
    88 
    8985public:
    9086  TDecGop();
  • trunk/source/Lib/TLibDecoder/TDecSbac.cpp

    r833 r872  
    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)
     
    155154#endif
    156155  m_cCUPartSizeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PART_SIZE );
    157   m_cCUAMPSCModel.initBuffer             ( sliceType, qp, (UChar*)INIT_CU_AMP_POS );
    158156  m_cCUPredModeSCModel.initBuffer        ( sliceType, qp, (UChar*)INIT_PRED_MODE );
    159157  m_cCUIntraPredSCModel.initBuffer       ( sliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
     
    236234#endif
    237235  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    238   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
    239236  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    240237  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
     
    906903        if (eMode == SIZE_2NxN)
    907904        {
    908           m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
     905        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    909906          if (uiSymbol == 0)
    910907          {
     
    915912        else if (eMode == SIZE_Nx2N)
    916913        {
    917           m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUAMPSCModel.get( 0, 0, 0 ));
     914        m_pcTDecBinIf->decodeBin(uiSymbol, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    918915          if (uiSymbol == 0)
    919916          {
     
    20092006    if (uiCode == 0)
    20102007    {
    2011       ruiVal = 5;
     2008      ruiVal = 1;
    20122009    }
    20132010    else
    20142011    {
    2015       ruiVal = 1;
    2016     }
    2017   }
    2018 }
    2019 
    2020 inline Void copySaoOneLcuParam(SaoLcuParam* psDst,  SaoLcuParam* psSrc)
    2021 {
    2022   Int i;
    2023   psDst->partIdx = psSrc->partIdx;
    2024   psDst->typeIdx    = psSrc->typeIdx;
    2025   if (psDst->typeIdx != -1)
    2026   {
    2027     psDst->subTypeIdx = psSrc->subTypeIdx ;
    2028     psDst->length  = psSrc->length;
    2029     for (i=0;i<psDst->length;i++)
    2030     {
    2031       psDst->offset[i] = psSrc->offset[i];
    2032     }
    2033   }
    2034   else
    2035   {
    2036     psDst->length  = 0;
    2037     for (i=0;i<SAO_BO_LEN;i++)
    2038     {
    2039       psDst->offset[i] = 0;
    2040     }
    2041   }
    2042 }
    2043 
    2044 Void TDecSbac::parseSaoOffset(SaoLcuParam* psSaoLcuParam, UInt compIdx)
     2012      ruiVal = 2;
     2013    }
     2014  }
     2015}
     2016
     2017Void TDecSbac::parseSaoSign(UInt& val)
     2018{
     2019  m_pcTDecBinIf->decodeBinEP ( val );
     2020}
     2021
     2022Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam
     2023                                , Bool* sliceEnabled
     2024                                , Bool leftMergeAvail
     2025                                , Bool aboveMergeAvail
     2026                                )
    20452027{
    20462028  UInt uiSymbol;
    2047   static Int iTypeLength[MAX_NUM_SAO_TYPE] =
    2048   {
    2049     SAO_EO_LEN,
    2050     SAO_EO_LEN,
    2051     SAO_EO_LEN,
    2052     SAO_EO_LEN,
    2053     SAO_BO_LEN
    2054   };
    2055 
    2056   if (compIdx==2)
    2057   {
    2058     uiSymbol = (UInt)( psSaoLcuParam->typeIdx + 1);
    2059   }
    2060   else
    2061   {
    2062     parseSaoTypeIdx(uiSymbol);
    2063   }
    2064   psSaoLcuParam->typeIdx = (Int)uiSymbol - 1;
    2065   if (uiSymbol)
    2066   {
    2067     psSaoLcuParam->length = iTypeLength[psSaoLcuParam->typeIdx];
    2068 
    2069     Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
    2070     Int offsetTh = 1 << min(bitDepth - 5,5);
    2071 
    2072     if( psSaoLcuParam->typeIdx == SAO_BO )
    2073     {
    2074       for(Int i=0; i< psSaoLcuParam->length; i++)
    2075       {
    2076         parseSaoMaxUvlc(uiSymbol, offsetTh -1 );
    2077         psSaoLcuParam->offset[i] = uiSymbol;
     2029
     2030  Bool isLeftMerge = false;
     2031  Bool isAboveMerge= false;
     2032
     2033  if(leftMergeAvail)
     2034  {
     2035    parseSaoMerge(uiSymbol); //sao_merge_left_flag
     2036    isLeftMerge = (uiSymbol?true:false);
     2037  }
     2038
     2039  if( aboveMergeAvail && !isLeftMerge)
     2040  {
     2041    parseSaoMerge(uiSymbol); //sao_merge_up_flag
     2042    isAboveMerge = (uiSymbol?true:false);
     2043  }
     2044
     2045  if(isLeftMerge || isAboveMerge) //merge mode
     2046      {
     2047    saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE;
     2048    saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE;
    20782049      }   
    2079       for(Int i=0; i< psSaoLcuParam->length; i++)
    2080       {
    2081         if (psSaoLcuParam->offset[i] != 0)
    2082         {
    2083           m_pcTDecBinIf->decodeBinEP ( uiSymbol);
    2084           if (uiSymbol)
     2050  else //new or off mode
     2051      {
     2052    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     2053        {
     2054      SAOOffset& ctbParam = saoBlkParam[compIdx];
     2055
     2056      if(!sliceEnabled[compIdx])
    20852057          {
    2086             psSaoLcuParam->offset[i] = -psSaoLcuParam->offset[i] ;
    2087           }
    2088         }
    2089       }
    2090       parseSaoUflc(5, uiSymbol );
    2091       psSaoLcuParam->subTypeIdx = uiSymbol;
    2092     }
    2093     else if( psSaoLcuParam->typeIdx < 4 )
    2094     {
    2095       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[0] = uiSymbol;
    2096       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[1] = uiSymbol;
    2097       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[2] = -(Int)uiSymbol;
    2098       parseSaoMaxUvlc(uiSymbol, offsetTh -1 ); psSaoLcuParam->offset[3] = -(Int)uiSymbol;
    2099      if (compIdx != 2)
     2058        //off
     2059        ctbParam.modeIdc = SAO_MODE_OFF;
     2060        continue;
     2061        }
     2062
     2063      //type
     2064      if(compIdx == SAO_Y || compIdx == SAO_Cb)
     2065    {
     2066        parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma
     2067
     2068        assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2);
     2069
     2070        if(uiSymbol ==0) //OFF
    21002071     {
    2101        parseSaoUflc(2, uiSymbol );
    2102        psSaoLcuParam->subTypeIdx = uiSymbol;
    2103        psSaoLcuParam->typeIdx += psSaoLcuParam->subTypeIdx;
    2104      }
     2072          ctbParam.modeIdc = SAO_MODE_OFF;
    21052073   }
    2106   }
    2107   else
    2108   {
    2109     psSaoLcuParam->length = 0;
    2110   }
    2111 }
    2112 
    2113 Void TDecSbac::parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
    2114 {
    2115   Int iAddr = pcCU->getAddr();
    2116   UInt uiSymbol;
    2117   for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
    2118   {
    2119     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag    = 0;
    2120     pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag  = 0;
    2121     pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx     = 0;
    2122     pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx        = -1;
    2123     pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[0]     = 0;
    2124     pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[1]     = 0;
    2125     pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[2]     = 0;
    2126     pSaoParam->saoLcuParam[iCompIdx][iAddr].offset[3]     = 0;
    2127 
    2128   }
    2129  if (pSaoParam->bSaoFlag[0] || pSaoParam->bSaoFlag[1] )
    2130   {
    2131     if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
    2132     {
    2133       parseSaoMerge(uiSymbol);
    2134       pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag = (Bool)uiSymbol; 
    2135     }
    2136     if (pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag==0)
    2137     {
    2138       if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
    2139       {
    2140         parseSaoMerge(uiSymbol);
    2141         pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag = (Bool)uiSymbol;
    2142       }
    2143     }
    2144   }
    2145 
    2146   for (Int iCompIdx=0; iCompIdx<3; iCompIdx++)
    2147   {
    2148     if ((iCompIdx == 0  && pSaoParam->bSaoFlag[0]) || (iCompIdx > 0  && pSaoParam->bSaoFlag[1]) )
    2149     {
    2150       if (rx>0 && iCUAddrInSlice!=0 && allowMergeLeft)
    2151       {
    2152         pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = pSaoParam->saoLcuParam[0][iAddr].mergeLeftFlag;
    2153       }
    2154       else
    2155       {
    2156         pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag = 0;
    2157       }
    2158 
    2159       if (pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeLeftFlag==0)
    2160       {
    2161         if ((ry > 0) && (iCUAddrUpInSlice>=0) && allowMergeUp)
    2162         {
    2163           pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = pSaoParam->saoLcuParam[0][iAddr].mergeUpFlag;
     2074        else if(uiSymbol == 1) //BO
     2075        {
     2076          ctbParam.modeIdc = SAO_MODE_NEW;
     2077          ctbParam.typeIdc = SAO_TYPE_START_BO;
     2078  }
     2079        else //2, EO
     2080  {
     2081          ctbParam.modeIdc = SAO_MODE_NEW;
     2082          ctbParam.typeIdc = SAO_TYPE_START_EO;
     2083        }
     2084
     2085  }
     2086      else //Cr, follow Cb SAO type
     2087      {
     2088        ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc;
     2089        ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     2090}
     2091
     2092      if(ctbParam.modeIdc == SAO_MODE_NEW)
     2093{
     2094        Int offset[4];
     2095        for(Int i=0; i< 4; i++)
     2096  {
     2097          parseSaoMaxUvlc(uiSymbol,  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     2098          offset[i] = (Int)uiSymbol;
     2099  }
     2100
     2101        if(ctbParam.typeIdc == SAO_TYPE_START_BO)
     2102  {
     2103          for(Int i=0; i< 4; i++)
     2104    {
     2105            if(offset[i] != 0)
     2106    {
     2107              parseSaoSign(uiSymbol); //sao_offset_sign
     2108              if(uiSymbol)
     2109      {
     2110                offset[i] = -offset[i];
     2111      }
     2112    }
     2113  }
     2114          parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position
     2115          ctbParam.typeAuxInfo = uiSymbol;
     2116
     2117          for(Int i=0; i<4; i++)
     2118      {
     2119            ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i];
     2120      }
     2121
     2122        }
     2123        else //EO
     2124        {
     2125          ctbParam.typeAuxInfo = 0;
     2126
     2127          if(compIdx == SAO_Y || compIdx == SAO_Cb)
     2128        {
     2129            parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma
     2130            ctbParam.typeIdc += uiSymbol;
    21642131        }
    21652132        else
    21662133        {
    2167           pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag = 0;
    2168         }
    2169         if (!pSaoParam->saoLcuParam[iCompIdx][iAddr].mergeUpFlag)
    2170         {
    2171           pSaoParam->saoLcuParam[2][iAddr].typeIdx = pSaoParam->saoLcuParam[1][iAddr].typeIdx;
    2172           parseSaoOffset(&(pSaoParam->saoLcuParam[iCompIdx][iAddr]), iCompIdx);
    2173         }
    2174         else
    2175         {
    2176           copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr], &pSaoParam->saoLcuParam[iCompIdx][iAddr-pSaoParam->numCuInWidth]);
    2177         }
    2178       }
    2179       else
    2180       {
    2181         copySaoOneLcuParam(&pSaoParam->saoLcuParam[iCompIdx][iAddr],  &pSaoParam->saoLcuParam[iCompIdx][iAddr-1]);
    2182       }
    2183     }
    2184     else
    2185     {
    2186       pSaoParam->saoLcuParam[iCompIdx][iAddr].typeIdx = -1;
    2187       pSaoParam->saoLcuParam[iCompIdx][iAddr].subTypeIdx = 0;
     2134            ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc;
     2135        }
     2136          ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0];
     2137          ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1];
     2138          ctbParam.offset[SAO_CLASS_EO_PLAIN      ] = 0;
     2139          ctbParam.offset[SAO_CLASS_EO_HALF_PEAK  ] = -offset[2];
     2140          ctbParam.offset[SAO_CLASS_EO_FULL_PEAK  ] = -offset[3];
     2141      }
     2142      }
    21882143    }
    21892144  }
     
    24242379#endif
    24252380
     2381
     2382
    24262383//! \}
  • trunk/source/Lib/TLibDecoder/TDecSbac.h

    r833 r872  
    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 *
     
    9494  Void  parseSaoTypeIdx           ( UInt&  ruiVal  );
    9595  Void  parseSaoUflc              ( UInt uiLength, UInt& ruiVal     );
    96   Void  parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
    97   Void  parseSaoOffset            (SaoLcuParam* psSaoLcuParam, UInt compIdx);
     96  Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail);
     97  Void parseSaoSign(UInt& val);
    9898private:
    9999  Void  xReadUnarySymbol    ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset );
     
    209209  ContextModel3DBuffer m_cMVPIdxSCModel;
    210210 
    211   ContextModel3DBuffer m_cCUAMPSCModel;
    212211  ContextModel3DBuffer m_cSaoMergeSCModel;
    213212  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
  • trunk/source/Lib/TLibDecoder/TDecSlice.cpp

    r608 r872  
    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 *
     
    313313    g_bJustDoIt = g_bEncDecTraceEnable;
    314314#endif
    315     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    316     {
    317       SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
    318       saoParam->bSaoFlag[0] = pcSlice->getSaoEnabledFlag();
    319       if (iCUAddr == iStartCUAddr)
    320       {
    321         saoParam->bSaoFlag[1] = pcSlice->getSaoEnabledFlagChroma();
    322       }
    323       Int numCuInWidth     = saoParam->numCuInWidth;
    324       Int cuAddrInSlice = iCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
    325       Int cuAddrUpInSlice  = cuAddrInSlice - numCuInWidth;
    326       Int rx = iCUAddr % numCuInWidth;
    327       Int ry = iCUAddr / numCuInWidth;
    328       Int allowMergeLeft = 1;
    329       Int allowMergeUp   = 1;
    330       if (rx!=0)
    331       {
    332         if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))
    333         {
    334           allowMergeLeft = 0;
    335         }
    336       }
    337       if (ry!=0)
    338       {
    339         if (rpcPic->getPicSym()->getTileIdxMap(iCUAddr-numCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(iCUAddr))
    340         {
    341           allowMergeUp = 0;
    342         }
    343       }
    344       pcSbacDecoder->parseSaoOneLcuInterleaving(rx, ry, saoParam,pcCU, cuAddrInSlice, cuAddrUpInSlice, allowMergeLeft, allowMergeUp);
    345     }
    346     else if ( pcSlice->getSPS()->getUseSAO() )
    347     {
    348       Int addr = pcCU->getAddr();
    349       SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam();
    350       for (Int cIdx=0; cIdx<3; cIdx++)
    351       {
    352         SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
    353         if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
    354         {
    355           saoLcuParam->mergeUpFlag   = 0;
    356           saoLcuParam->mergeLeftFlag = 0;
    357           saoLcuParam->subTypeIdx    = 0;
    358           saoLcuParam->typeIdx       = -1;
    359           saoLcuParam->offset[0]     = 0;
    360           saoLcuParam->offset[1]     = 0;
    361           saoLcuParam->offset[2]     = 0;
    362           saoLcuParam->offset[3]     = 0;
    363         }
     315
     316    if ( pcSlice->getSPS()->getUseSAO() )
     317      {
     318      SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[iCUAddr];
     319      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     320      {
     321        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     322        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     323        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     324
     325        Bool leftMergeAvail = false;
     326        Bool aboveMergeAvail= false;
     327
     328        //merge left condition
     329        Int rx = (iCUAddr % uiWidthInLCUs);
     330        if(rx > 0)
     331        {
     332          leftMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-1);
     333        }
     334        //merge up condition
     335        Int ry = (iCUAddr / uiWidthInLCUs);
     336        if(ry > 0)
     337        {
     338          aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs);
     339      }
     340
     341        pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail);
     342    }
     343      else
     344        {
     345        saoblkParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     346        saoblkParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
     347        saoblkParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
    364348      }
    365349    }
  • trunk/source/Lib/TLibDecoder/TDecSlice.h

    r655 r872  
    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/TLibDecoder/TDecTop.cpp

    r773 r872  
    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 *
     
    5151  m_aaiCodedOffset         = new Int* [ MAX_NUM_LAYERS ];
    5252  m_aaiCodedScale          = new Int* [ MAX_NUM_LAYERS ];
     53#if !FIX_CAM_PARS_COLLECTOR
    5354  m_aiViewId               = new Int  [ MAX_NUM_LAYERS ];
    5455
    5556  m_bViewReceived          = new Bool [ MAX_NUM_LAYERS ];
     57#endif
    5658  for( UInt uiId = 0; uiId < MAX_NUM_LAYERS; uiId++ )
    5759  {
     
    6365  m_iLog2Precision   = LOG2_DISP_PREC_LUT;
    6466  m_uiBitDepthForLUT = 8; // fixed
     67#if FIX_CAM_PARS_COLLECTOR
     68  m_receivedIdc = NULL;
     69  m_vps         = NULL;
     70#endif
    6571}
    6672
     
    7480  delete [] m_aaiCodedOffset;
    7581  delete [] m_aaiCodedScale;
     82#if !FIX_CAM_PARS_COLLECTOR
    7683  delete [] m_aiViewId; 
    7784  delete [] m_bViewReceived;
     85#endif
    7886
    7987  xDeleteArray( m_adBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
    8088  xDeleteArray( m_aiBaseViewShiftLUT, MAX_NUM_LAYERS, MAX_NUM_LAYERS, 2 );
    81 }
    82 
     89#if FIX_CAM_PARS_COLLECTOR
     90  xDeleteArray( m_receivedIdc, m_uiMaxViewIndex + 1 );
     91#endif
     92}
     93
     94
     95#if FIX_CAM_PARS_COLLECTOR
     96Void
     97CamParsCollector::init( FILE* pCodedScaleOffsetFile, TComVPS* vps)
     98{
     99  assert( !isInitialized() ); // Only one initialization currently supported
     100  m_bInitialized            = true;
     101  m_vps                     = vps;
     102  m_bCamParsVaryOverTime    = false;
     103  m_pCodedScaleOffsetFile   = pCodedScaleOffsetFile;
     104  m_lastPoc                 = -1;   
     105  m_firstReceivedPoc        = -2;
     106
     107  m_uiMaxViewIndex            = -1;
     108  for (Int i = 0; i <= vps->getMaxLayersMinus1(); i++)
     109  {
     110    Int curViewIdx = m_vps->getViewIndex( m_vps->getLayerIdInNuh( i ));
     111    m_bCamParsVaryOverTime = m_bCamParsVaryOverTime || vps->hasCamParInSliceHeader( curViewIdx );
     112    m_uiMaxViewIndex = std::max( m_uiMaxViewIndex, curViewIdx  ) ;
     113  }
     114
     115  assert( m_receivedIdc == NULL );
     116  m_receivedIdc = new Int*[ m_uiMaxViewIndex + 1];
     117  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
     118  {
     119    m_receivedIdc[i] = new Int[ m_uiMaxViewIndex + 1 ];
     120  }
     121
     122  xResetReceivedIdc( true );
     123
     124  for (Int viewIndex = 0; viewIndex <= m_uiMaxViewIndex ; viewIndex++ )
     125  {
     126    if (m_vps->getCamParPresent( viewIndex ) )
     127    {   
     128      if( !m_vps->hasCamParInSliceHeader( viewIndex ) )
     129      {
     130        for (Int baseViewIndex = 0; baseViewIndex < viewIndex ; baseViewIndex++ )
     131        {
     132          m_receivedIdc   [ baseViewIndex ][ viewIndex ] = -1;
     133          m_aaiCodedScale [ baseViewIndex ][ viewIndex ] = m_vps->getCodedScale    (viewIndex) [ baseViewIndex ];
     134          m_aaiCodedOffset[ baseViewIndex ][ viewIndex ] = m_vps->getCodedOffset   (viewIndex) [ baseViewIndex ];
     135
     136          m_receivedIdc   [ viewIndex ][ baseViewIndex ] = -1;
     137          m_aaiCodedScale [ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedScale (viewIndex) [ baseViewIndex ];
     138          m_aaiCodedOffset[ viewIndex ][ baseViewIndex ] = m_vps->getInvCodedOffset(viewIndex) [ baseViewIndex ];
     139          xInitLUTs( baseViewIndex, viewIndex, m_aaiCodedScale[ baseViewIndex ][ viewIndex ], m_aaiCodedOffset[ baseViewIndex ][ viewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     140          xInitLUTs( viewIndex, baseViewIndex, m_aaiCodedScale[ viewIndex ][ baseViewIndex ], m_aaiCodedOffset[ viewIndex ][ baseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT );
     141        }
     142      }
     143    }
     144  }
     145}
     146
     147Void
     148CamParsCollector::xResetReceivedIdc( Bool overWriteFlag )
     149{
     150  for (Int i = 0; i <= m_uiMaxViewIndex; i++)
     151  { 
     152    for (Int j = 0; j <= m_uiMaxViewIndex; j++)
     153    {
     154      if ( overWriteFlag ||  ( m_receivedIdc[i][j] != -1 ) )
     155      {
     156        m_receivedIdc[i][j] = 0;
     157      }     
     158    }
     159  }
     160}
     161#else
    83162Void
    84163CamParsCollector::init( FILE* pCodedScaleOffsetFile )
     
    92171  m_uiMaxViewIndex             = 0;
    93172}
     173#endif
     174
     175
    94176
    95177Void
     
    124206  CamParsCollector::xInitLUTs( UInt uiSourceView, UInt uiTargetView, Int iScale, Int iOffset, Double****& radLUT, Int****& raiLUT)
    125207{
     208#if FIX_CAM_PARS_COLLECTOR
     209  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_vps->getCamParPrecision() + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
     210#else
    126211  Int     iLog2DivLuma   = m_uiBitDepthForLUT + m_uiCamParsCodedPrecision + 1 - m_iLog2Precision;   AOF( iLog2DivLuma > 0 );
     212#endif
    127213  Int     iLog2DivChroma = iLog2DivLuma + 1;
    128214
     
    166252}
    167253
     254#if !FIX_CAM_PARS_COLLECTOR
    168255Void
    169256CamParsCollector::setSlice( TComSlice* pcSlice )
     
    284371}
    285372
     373#else
     374Void
     375CamParsCollector::setSlice( TComSlice* pcSlice )
     376{
     377  if( pcSlice == 0 )
     378  {
     379    xOutput( m_lastPoc );
     380    return;
     381  }
     382
     383  if ( pcSlice->getIsDepth())
     384  {
     385    return;
     386  }
     387
     388  Int curPoc = pcSlice->getPOC();
     389  if( m_firstReceivedPoc == -2 )
     390  {
     391    m_firstReceivedPoc = curPoc;
     392  }
     393
     394  Bool newPocFlag = ( m_lastPoc != curPoc ); 
     395
     396  if ( newPocFlag )
     397  {   
     398    if( m_lastPoc != -1 )
     399    {
     400      xOutput( m_lastPoc );
     401    }
     402
     403    xResetReceivedIdc( false );
     404    m_lastPoc = pcSlice->getPOC();
     405  }
     406
     407  UInt uiViewIndex          = pcSlice->getViewIndex(); 
     408  if( m_vps->getCamParPresent( uiViewIndex ) )
     409  {   
     410    if( m_vps->hasCamParInSliceHeader( uiViewIndex ) ) // check consistency of slice parameters here
     411    {   
     412      for( UInt uiBaseViewIndex = 0; uiBaseViewIndex < uiViewIndex; uiBaseViewIndex++ )
     413      {       
     414        if ( m_receivedIdc[ uiViewIndex ][ uiBaseViewIndex ] != 0 )
     415        {     
     416          AOF( m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedScale () [ uiBaseViewIndex ] );
     417          AOF( m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ] == pcSlice->getInvCodedOffset() [ uiBaseViewIndex ] );
     418        }
     419        else
     420        {         
     421          m_receivedIdc   [ uiViewIndex ][ uiBaseViewIndex ]  = 1;
     422          m_aaiCodedScale [ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedScale () [ uiBaseViewIndex ];
     423          m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ]  = pcSlice->getInvCodedOffset() [ uiBaseViewIndex ];
     424          xInitLUTs( uiViewIndex, uiBaseViewIndex, m_aaiCodedScale[ uiViewIndex ][ uiBaseViewIndex ], m_aaiCodedOffset[ uiViewIndex ][ uiBaseViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
     425        }
     426        if ( m_receivedIdc[ uiBaseViewIndex ][ uiViewIndex ] != 0 )
     427        {     
     428          AOF( m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedScale    () [ uiBaseViewIndex ] );
     429          AOF( m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ] == pcSlice->getCodedOffset   () [ uiBaseViewIndex ] );
     430        }
     431        else
     432        {       
     433          m_receivedIdc   [ uiBaseViewIndex ][ uiViewIndex ]  = 1;
     434          m_aaiCodedScale [ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedScale    () [ uiBaseViewIndex ];
     435          m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ]  = pcSlice->getCodedOffset   () [ uiBaseViewIndex ];
     436          xInitLUTs( uiBaseViewIndex, uiViewIndex, m_aaiCodedScale[ uiBaseViewIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseViewIndex ][ uiViewIndex ], m_adBaseViewShiftLUT, m_aiBaseViewShiftLUT);
     437        }
     438      }
     439    }
     440  }
     441}
     442#endif
     443
     444
    286445#if H_3D_IV_MERGE
    287446Void
     
    295454#endif
    296455
     456#if !FIX_CAM_PARS_COLLECTOR
    297457Bool
    298458CamParsCollector::xIsComplete()
     
    307467  return true;
    308468}
     469#endif
    309470
    310471Void
     
    313474  if( m_pCodedScaleOffsetFile )
    314475  {
     476#if FIX_CAM_PARS_COLLECTOR
     477    if( iPOC == m_firstReceivedPoc )
     478#else
    315479    if( iPOC == 0 )
     480#endif
    316481    {
    317482      fprintf( m_pCodedScaleOffsetFile, "#  ViewIndex       ViewId\n" );
    318483      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------\n" );
     484#if FIX_CAM_PARS_COLLECTOR
    319485      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
    320486      {
     487        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_vps->getViewIdVal( uiViewIndex ) );
     488#else       
     489      for( UInt uiViewIndex = 0; uiViewIndex <= m_uiMaxViewIndex; uiViewIndex++ )
     490      {
    321491        fprintf( m_pCodedScaleOffsetFile, "%12d %12d\n", uiViewIndex, m_aiViewId[ uiViewIndex ] );
     492#endif
    322493      }
    323494      fprintf( m_pCodedScaleOffsetFile, "\n\n");
     
    325496      fprintf( m_pCodedScaleOffsetFile, "#----------- ------------ ------------ ------------ ------------ ------------ ------------\n" );
    326497    }
     498#if FIX_CAM_PARS_COLLECTOR
     499    if( iPOC == m_firstReceivedPoc || m_bCamParsVaryOverTime  )
     500#else
    327501    if( iPOC == 0 || m_bCamParsVaryOverTime )
     502#endif
    328503    {
    329504      Int iS = iPOC;
     
    335510          if( uiViewIndex != uiBaseIndex )
    336511          {
     512#if FIX_CAM_PARS_COLLECTOR
     513            if ( m_receivedIdc[uiBaseIndex][uiViewIndex] != 0 )
     514            {           
     515              fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
     516                iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_vps->getCamParPrecision() );
     517            }           
     518#else
    337519            fprintf( m_pCodedScaleOffsetFile, "%12d %12d %12d %12d %12d %12d %12d\n",
    338520              iS, iE, uiViewIndex, uiBaseIndex, m_aaiCodedScale[ uiBaseIndex ][ uiViewIndex ], m_aaiCodedOffset[ uiBaseIndex ][ uiViewIndex ], m_uiCamParsCodedPrecision );
     521#endif
     522
    339523          }
    340524        }
     
    457641  for( Int temporalLayer=0; temporalLayer < MAX_TLAYER; temporalLayer++)
    458642  {
     643#if H_MV_HLS_7_SPS_P0155_16_32
     644    numReorderPics[temporalLayer] = ( getLayerId() == 0 ) ? pcSlice->getSPS()->getNumReorderPics(temporalLayer) : pcSlice->getVPS()->getNumReorderPics(temporalLayer);
     645#else
    459646    numReorderPics[temporalLayer] = pcSlice->getSPS()->getNumReorderPics(temporalLayer);
    460   }
    461 
     647#endif
     648  }
     649#if H_MV_HLS_7_SPS_P0155_16_32
     650  if ( getLayerId() == 0 )
     651  { 
     652    m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
     653  }
     654  else
     655  {
     656    m_iMaxRefPicNum = pcSlice->getVPS()->getMaxDecPicBuffering(pcSlice->getTLayer());
     657#if H_MV_HLS7_GEN
     658    TComVPS* vps         = pcSlice->getVPS();
     659    TComDpbSize* dpbSize = vps->getDpbSize();
     660    Int lsIdx            = vps->getLayerSetIdxForOutputLayerSet( getTargetOutputLayerSetIdx()); // Is this correct, seems to be missing in spec?
     661    Int layerIdx         = vps->getIdxInLayerSet     ( lsIdx, getLayerId() );
     662    Int subDpbIdx        = dpbSize->getSubDpbAssigned( lsIdx, layerIdx );
     663    m_iMaxRefPicNum      = dpbSize->getMaxVpsDecPicBufferingMinus1(getTargetOutputLayerSetIdx(), subDpbIdx , vps->getSubLayersVpsMaxMinus1( vps->getLayerIdInVps( getLayerId() ) ) + 1 ) + 1 ; 
     664#endif   
     665  }
     666#else
    462667  m_iMaxRefPicNum = pcSlice->getSPS()->getMaxDecPicBuffering(pcSlice->getTLayer());     // m_uiMaxDecPicBuffering has the space for the picture currently being decoded
     668#endif
    463669  if (m_cListPic.size() < (UInt)m_iMaxRefPicNum)
    464670  {
     
    467673    rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    468674                     conformanceWindow, defaultDisplayWindow, numReorderPics, true);
    469     rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
    470675    m_cListPic.pushBack( rpcPic );
    471676   
     
    505710  rpcPic->create ( pcSlice->getSPS()->getPicWidthInLumaSamples(), pcSlice->getSPS()->getPicHeightInLumaSamples(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth,
    506711                   conformanceWindow, defaultDisplayWindow, numReorderPics, true);
    507   rpcPic->getPicSym()->allocSaoParam(&m_cSAO);
    508712}
    509713
     
    662866
    663867  m_cSAO.destroy();
    664   m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() );
     868  m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() );
    665869  m_cLoopFilter.create( sps->getMaxCUDepth() );
    666870}
     
    670874{
    671875  assert( nalu.m_layerId == m_layerId );
    672 
    673876#else
    674877Bool TDecTop::xDecodeSlice(InputNALUnit &nalu, Int &iSkipFrame, Int iPOCLastDisplay )
     
    682885    m_uiSliceIdx     = 0;
    683886  }
     887  else
     888  {
     889    m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
     890  }
    684891  m_apcSlicePilot->setSliceIdx(m_uiSliceIdx);
    685   if (!m_bFirstSliceInPicture)
    686   {
    687     m_apcSlicePilot->copySliceInfo( pcPic->getPicSym()->getSlice(m_uiSliceIdx-1) );
    688   }
    689892
    690893  m_apcSlicePilot->setNalUnitType(nalu.m_nalUnitType);
     
    9941197#endif
    9951198#else
    996 #if FIX1071
    9971199    pcSlice->setRefPicList( m_cListPic, true );
    998 #else
    999     pcSlice->setRefPicList( m_cListPic );
    1000 #endif
    1001 
    10021200#endif
    10031201
     
    12151413    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    12161414    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    1217     case NAL_UNIT_CODED_SLICE_TLA_R:
     1415    case NAL_UNIT_CODED_SLICE_TSA_R:
    12181416    case NAL_UNIT_CODED_SLICE_TSA_N:
    12191417    case NAL_UNIT_CODED_SLICE_STSA_R:
     
    12351433#endif
    12361434      break;
     1435    case NAL_UNIT_EOS:
     1436      m_associatedIRAPType = NAL_UNIT_INVALID;
     1437      m_pocCRA = 0;
     1438      m_pocRandomAccess = MAX_INT;
     1439      m_prevPOC = MAX_INT;
     1440      m_bFirstSliceInPicture = true;
     1441      m_bFirstSliceInSequence = true;
     1442      m_prevSliceSkipped = false;
     1443      m_skippedPOC = 0;
     1444      return false;
     1445     
     1446    case NAL_UNIT_ACCESS_UNIT_DELIMITER:
     1447      // TODO: process AU delimiter
     1448      return false;
     1449     
     1450    case NAL_UNIT_EOB:
     1451      return false;
     1452     
     1453     
     1454    case NAL_UNIT_RESERVED_VCL_N10:
     1455    case NAL_UNIT_RESERVED_VCL_R11:
     1456    case NAL_UNIT_RESERVED_VCL_N12:
     1457    case NAL_UNIT_RESERVED_VCL_R13:
     1458    case NAL_UNIT_RESERVED_VCL_N14:
     1459    case NAL_UNIT_RESERVED_VCL_R15:
     1460     
     1461    case NAL_UNIT_RESERVED_IRAP_VCL22:
     1462    case NAL_UNIT_RESERVED_IRAP_VCL23:
     1463     
     1464    case NAL_UNIT_RESERVED_VCL24:
     1465    case NAL_UNIT_RESERVED_VCL25:
     1466    case NAL_UNIT_RESERVED_VCL26:
     1467    case NAL_UNIT_RESERVED_VCL27:
     1468    case NAL_UNIT_RESERVED_VCL28:
     1469    case NAL_UNIT_RESERVED_VCL29:
     1470    case NAL_UNIT_RESERVED_VCL30:
     1471    case NAL_UNIT_RESERVED_VCL31:
     1472     
     1473    case NAL_UNIT_FILLER_DATA:
     1474    case NAL_UNIT_RESERVED_NVCL41:
     1475    case NAL_UNIT_RESERVED_NVCL42:
     1476    case NAL_UNIT_RESERVED_NVCL43:
     1477    case NAL_UNIT_RESERVED_NVCL44:
     1478    case NAL_UNIT_RESERVED_NVCL45:
     1479    case NAL_UNIT_RESERVED_NVCL46:
     1480    case NAL_UNIT_RESERVED_NVCL47:
     1481    case NAL_UNIT_UNSPECIFIED_48:
     1482    case NAL_UNIT_UNSPECIFIED_49:
     1483    case NAL_UNIT_UNSPECIFIED_50:
     1484    case NAL_UNIT_UNSPECIFIED_51:
     1485    case NAL_UNIT_UNSPECIFIED_52:
     1486    case NAL_UNIT_UNSPECIFIED_53:
     1487    case NAL_UNIT_UNSPECIFIED_54:
     1488    case NAL_UNIT_UNSPECIFIED_55:
     1489    case NAL_UNIT_UNSPECIFIED_56:
     1490    case NAL_UNIT_UNSPECIFIED_57:
     1491    case NAL_UNIT_UNSPECIFIED_58:
     1492    case NAL_UNIT_UNSPECIFIED_59:
     1493    case NAL_UNIT_UNSPECIFIED_60:
     1494    case NAL_UNIT_UNSPECIFIED_61:
     1495    case NAL_UNIT_UNSPECIFIED_62:
     1496    case NAL_UNIT_UNSPECIFIED_63:
    12371497    default:
    1238       assert (1);
     1498      assert (0);
    12391499  }
    12401500
  • trunk/source/Lib/TLibDecoder/TDecTop.h

    r833 r872  
    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 *
     
    7171  ~CamParsCollector ();
    7272
     73#if FIX_CAM_PARS_COLLECTOR
     74  Void  init        ( FILE* pCodedScaleOffsetFile, TComVPS* vps );
     75#else
    7376  Void  init        ( FILE* pCodedScaleOffsetFile );
     77#endif
     78
    7479  Void  uninit      ();
    7580  Void  setSlice    ( TComSlice* pcSlice );
     
    8590  Int getCodedScale( Int iBaseView, Int iCureView){ return m_aaiCodedScale[ iBaseView ][ iCureView ];}
    8691  Int getCodedOffset( Int iBaseView, Int iCureView){ return m_aaiCodedOffset[ iBaseView ][ iCureView ];}
    87   UInt getCamParsCodedPrecision(){ return m_uiCamParsCodedPrecision; }
     92  UInt getCamParsCodedPrecision(){ return m_vps->getCamParPrecision(); }
    8893#endif
    8994
    9095private:
     96#if FIX_CAM_PARS_COLLECTOR
     97  Void xResetReceivedIdc( Bool overWriteFlag );
     98#else
    9199  Bool  xIsComplete ();
     100#endif
    92101  Void  xOutput     ( Int iPOC );
    93102
     
    98107  Int**   m_aaiCodedOffset;
    99108  Int**   m_aaiCodedScale;
     109 
     110#if !FIX_CAM_PARS_COLLECTOR
    100111  Int*    m_aiViewId; 
    101 
     112#else
     113  TComVPS* m_vps;
     114  Int**    m_receivedIdc;
     115  Int      m_uiMaxViewIndex;
     116  Int      m_lastPoc;
     117  Int      m_firstReceivedPoc;
     118#endif
     119
     120 
     121#if !FIX_CAM_PARS_COLLECTOR
    102122  Bool*   m_bViewReceived;
    103123  UInt    m_uiCamParsCodedPrecision;
     124#endif
    104125  Bool    m_bCamParsVaryOverTime;
     126#if !FIX_CAM_PARS_COLLECTOR
    105127  Int     m_iLastViewIndex;
    106128  Int     m_iLastPOC;
    107129  UInt    m_uiMaxViewIndex;
     130#endif
    108131
    109132
  • trunk/source/Lib/TLibEncoder/AnnexBwrite.h

    r608 r872  
    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

    r608 r872  
    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  vector<uint8_t>& rbsp   = nalu.m_Bitstream.getFIFO();
    9292
     93#if H_MV_HLS_7_MISC_P0130_EOS  // This will handle situation when writing NAL with zero payload
     94  if (rbsp.size() == 0) return;
     95#endif
     96
    9397  for (vector<uint8_t>::iterator it = rbsp.begin(); it != rbsp.end();)
    9498  {
  • trunk/source/Lib/TLibEncoder/NALwrite.h

    r608 r872  
    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

    r608 r872  
    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 *
     
    9393    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
    9494    break;
     95#if H_MV_HLS_7_SEI_P0204_26
     96    case SEI::SUB_BITSTREAM_PROPERTY:
     97    fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n");
     98    break;
     99#endif
    95100  default:
    96101    fprintf( g_hTrace, "=========== Unknown SEI message ===========\n");
     
    146151    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
    147152    break;
     153#if H_MV_HLS_7_SEI_P0204_26
     154   case SEI::SUB_BITSTREAM_PROPERTY:
     155   xWriteSEISubBitstreamProperty(*static_cast<const SEISubBitstreamProperty*>(&sei));
     156   break;
     157#endif
    148158  default:
    149159    assert(!"Unhandled SEI message");
     
    307317  if( !hrd->getSubPicCpbParamsPresentFlag() )
    308318  {
    309     WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
     319    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" );
     320  }
     321  if( sei.m_rapCpbParamsPresentFlag )
     322  {
     323    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
     324    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
    310325  }
    311326  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
    312327  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
    313   if( sei.m_rapCpbParamsPresentFlag )
    314   {
    315     WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
    316     WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
    317   }
    318328  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
    319329  {
     
    579589}
    580590
     591#if H_MV_HLS_7_SEI_P0204_26
     592Void SEIWriter::xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei)
     593{
     594  WRITE_CODE( sei.m_activeVpsId, 4, "active_vps_id" );
     595  assert( sei.m_numAdditionalSubStreams >= 1 );
     596  WRITE_UVLC( sei.m_numAdditionalSubStreams - 1, "num_additional_sub_streams_minus1" );
     597
     598  for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ )
     599  {
     600    WRITE_CODE( sei.m_subBitstreamMode[i],       2, "sub_bitstream_mode[i]"           );
     601    WRITE_UVLC( sei.m_outputLayerSetIdxToVps[i],    "output_layer_set_idx_to_vps[i]"  );
     602    WRITE_CODE( sei.m_highestSublayerId[i],      3, "highest_sub_layer_id[i]"         );
     603    WRITE_CODE( sei.m_avgBitRate[i],            16, "avg_bit_rate[i]"                 );
     604    WRITE_CODE( sei.m_maxBitRate[i],            16, "max_bit_rate[i]"                 );
     605  }
     606  xWriteByteAlign();
     607}
     608#endif
     609
    581610Void SEIWriter::xWriteByteAlign()
    582611{
  • trunk/source/Lib/TLibEncoder/SEIwrite.h

    r608 r872  
    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 *
     
    6666  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
    6767  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
     68#if H_MV_HLS_7_SEI_P0204_26
     69  Void xWriteSEISubBitstreamProperty(const SEISubBitstreamProperty &sei);
     70#endif
    6871  Void xWriteByteAlign();
    6972};
  • trunk/source/Lib/TLibEncoder/SyntaxElementWriter.cpp

    r608 r872  
    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

    r608 r872  
    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

    r655 r872  
    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

    r655 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r833 r872  
    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 *
     
    256256  if( pcPPS->getScalingListPresentFlag() )
    257257  {
    258 #if SCALING_LIST_OUTPUT_RESULT
    259     printf("PPS\n");
    260 #endif
    261258    codeScalingList( m_pcSlice->getScalingList() );
    262259  }
     
    273270  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    274271  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
    275 #if PPS_FIX_DEPTH
    276   if( pcPPS->getSPS()->getVPS()->getDepthId(pcPPS->getSPS()->getLayerId()) )
    277   {
    278     WRITE_FLAG( 1, "slice_segment_header_extension_present_flag" );
    279   }
    280   else
    281 #endif
    282272  WRITE_FLAG( pcPPS->getSliceHeaderExtensionPresentFlag() ? 1 : 0, "slice_segment_header_extension_present_flag");
    283273
     274#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     275#if !H_MV
     276  WRITE_FLAG( 0, "pps_extension_flag" );
     277#else
     278  WRITE_FLAG( 1, "pps_extension_flag" );
     279
     280  for ( Int i = 0; i < PPS_EX_T_MAX_NUM; i++ )
     281  {
     282    WRITE_FLAG( pcPPS->getPpsExtensionTypeFlag( i ) ? 1 : 0 , "pps_extension_type_flag" );
     283#if H_3D
     284    assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_3D || i == PPS_EX_T_ESC );
     285#else
     286    assert( !pcPPS->getPpsExtensionTypeFlag( i ) || i == PPS_EX_T_MV || i == PPS_EX_T_ESC );
     287#endif
     288  }
     289
     290  if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_MV ) )
     291  {
     292#if H_MV_HLS_7_POC_P0041
     293    WRITE_FLAG( pcPPS->getPocResetInfoPresentFlag( ) ? 1 : 0 , "poc_reset_info_present_flag" );
     294#endif
     295  }
     296
     297#if H_3D
     298  if( pcPPS->getPpsExtensionTypeFlag( PPS_EX_T_3D ) ) // This probably needs to be aligned with Rext and SHVC
     299  {
     300    codePPSExtension( pcPPS );
     301  }
     302#endif
     303
     304#endif
     305#else
    284306#if !H_3D
    285307  WRITE_FLAG( 0, "pps_extension_flag" );
     
    288310  codePPSExtension( pcPPS );
    289311  WRITE_FLAG( 0, "pps_extension2_flag" );
     312#endif
    290313#endif
    291314}
     
    436459            else
    437460            {
    438               WRITE_CODE(uiNumDepthValues_coded, 8, "num_depth_values_in_dlt[layerId]");    // num_entry
     461              WRITE_CODE(uiNumDepthValues_coded, 8, "num_depth_values_in_dlt[i]");    // num_entry
    439462
    440463#if !H_3D_DELTA_DLT
     
    702725#endif
    703726  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    704 
     727#if H_MV_HLS_7_SPS_P0155_16_32
     728  if ( pcSPS->getLayerId() == 0 )
     729  { 
     730#endif
    705731  const Bool subLayerOrderingInfoPresentFlag = 1;
    706732  WRITE_FLAG(subLayerOrderingInfoPresentFlag,       "sps_sub_layer_ordering_info_present_flag");
     
    715741    }
    716742  }
     743#if H_MV_HLS_7_SPS_P0155_16_32
     744  }
     745#endif
     746
    717747  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
    718748 
     
    742772    if(pcSPS->getScalingListPresentFlag())
    743773    {
    744 #if SCALING_LIST_OUTPUT_RESULT
    745     printf("SPS\n");
    746 #endif
    747774      codeScalingList( m_pcSlice->getScalingList() );
    748775    }
     
    844871    WRITE_SVLC( pcSPS->getScaledRefLayerRightOffset( j ), "scaled_ref_layer_right_offset" );
    845872    WRITE_SVLC( pcSPS->getScaledRefLayerBottomOffset( j ), "scaled_ref_layer_bottom_offset" );
     873#if H_MV_HLS_7_RESERVED_FLAGS
     874    WRITE_FLAG( 0, "sps_multilayer_ext_reserved_zero_flag[ j ]" );
     875#endif
    846876  }
    847877}
     
    874904  WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
    875905  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
    876 #if H_MV
     906#if H_MV_HLS_7_VPS_P0125_24
     907  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
     908#else
     909#if H_MV && !H_MV_HLS7_GEN
    877910  WRITE_CODE( 0xffff,                              16,        "vps_extension_offset" );
    878911#else
    879912  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
     913#endif
    880914#endif
    881915  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
     
    9761010{
    9771011  WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
     1012#if !H_MV_HLS_7_VPS_P0307_23
    9781013  WRITE_FLAG( pcVPS->getVpsVuiPresentFlag() ? 1 : 0 , "vps_vui_present_flag" );
    9791014  if ( pcVPS->getVpsVuiPresentFlag() )
     
    9811016  WRITE_CODE( pcVPS->getVpsVuiOffset( ), 16,                 "vps_vui_offset" );  // TBD
    9821017  }
     1018#endif
     1019
    9831020  WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
    9841021 
     
    10551092  if ( pcVPS->getVpsSubLayersMaxMinus1PresentFlag() )
    10561093  {
    1057     for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
     1094    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    10581095    {
    10591096      WRITE_CODE( pcVPS->getSubLayersVpsMaxMinus1( i ), 3, "sub_layers_vps_max_minus1" );
     
    10631100  else
    10641101  {
    1065     for (Int i = 0; i < pcVPS->getMaxLayersMinus1(); i++ )
     1102    for (Int i = 0; i <= pcVPS->getMaxLayersMinus1(); i++ )
    10661103    {
    10671104      assert( pcVPS->getSubLayersVpsMaxMinus1( i ) + 1 == pcVPS->getMaxTLayers( ) );   
     
    10851122
    10861123  WRITE_FLAG( pcVPS->getAllRefLayersActiveFlag( ) ? 1 : 0 , "all_ref_layers_active_flag" );
     1124#if !H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
    10871125  WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
     1126#endif
     1127
     1128#if !H_MV_HLS_7_VPS_P0306_22
    10881129  WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
     1130#else
     1131  WRITE_UVLC( pcVPS->getVpsNumProfileTierLevelMinus1( ), "vps_num_profile_tier_level_minus1" );
     1132#endif
    10891133
    10901134  for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
    10911135  {
    10921136    WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
     1137#if !H_MV_HLS_7_VPS_P0048_14
    10931138    if( !pcVPS->getVpsProfilePresentFlag( i ) )
    10941139    {   
     
    10961141      pcVPS->checkProfileRefMinus1( i );     
    10971142    }
     1143#endif
    10981144    codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
    10991145  }
    11001146
     1147
     1148
     1149
     1150
     1151
     1152#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1153  WRITE_UVLC( pcVPS->getNumAddOutputLayerSets( ), "num_add_output_layer_sets" );
     1154
     1155  if( pcVPS->getNumOutputLayerSets() > 1)
     1156  {
     1157    WRITE_CODE( pcVPS->getDefaultTargetOutputLayerIdc( ), 2, "default_target_output_layer_idc" );
     1158  } 
     1159#else
    11011160  Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1;
    11021161
     
    11141173    pcVPS->checkDefaultOneTargetOutputLayerIdc();
    11151174  } 
     1175#endif
    11161176
    11171177  assert( pcVPS->getOutputLayerFlag(0, 0) == pcVPS->inferOutputLayerFlag( 0, 0 ));
    11181178  assert( pcVPS->getOutputLayerSetIdxMinus1( 0 ) == -1 );
     1179
     1180#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1181
     1182  for( Int i = 1; i < pcVPS->getNumOutputLayerSets( ); i++ )
     1183  {
     1184    if( i > pcVPS->getVpsNumLayerSetsMinus1( ) )   
     1185#else
    11191186  for( Int i = 1; i < numOutputLayerSets; i++ )
    11201187  {
    11211188    if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
     1189#endif
    11221190    {     
    11231191      WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
     1192#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1193    }
     1194
     1195    if ( i > pcVPS->getVpsNumLayerSetsMinus1() || pcVPS->getDefaultTargetOutputLayerIdc() == 2 )
     1196    {       
     1197      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ); j++ )
     1198      {
     1199        WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
     1200      }             
     1201    }
     1202    else
     1203    {
     1204      for( Int j = 0; j < pcVPS->getNumLayersInIdList( pcVPS->getLayerSetIdxForOutputLayerSet( i ) ) - 1; j++ )
     1205      {             
     1206        assert( pcVPS->getOutputLayerFlag( i , j ) == pcVPS->inferOutputLayerFlag( i, j ));
     1207      }
     1208    }       
     1209
     1210#else
    11241211      for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
    11251212      {
     
    11351222      }
    11361223    }
    1137 
     1224#endif
    11381225    if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
    11391226    {     
    11401227      WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
    11411228    }
     1229#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1230    if( pcVPS->getNumOutputLayersInOutputLayerSet( i ) == 1 && pcVPS->getNumDirectRefLayers( pcVPS->getOlsHighestOutputLayerId( i ) ) > 0 )
     1231    {
     1232      WRITE_FLAG( pcVPS->getAltOutputLayerFlag( i ) ? 1 : 0 , "alt_output_layer_flag[ i ]" );
     1233    }
     1234  }
     1235#else
    11421236  }
    11431237
     
    11461240    WRITE_FLAG( pcVPS->getAltOutputLayerFlag( ) ? 1 : 0 , "alt_output_layer_flag" );
    11471241  }
     1242#endif
     1243
     1244
     1245
     1246
    11481247
    11491248  WRITE_FLAG( pcVPS->getRepFormatIdxPresentFlag( ) ? 1 : 0 , "rep_format_idx_present_flag" );
    11501249  if ( pcVPS->getRepFormatIdxPresentFlag() )
    11511250  {
     1251#if H_MV_HLS_7_VPS_P0306_22
     1252    WRITE_UVLC( pcVPS->getVpsNumRepFormatsMinus1( ), "vps_num_rep_formats_minus1" );
     1253#else
    11521254    WRITE_CODE( pcVPS->getVpsNumRepFormatsMinus1( ), 4, "vps_num_rep_formats_minus1" );
     1255#endif
    11531256  }
    11541257
     
    11661269      if( pcVPS->getVpsNumRepFormatsMinus1() > 0 )
    11671270      {
     1271#if H_MV_HLS_7_VPS_P0306_22
     1272        WRITE_CODE( pcVPS->getVpsRepFormatIdx(i), pcVPS->getVpsRepFormatIdxLen(), "vps_rep_format_idx[i]" );
     1273#else
    11681274        WRITE_CODE( pcVPS->getVpsRepFormatIdx( i ), 8, "vps_rep_format_idx" );
     1275#endif
    11691276      }
    11701277    }
     
    11721279
    11731280  WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
     1281#if H_MV_HLS7_GEN
     1282  WRITE_FLAG( pcVPS->getVpsPocLsbAlignedFlag( ) ? 1 : 0 , "vps_poc_lsb_aligned_flag" );
     1283#endif
    11741284  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
    11751285  {
     
    11791289    }
    11801290  }
     1291#if H_MV_HLS_7_RESERVED_FLAGS
     1292  WRITE_FLAG( 0, "vps_reserved_zero_flag" );
     1293#endif
    11811294  codeDpbSize( pcVPS );
    11821295
     
    12081321    }
    12091322  } 
     1323#if H_MV_HLS_7_VPS_P0307_23
     1324  WRITE_UVLC( 0, "vps_non_vui_extension_length" );
     1325  WRITE_FLAG( pcVPS->getVpsVuiPresentFlag() ? 1 : 0 , "vps_vui_present_flag" );
     1326#endif
     1327#if !H_MV_HLS_7_RESERVED_FLAGS 
    12101328    WRITE_FLAG ( 0,                                      "vps_shvc_reserved_zero_flag" );
    1211 
     1329#endif
    12121330    if( pcVPS->getVpsVuiPresentFlag() )
    12131331    {
     
    12151333      codeVPSVUI( pcVPS );
    12161334    }     
     1335#if H_MV_HLS_7_FIX_INFER_CROSS_LAYER_IRAP_ALIGNED_FLAG
     1336    {
     1337      TComVPSVUI* pcVPSVUI = pcVPS->getVPSVUI( );
     1338      assert( pcVPSVUI );
     1339      pcVPSVUI->inferVpsVui( true );
     1340    }
     1341#endif
    12171342}
    12181343Void TEncCavlc::codeVideoSignalInfo( TComVideoSignalInfo* pcVideoSignalInfo )
     
    12341359  { 
    12351360    WRITE_FLAG( dpbSize->getSubLayerFlagInfoPresentFlag( i ) ? 1 : 0 , "sub_layer_flag_info_present_flag" );
    1236 
     1361#if H_MV_HLS_7_HRD_P0156_7
     1362    for( Int j = 0; j  <=  vps->getMaxSubLayersInLayerSetMinus1( i ); j++ )
     1363#else
    12371364    for( Int j = 0; j  <=  vps->getMaxTLayers() - 1 ; j++ )
     1365#endif
    12381366    { 
    12391367      if( j > 0  &&  dpbSize->getSubLayerDpbInfoPresentFlag( i, j )  ) 
     
    12431371      if( dpbSize->getSubLayerDpbInfoPresentFlag( i, j ) )
    12441372      { 
     1373#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1374        for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i )); k++ )   
     1375#else
    12451376        for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   // Preliminary fix does not match with spec
     1377#endif
    12461378        {
    12471379          WRITE_UVLC( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ), "max_vps_dec_pic_buffering_minus1" );
    12481380        }
    12491381        WRITE_UVLC( dpbSize->getMaxVpsNumReorderPics( i, j ), "max_vps_num_reorder_pics" );
     1382#if H_MV_HLS7_GEN
     1383        if( vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ) != vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ) )
     1384        {
     1385          for( Int k = 0; k < vps->getNumLayersInIdList( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )
     1386          {
     1387            WRITE_UVLC( dpbSize->getMaxVpsLayerDecPicBuffMinus1( i, k, j ), "max_vps_layer_dec_pic_buff_minus1" );
     1388          }
     1389        }
     1390#endif
    12501391        WRITE_UVLC( dpbSize->getMaxVpsLatencyIncreasePlus1( i, j ), "max_vps_latency_increase_plus1" );
    12511392      }
     
    12541395        if ( j > 0 )
    12551396        {
     1397#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1398          for( Int k = 0; k < vps->getNumSubDpbs( vps->getLayerSetIdxForOutputLayerSet( i ) ); k++ )   
     1399#else
    12561400          for( Int k = 0; k < vps->getNumSubDpbs( vps->getOutputLayerSetIdxMinus1( i ) + 1 ); k++ )   
     1401#endif
    12571402          {
    12581403            assert( dpbSize->getMaxVpsDecPicBufferingMinus1( i, k, j ) == dpbSize->getMaxVpsDecPicBufferingMinus1( i,k, j - 1 ) );
     
    13061451    WRITE_FLAG( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) ? 1 : 0 , "cross_layer_irap_aligned_flag" );
    13071452  }
    1308 
     1453#if H_MV_HLS_7_MISC_P0068_21
     1454  if( pcVPSVUI->getCrossLayerIrapAlignedFlag( ) )
     1455  {
     1456    WRITE_FLAG( pcVPSVUI->getAllLayersIdrAlignedFlag( ) ? 1 : 0 , "all_layers_idr_aligned_flag" );
     1457  }
     1458#endif
    13091459  WRITE_FLAG( pcVPSVUI->getBitRatePresentVpsFlag( ) ? 1 : 0 , "bit_rate_present_vps_flag" );
    13101460  WRITE_FLAG( pcVPSVUI->getPicRatePresentVpsFlag( ) ? 1 : 0 , "pic_rate_present_vps_flag" );
    13111461  if( pcVPSVUI->getBitRatePresentVpsFlag( )  ||  pcVPSVUI->getPicRatePresentVpsFlag( ) )
    13121462  {
     1463#if H_MV_HLS_7_OUTPUT_LAYERS_5_10_22_27
     1464    for( Int i = 0; i  <=  pcVPS->getVpsNumLayerSetsMinus1(); i++ )
     1465#else
    13131466    for( Int i = 0; i  <=  pcVPS->getVpsNumberLayerSetsMinus1(); i++ )
     1467#endif
    13141468    {
    13151469      for( Int j = 0; j  <=  pcVPS->getMaxTLayers(); j++ )
     
    13371491  }
    13381492
     1493#if H_MV_HLS_7_VPS_P0076_15
     1494  WRITE_FLAG( pcVPSVUI->getVideoSignalInfoIdxPresentFlag( ) ? 1 : 0 , "video_signal_info_idx_present_flag" );
     1495  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     1496  {
     1497    WRITE_CODE( pcVPSVUI->getVpsNumVideoSignalInfoMinus1( ), 4, "vps_num_video_signal_info_minus1" );
     1498  }
     1499  else
     1500  {
     1501    pcVPSVUI->setVpsNumVideoSignalInfoMinus1( pcVPS->getMaxLayersMinus1() );
     1502  }
     1503
     1504  for( Int i = 0; i <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1(); i++ )
     1505  {
     1506    assert( pcVPSVUI->getVideoSignalInfo( i ) != NULL );
     1507    TComVideoSignalInfo* curVideoSignalInfo = pcVPSVUI->getVideoSignalInfo( i );
     1508    codeVideoSignalInfo( curVideoSignalInfo );     
     1509
     1510  }
     1511
     1512  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() && pcVPSVUI->getVpsNumVideoSignalInfoMinus1() > 0 )
     1513  {
     1514    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
     1515    {
     1516      WRITE_CODE( pcVPSVUI->getVpsVideoSignalInfoIdx( i ), 4, "vps_video_signal_info_idx" );
     1517      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i ) >= 0 && pcVPSVUI->getVpsVideoSignalInfoIdx( i ) <= pcVPSVUI->getVpsNumVideoSignalInfoMinus1() );
     1518    }
     1519  }
     1520  else
     1521  {
     1522    for( Int i = 1; i <=  pcVPS->getMaxLayersMinus1(); i++ )
     1523    {
     1524      assert( pcVPSVUI->getVpsVideoSignalInfoIdx( i  ) == ( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() ? 0 : i ) );
     1525    }
     1526  }
     1527#endif
    13391528  WRITE_FLAG( pcVPSVUI->getTilesNotInUseFlag( ) ? 1 : 0 , "tiles_not_in_use_flag" );
    13401529  if( !pcVPSVUI->getTilesNotInUseFlag() )
     
    13711560    }
    13721561  }
     1562#if H_MV_HLS_7_RESERVED_FLAGS
     1563  WRITE_CODE( 0, 3, "vps_vui_reserved_zero_3bits" );
     1564#endif
    13731565  WRITE_FLAG( pcVPSVUI->getIlpRestrictedRefLayersFlag( ) ? 1 : 0 , "ilp_restricted_ref_layers_flag" );
    13741566
     
    13911583    }
    13921584  }
     1585
     1586#if !H_MV_HLS_7_VPS_P0076_15
    13931587  WRITE_FLAG( pcVPSVUI->getVideoSignalInfoIdxPresentFlag( ) ? 1 : 0 , "video_signal_info_idx_present_flag" );
    13941588  if( pcVPSVUI->getVideoSignalInfoIdxPresentFlag() )
     
    14231617    }
    14241618  }
     1619#endif
    14251620  WRITE_FLAG( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) ? 1 : 0 , "vps_vui_bsp_hrd_present_flag" );
    14261621  if ( pcVPSVUI->getVpsVuiBspHrdPresentFlag( ) )
     
    14281623    codeVpsVuiBspHrdParameters( pcVPS );
    14291624  }
    1430 }
     1625#if H_MV_HLS_7_MISC_P0182_13
     1626  for( Int i = 1; i  <=  pcVPS->getMaxLayersMinus1(); i++ )
     1627  {
     1628    if( pcVPS->getNumDirectRefLayers( pcVPS->getLayerIdInNuh( i )) == 0 )
     1629    {
     1630      WRITE_FLAG( pcVPSVUI->getBaseLayerParameterSetCompatibilityFlag( i ) ? 1 : 0 , "base_layer_parameter_set_compatibility_flag" );
     1631    }
     1632}
     1633#endif
     1634}
     1635
    14311636Void TEncCavlc::codeVpsVuiBspHrdParameters( TComVPS* pcVPS )
    14321637{
     
    16441849    }
    16451850    pcSlice->checkCrossLayerBlaFlag( );
    1646 
     1851#if !H_MV_HLS7_GEN
    16471852    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
    16481853    {
     
    16501855      WRITE_FLAG( pcSlice->getPocResetFlag( ) ? 1 : 0 , "poc_reset_flag" );
    16511856    }
     1857#endif
    16521858
    16531859
     
    16881894      TComReferencePictureSet* rps = pcSlice->getRPS();
    16891895     
    1690 #if FIX1071
    16911896      // check for bitstream restriction stating that:
    16921897      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     
    16991904          }
    17001905        }
    1701 #endif
    17021906
    17031907      if(pcSlice->getRPSidx() < 0)
     
    18332037      {
    18342038         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
    1835          {
    1836            SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1837           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    1838          }
     2039         WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
    18392040      }
    18402041    }
     
    20342235#endif
    20352236
     2237#if !H_MV_HLS_7_POC_P0041
    20362238#if PPS_FIX_DEPTH
    20372239  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag() || pcSlice->getIsDepth() )
     
    20422244    WRITE_UVLC(0,"slice_header_extension_length");
    20432245  }
     2246#endif
     2247
     2248#if H_MV_HLS_7_POC_P0041
     2249#if !H_MV
     2250  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
     2251  {
     2252    WRITE_UVLC(0,"slice_header_extension_length");
     2253  }
     2254#else
     2255  if(pcSlice->getPPS()->getSliceHeaderExtensionPresentFlag())
     2256  {
     2257    // Derive the value of PocMsbValRequiredFlag
     2258    pcSlice->setPocMsbValRequiredFlag( pcSlice->getCraPicFlag() || pcSlice->getBlaPicFlag()
     2259                                          /* || related to vps_poc_lsb_aligned_flag */
     2260                                          );
     2261
     2262    // Determine value of SH extension length.
     2263    Int shExtnLengthInBit = 0;
     2264    if (pcSlice->getPPS()->getPocResetInfoPresentFlag())
     2265    {
     2266      shExtnLengthInBit += 2;
     2267    }
     2268    if (pcSlice->getPocResetIdc() > 0)
     2269    {
     2270      shExtnLengthInBit += 6;
     2271    }
     2272    if (pcSlice->getPocResetIdc() == 3)
     2273    {
     2274      shExtnLengthInBit += (pcSlice->getSPS()->getBitsForPOC() + 1);
     2275    }
     2276
     2277
     2278    if( !pcSlice->getPocMsbValRequiredFlag() /* TODO &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     2279    {
     2280      shExtnLengthInBit++;    // For poc_msb_val_present_flag
     2281    }
     2282    else
     2283    {
     2284      if( pcSlice->getPocMsbValRequiredFlag() )
     2285      {
     2286        pcSlice->setPocMsbValPresentFlag( true );
     2287      }
     2288      else
     2289      {
     2290        pcSlice->setPocMsbValPresentFlag( false );
     2291      }
     2292    }
     2293
     2294    if( pcSlice->getPocMsbValPresentFlag() )
     2295    {
     2296//      Int iMaxPOClsb = 1<< pcSlice->getSPS()->getBitsForPOC(); currently unused
     2297
     2298      UInt lengthVal = 1;
     2299      UInt tempVal = pcSlice->getPocMsbVal() + 1;
     2300      assert ( tempVal );
     2301      while( 1 != tempVal )
     2302      {
     2303        tempVal >>= 1;
     2304        lengthVal += 2;
     2305      }
     2306      shExtnLengthInBit += lengthVal;
     2307    }
     2308    Int shExtnAdditionalBits = 0;
     2309    if(shExtnLengthInBit % 8 != 0)
     2310    {
     2311      shExtnAdditionalBits = 8 - (shExtnLengthInBit % 8);
     2312    }
     2313    pcSlice->setSliceSegmentHeaderExtensionLength((shExtnLengthInBit + shExtnAdditionalBits) / 8);
     2314     
     2315
     2316    WRITE_UVLC( pcSlice->getSliceSegmentHeaderExtensionLength( ), "slice_segment_header_extension_length" );
     2317    UInt posFollSliceSegHeaderExtLen = m_pcBitIf->getNumberOfWrittenBits();
     2318    if( pcSlice->getPPS()->getPocResetInfoPresentFlag() )
     2319    {
     2320      WRITE_CODE( pcSlice->getPocResetIdc( ), 2, "poc_reset_idc" );
     2321    }
     2322    else
     2323    {
     2324      assert( pcSlice->getPocResetIdc( ) == 0 );
     2325    }
     2326
     2327    if( pcSlice->getPocResetIdc() !=  0 )
     2328    {
     2329      WRITE_CODE( pcSlice->getPocResetPeriodId( ), 6, "poc_reset_period_id" );
     2330    }
     2331   
     2332    if( pcSlice->getPocResetIdc() ==  3 )
     2333    {
     2334      WRITE_FLAG( pcSlice->getFullPocResetFlag( ) ? 1 : 0 , "full_poc_reset_flag" );
     2335      WRITE_CODE( pcSlice->getPocLsbVal( ), pcSlice->getPocLsbValLen() , "poc_lsb_val" );
     2336    }             
     2337   
     2338    if( !pcSlice->getPocMsbValRequiredFlag() /* TODO &&  pcSlice->getVPS()->getVpsPocLsbAlignedFlag() */ )
     2339    {
     2340      WRITE_FLAG( pcSlice->getPocMsbValPresentFlag( ) ? 1 : 0 , "poc_msb_val_present_flag" );
     2341    }
     2342   
     2343    if( pcSlice->getPocMsbValPresentFlag() )
     2344    {
     2345      WRITE_UVLC( pcSlice->getPocMsbVal( ), "poc_msb_val" );
     2346    }
     2347   
     2348    while( ( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) < pcSlice->getSliceSegmentHeaderExtensionLength() * 8 )
     2349    {
     2350      WRITE_FLAG( 0, "slice_segment_header_extension_data_bit" );
     2351    }
     2352
     2353    assert( ( m_pcBitIf->getNumberOfWrittenBits() - posFollSliceSegHeaderExtLen ) == pcSlice->getSliceSegmentHeaderExtensionLength() * 8  );
     2354  }
     2355#endif
     2356#endif
    20442357}
    20452358
     
    24292742  Bool scalingListPredModeFlag;
    24302743
    2431 #if SCALING_LIST_OUTPUT_RESULT
    2432   Int startBit;
    2433   Int startTotalBit;
    2434   startBit = m_pcBitIf->getNumberOfWrittenBits();
    2435   startTotalBit = m_pcBitIf->getNumberOfWrittenBits();
    2436 #endif
    2437 
    24382744    //for each size
    24392745    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    24412747      for(listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    24422748      {
    2443 #if SCALING_LIST_OUTPUT_RESULT
    2444         startBit = m_pcBitIf->getNumberOfWrittenBits();
    2445 #endif
    24462749        scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    24472750        WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     
    24542757          xCodeScalingList(scalingList, sizeId, listId);
    24552758        }
    2456 #if SCALING_LIST_OUTPUT_RESULT
    2457         printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
    2458 #endif
    2459       }
    2460     }
    2461 #if SCALING_LIST_OUTPUT_RESULT
    2462   printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
    2463 #endif
     2759      }
     2760    }
    24642761  return;
    24652762}
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r833 r872  
    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 *
     
    120120 
    121121  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
    122   Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
    123   Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
    124   Void codeSaoMerge  ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    125   Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    126   Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
    127 
     122  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
    128123  Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
    129124  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r833 r872  
    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 *
     
    177177  Int       m_maxNumOffsetsPerPic;
    178178  Bool      m_saoLcuBoundary;
    179   Bool      m_saoLcuBasedOptimization;
    180 
    181   //====== Lossless ========
    182   Bool      m_useLossless;
    183179  //====== Motion search ========
    184180  Int       m_iFastSearch;                      //  0:Full search  1:Diamond  2:PMVFAST
     
    201197 
    202198  //====== Tool list ========
    203   Bool      m_bUseSBACRD;
    204199  Bool      m_bUseASR;
    205200  Bool      m_bUseHADME;
     
    292287  Int       m_TMVPModeId;
    293288  Int       m_signHideFlag;
    294 #if RATE_CONTROL_LAMBDA_DOMAIN
    295289  Bool      m_RCEnableRateControl;
    296290  Int       m_RCTargetBitrate;
    297 #if M0036_RC_IMPROVEMENT
    298291  Int       m_RCKeepHierarchicalBit;
    299 #else
    300   Bool      m_RCKeepHierarchicalBit;
    301 #endif
    302292  Bool      m_RCLCULevelRC;
    303293  Bool      m_RCUseLCUSeparateModel;
     
    311301  Bool      m_bViewWiseRateCtrl;
    312302#endif
    313 #else
    314   Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
    315   Int       m_targetBitrate;                                 ///< target bitrate
    316   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
    317 
    318 #if KWU_RC_MADPRED_E0227
    319   UInt       m_depthMADPred;
    320 #endif
    321 #if KWU_RC_VIEWRC_E0227
    322   Bool      m_bViewWiseRateCtrl;
    323 #endif
    324 #endif
    325303  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    326   Bool      m_CUTransquantBypassFlagValue;                    ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.
     304  Bool      m_CUTransquantBypassFlagForce;                    ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true.
    327305#if H_MV
    328306  TComVPS*  m_cVPS;                                           ///< pointer to VPS, same for all layers
     
    369347
    370348  Bool      m_useStrongIntraSmoothing;                        ///< enable the use of strong intra smoothing (bi_linear interpolation) for 32x32 blocks when reference samples are flat.
     349#if H_MV_HLS_7_SEI_P0204_26
     350  Bool              m_subBistreamPropSEIEnabled;
     351  Int               m_numAdditionalSubStreams;
     352  std::vector<Int>  m_subBitstreamMode;
     353  std::vector<Int>  m_outputLayerSetIdxToVps;
     354  std::vector<Int>  m_highestSublayerId;
     355  std::vector<Int>  m_avgBitRate;
     356  std::vector<Int>  m_maxBitRate;
     357#endif
    371358
    372359#if H_MV
     
    573560  Void      setQPAdaptationRange            ( Int   i )      { m_iQPAdaptationRange = i; }
    574561 
    575   //====== Lossless ========
    576   Void      setUseLossless                  (Bool    b  )        { m_useLossless = b;  }
    577562  //====== Sequence ========
    578563  Int       getFrameRate                    ()      { return  m_iFrameRate; }
     
    617602  Bool      getUseAdaptiveQP                ()      { return  m_bUseAdaptiveQP; }
    618603  Int       getQPAdaptationRange            ()      { return  m_iQPAdaptationRange; }
    619   //====== Lossless ========
    620   Bool      getUseLossless                  ()      { return  m_useLossless;  }
    621604 
    622605  //==== Tool list ========
    623   Void      setUseSBACRD                    ( Bool  b )     { m_bUseSBACRD  = b; }
    624606  Void      setUseASR                       ( Bool  b )     { m_bUseASR     = b; }
    625607  Void      setUseHADME                     ( Bool  b )     { m_bUseHADME   = b; }
     
    640622  Void      setdQPs                         ( Int*  p )     { m_aidQP       = p; }
    641623  Void      setDeltaQpRD                    ( UInt  u )     {m_uiDeltaQpRD  = u; }
    642   Bool      getUseSBACRD                    ()      { return m_bUseSBACRD;  }
    643624  Bool      getUseASR                       ()      { return m_bUseASR;     }
    644625  Bool      getUseHADME                     ()      { return m_bUseHADME;   }
     
    684665  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
    685666  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
    686   Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
    687   Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
    688667  Void  setLFCrossTileBoundaryFlag               ( Bool   val  )       { m_loopFilterAcrossTilesEnabledFlag = val; }
    689668  Bool  getLFCrossTileBoundaryFlag               ()                    { return m_loopFilterAcrossTilesEnabledFlag;   }
     
    809788  Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
    810789  Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
     790
     791#if H_MV_HLS_7_SEI_P0204_26
     792  Bool   getSubBitstreamPropSEIEnabled()        { return m_subBistreamPropSEIEnabled;}
     793  Void   setSubBitstreamPropSEIEnabled(Bool x)  { m_subBistreamPropSEIEnabled = x;}
     794
     795  Int    getNumAdditionalSubStreams()           { return m_numAdditionalSubStreams;}
     796  Void   setNumAdditionalSubStreams(Int x)      { m_numAdditionalSubStreams = x;}
     797
     798  std::vector<Int> const &getSubBitstreamMode()  { return m_subBitstreamMode;}
     799  Int   getSubBitstreamMode(Int idx)  { return m_subBitstreamMode[idx];}
     800  Void  setSubBitstreamMode(std::vector<Int> &x)  { m_subBitstreamMode = x;}
     801
     802  std::vector<Int> const &getOutputLayerSetIdxToVps()  { return m_outputLayerSetIdxToVps;}
     803  Int   getOutputLayerSetIdxToVps(Int idx)  { return m_outputLayerSetIdxToVps[idx];}
     804  Void  setOutputLayerSetIdxToVps(std::vector<Int> &x)  { m_outputLayerSetIdxToVps = x;}
     805
     806  std::vector<Int> const &getHighestSublayerId()  { return m_highestSublayerId;}
     807  Int   getHighestSublayerId(Int idx)  { return m_highestSublayerId[idx];}
     808  Void  setHighestSublayerId(std::vector<Int> &x)  { m_highestSublayerId = x;}
     809
     810  std::vector<Int> const &getAvgBitRate()  { return m_avgBitRate;}
     811  Int   getAvgBitRate(Int idx)  { return m_avgBitRate[idx];}
     812  Void  setAvgBitRate(std::vector<Int> &x)  { m_avgBitRate = x;}
     813
     814  std::vector<Int> const &getMaxBitRate()  { return m_maxBitRate;}
     815  Int   getMaxBitRate(Int idx)  { return m_maxBitRate[idx];}
     816  Void  setMaxBitRate(std::vector<Int> &x)  { m_maxBitRate = x;}
     817
     818#endif
    811819  Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
    812820  Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
     
    825833  Void      setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; }
    826834  Int       getSignHideFlag()                    { return m_signHideFlag; }
    827 #if RATE_CONTROL_LAMBDA_DOMAIN
    828835  Bool      getUseRateCtrl         ()              { return m_RCEnableRateControl;   }
    829836  Void      setUseRateCtrl         ( Bool b )      { m_RCEnableRateControl = b;      }
    830837  Int       getTargetBitrate       ()              { return m_RCTargetBitrate;       }
    831838  Void      setTargetBitrate       ( Int bitrate ) { m_RCTargetBitrate  = bitrate;   }
    832 #if M0036_RC_IMPROVEMENT
    833839  Int       getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    834840  Void      setKeepHierBit         ( Int i )       { m_RCKeepHierarchicalBit = i;    }
    835 #else
    836   Bool      getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    837   Void      setKeepHierBit         ( Bool b )      { m_RCKeepHierarchicalBit = b;    }
    838 #endif
    839841  Bool      getLCULevelRC          ()              { return m_RCLCULevelRC; }
    840842  Void      setLCULevelRC          ( Bool b )      { m_RCLCULevelRC = b; }
     
    854856  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
    855857#endif
    856 #else
    857   Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
    858   Void      setUseRateCtrl    (Bool flag)       { m_enableRateCtrl = flag;    }
    859   Int       getTargetBitrate  ()                { return m_targetBitrate;     }
    860   Void      setTargetBitrate  (Int target)      { m_targetBitrate  = target;  }
    861   Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
    862   Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
    863 
    864 #if KWU_RC_MADPRED_E0227
    865   UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
    866   Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
    867 #endif
    868 #if KWU_RC_VIEWRC_E0227
    869   Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
    870   Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
    871 #endif
    872 #endif
    873858  Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
    874859  Void      setTransquantBypassEnableFlag(Bool flag)  { m_TransquantBypassEnableFlag = flag; }
    875   Bool      getCUTransquantBypassFlagValue()          { return m_CUTransquantBypassFlagValue; }
    876   Void      setCUTransquantBypassFlagValue(Bool flag) { m_CUTransquantBypassFlagValue = flag; }
     860  Bool      getCUTransquantBypassFlagForceValue()          { return m_CUTransquantBypassFlagForce; }
     861  Void      setCUTransquantBypassFlagForceValue(Bool flag) { m_CUTransquantBypassFlagForce = flag; }
    877862#if H_MV
    878863  Void      setVPS           ( TComVPS *p ) { m_cVPS = p;    }
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r833 r872  
    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 *
     
    109109 
    110110  m_bEncodeDQP = false;
    111 #if RATE_CONTROL_LAMBDA_DOMAIN
    112 #if !M0036_RC_IMPROVEMENT
    113   m_LCUPredictionSAD = 0;
    114   m_addSADDepth      = 0;
    115   m_temporalSAD      = 0;
    116 #endif
    117 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    118   m_LCUPredictionSAD = 0;
    119   m_addSADDepth      = 0;
    120   m_temporalSAD      = 0;
    121   m_spatialSAD       = 0;
    122 #endif
    123 #endif
    124 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     111#if KWU_RC_MADPRED_E0227
    125112  m_LCUPredictionSAD = 0;
    126113  m_addSADDepth      = 0;
     
    273260  m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder();
    274261 
    275   m_bUseSBACRD        = pcEncTop->getUseSBACRD();
    276262  m_pcRateCtrl        = pcEncTop->getRateCtrl();
    277263}
     
    289275  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    290276
    291 #if RATE_CONTROL_LAMBDA_DOMAIN
    292 #if !M0036_RC_IMPROVEMENT
    293   m_addSADDepth      = 0;
    294   m_LCUPredictionSAD = 0;
    295   m_temporalSAD      = 0;
    296 #endif
    297 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    298   m_LCUPredictionSAD = 0;
    299   m_addSADDepth      = 0;
    300   m_temporalSAD      = 0;
    301   m_spatialSAD       = 0;
    302 #endif
    303 #endif
    304277#if KWU_RC_MADPRED_E0227
    305278  m_LCUPredictionSAD = 0;
     
    450423  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
    451424
    452   // variables for fast encoder decision
    453425#if H_3D_QTLPC 
    454426  Bool    bTrySplit     = true;
     
    478450  UInt uiBPelY   = uiTPelY + rpcBestCU->getHeight(0) - 1;
    479451
     452#if H_MV_ENC_DEC_TRAC
     453#if ENC_DEC_TRACE
     454    stopAtPos  ( rpcBestCU->getSlice()->getPOC(),
     455                 rpcBestCU->getSlice()->getLayerId(),
     456                 rpcBestCU->getCUPelX(),
     457                 rpcBestCU->getCUPelY(),
     458                 rpcBestCU->getWidth(0),
     459                 rpcBestCU->getHeight(0) );
     460#endif
     461#endif
     462
    480463  Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
    481464  Int iMinQP;
    482465  Int iMaxQP;
    483466  Bool isAddLowestQP = false;
    484   Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
    485467
    486468  if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     
    489471    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    490472    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
    491     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    492     {
    493       isAddLowestQP = true;
    494       iMinQP = iMinQP - 1;
    495     }
    496473  }
    497474  else
     
    501478  }
    502479
    503 #if RATE_CONTROL_LAMBDA_DOMAIN
    504480  if ( m_pcEncCfg->getUseRateCtrl() )
    505481  {
     
    507483    iMaxQP = m_pcRateCtrl->getRCQP();
    508484  }
    509 #else
    510   if(m_pcEncCfg->getUseRateCtrl())
    511   {
    512     Int qp = m_pcRateCtrl->getUnitQP();
    513     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    514     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    515   }
    516 #endif
     485  // transquant-bypass (TQB) processing loop variable initialisation ---
     486
     487  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.
     488
     489  if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) )
     490  {
     491    isAddLowestQP = true; // mark that the first iteration is to cost TQB mode.
     492    iMinQP = iMinQP - 1;  // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
     493    if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
     494    {
     495      iMaxQP = iMinQP;
     496    }
     497  }
     498
    517499#if H_3D_IC
    518500  Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth();
     
    534516    for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    535517    {
    536       if (isAddLowestQP && (iQP == iMinQP))
     518      const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     519
     520      if (bIsLosslessMode)
    537521      {
    538522        iQP = lowestQP;
    539523      }
    540       // variables for fast encoder decision
     524
    541525#if H_3D_QTLPC
    542526      bTrySplit    = true;
    543527#endif
    544528
    545       rpcTempCU->initEstData( uiDepth, iQP );
     529      rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    546530#if H_3D_QTLPC
    547531      //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU
     
    647631#endif
    648632#if  H_3D_FAST_TEXTURE_ENCODING
    649           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
    650 #else
    651           xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
     633          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode  );//by Competition for inter_2Nx2N
     634#else
     635          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
     636          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N
    652637#endif
    653638#if H_3D_VSP
     
    663648        bFMD = bIVFMerge && rpcBestCU->isSkipped(0);
    664649#endif
    665         rpcTempCU->initEstData( uiDepth, iQP );
     650        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    666651#if H_3D_VSP
    667652        rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    675660#endif
    676661#if  H_3D_FAST_TEXTURE_ENCODING
    677             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );
    678 #else
    679             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
     662            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
     663#else
     664          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
     665          rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    680666#endif
    681667#if H_3D_VSP
     
    687673          {
    688674            xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU, false );
    689             rpcTempCU->initEstData( uiDepth, iQP );
     675            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    690676#if H_3D_VSP
    691677            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    710696      }
    711697#endif
    712       if (isAddLowestQP && (iQP == lowestQP))
     698      if ( bIsLosslessMode )
    713699      {
    714700        iQP = iMinQP;
     
    716702    }
    717703
    718 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     704#if KWU_RC_MADPRED_E0227
    719705    if ( uiDepth <= m_addSADDepth )
    720706    {
     
    723709    }
    724710#endif
    725 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    726     if ( uiDepth <= m_addSADDepth )
    727     {
    728       m_LCUPredictionSAD += m_temporalSAD;
    729       m_addSADDepth = uiDepth;
    730     }
    731 #endif
    732 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
    733 if ( uiDepth <= m_addSADDepth )
    734 {
    735   m_LCUPredictionSAD += m_temporalSAD;
    736   m_addSADDepth = uiDepth;
    737 }
    738 #endif
    739 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
    740     if(m_pcEncCfg->getUseRateCtrl())
    741     {
    742       Int qp = m_pcRateCtrl->getUnitQP();
    743       iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    744       iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    745     }
    746 #endif
    747 
    748711#if H_3D_DIM_ENC
    749712    if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() )
     
    757720      for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    758721      {
    759         if (isAddLowestQP && (iQP == iMinQP))
     722        const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
     723
     724        if (bIsLosslessMode)
    760725        {
    761726          iQP = lowestQP;
    762727        }
    763         rpcTempCU->initEstData( uiDepth, iQP );
     728        rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    764729
    765730        // do inter modes, NxN, 2NxN, and Nx2N
     
    780745                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    781746#endif
    782                 rpcTempCU->initEstData( uiDepth, iQP );
     747                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    783748#if H_3D_VSP
    784749                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    799764            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N  );
    800765#endif
    801             rpcTempCU->initEstData( uiDepth, iQP );
     766            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    802767#if H_3D_VSP
    803768            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    819784            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN  );
    820785#endif
    821             rpcTempCU->initEstData( uiDepth, iQP );
     786            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    822787#if H_3D_VSP
    823788            rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    858823                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
    859824#endif
    860                 rpcTempCU->initEstData( uiDepth, iQP );
     825                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    861826#if H_3D_VSP
    862827                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    878843                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    879844#endif
    880                 rpcTempCU->initEstData( uiDepth, iQP );
     845                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    881846#if H_3D_VSP
    882847                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    902867                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true );
    903868#endif
    904                 rpcTempCU->initEstData( uiDepth, iQP );
     869                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    905870#if H_3D_VSP
    906871                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    922887                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true );
    923888#endif
    924                 rpcTempCU->initEstData( uiDepth, iQP );
     889                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    925890#if H_3D_VSP
    926891                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    948913                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    949914#endif
    950                 rpcTempCU->initEstData( uiDepth, iQP );
     915                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    951916#if H_3D_VSP
    952917                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    968933                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
    969934#endif
    970                 rpcTempCU->initEstData( uiDepth, iQP );
     935                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    971936#if H_3D_VSP
    972937                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    988953                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );
    989954#endif
    990                 rpcTempCU->initEstData( uiDepth, iQP );
     955                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    991956#if H_3D_VSP
    992957                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    1008973                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );
    1009974#endif
    1010                 rpcTempCU->initEstData( uiDepth, iQP );
     975                rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1011976#if H_3D_VSP
    1012977                rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    1022987#endif
    1023988              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU );
    1024               rpcTempCU->initEstData( uiDepth, iQP );
     989              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1025990#if H_3D_VSP
    1026991              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    1027992#endif
    1028993              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD );
    1029               rpcTempCU->initEstData( uiDepth, iQP );
     994              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    1030995#if H_3D_VSP
    1031996              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    10371002#endif
    10381003              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );
    1039               rpcTempCU->initEstData( uiDepth, iQP );
     1004              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    10401005#if H_3D_VSP
    10411006              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    10421007#endif
    10431008              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );
    1044               rpcTempCU->initEstData( uiDepth, iQP );
     1009              rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    10451010#if H_3D_VSP
    10461011              rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
     
    10721037            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
    10731038
    1074 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     1039#if KWU_RC_MADPRED_E0227
    10751040            if ( uiDepth <= m_addSADDepth )
    10761041            {
     
    10791044            }
    10801045#endif
    1081 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    1082             if ( uiDepth <= m_addSADDepth )
    1083             {
    1084               m_LCUPredictionSAD += m_spatialSAD;
    1085               m_addSADDepth = uiDepth;
    1086             }
    1087 #endif
    1088 
    1089 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
    1090             if ( uiDepth <= m_addSADDepth )
    1091             {
    1092               m_LCUPredictionSAD += m_spatialSAD;
    1093               m_addSADDepth = uiDepth;
    1094             }
    1095 #endif
    1096             rpcTempCU->initEstData( uiDepth, iQP );
     1046
     1047            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    10971048            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
    10981049            {
     
    11041055                {
    11051056                  xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN   );
    1106                   rpcTempCU->initEstData( uiDepth, iQP );
     1057                  rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    11071058                }
    11081059#if H_3D_QTLPC
     
    11261077          {
    11271078            xCheckIntraPCM (rpcBestCU, rpcTempCU);
    1128             rpcTempCU->initEstData( uiDepth, iQP );
     1079            rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    11291080          }
    11301081        }
     
    11321083        }
    11331084#endif
    1134         if (isAddLowestQP && (iQP == lowestQP))
     1085        if (bIsLosslessMode)
    11351086        {
    11361087          iQP = iMinQP;
     
    11421093    m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true );
    11431094    rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    1144     if(m_pcEncCfg->getUseSBACRD())
    1145     {
    11461095      rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1147     }
    1148 
    1149 #if H_3D_VSO // M8
     1096    #if H_3D_VSO // M8
    11501097    if ( m_pcRdCost->getUseVSO() )   
    11511098      rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );   
     
    11731120  {
    11741121    bBoundary = true;
    1175 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    1176     m_addSADDepth++;
    1177 #endif
    11781122  }
    11791123
     
    11881132    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    11891133    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
    1190     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    1191     {
    1192       isAddLowestQP = true;
    1193       iMinQP = iMinQP - 1;     
    1194     }
    11951134  }
    11961135  else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
     
    12141153    iMaxQP = iStartQP;
    12151154  }
    1216 #if RATE_CONTROL_LAMBDA_DOMAIN
    12171155  if ( m_pcEncCfg->getUseRateCtrl() )
    12181156  {
     
    12201158    iMaxQP = m_pcRateCtrl->getRCQP();
    12211159  }
    1222 #else
    1223   if(m_pcEncCfg->getUseRateCtrl())
    1224   {
    1225     Int qp = m_pcRateCtrl->getUnitQP();
    1226     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    1227     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    1228   }
    1229 #endif
     1160
     1161  if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
     1162  {
     1163    iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here.
     1164  }
    12301165  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    12311166  {
    1232     if (isAddLowestQP && (iQP == iMinQP))
    1233     {
    1234       iQP = lowestQP;
    1235     }
    1236     rpcTempCU->initEstData( uiDepth, iQP );
     1167    const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true.
     1168    rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );
    12371169
    12381170    // further split
     
    12671199        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
    12681200        {
    1269           if( m_bUseSBACRD )
    1270           {
    12711201            if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer
    12721202            {
     
    12771207              m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    12781208            }
    1279           }
    12801209
    12811210#if AMP_ENC_SPEEDUP
     
    13081237
    13091238        rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits
    1310         if(m_pcEncCfg->getUseSBACRD())
    1311         {
    13121239          rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    13131240        }
    1314       }
    1315 
    13161241#if H_3D_VSO // M10
    13171242      if ( m_pcRdCost->getUseVSO() )
     
    13491274          m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false );
    13501275          rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    1351           if(m_pcEncCfg->getUseSBACRD())
    1352           {
    13531276            rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    1354           }
    13551277#if H_3D_VSO // M11
    13561278          if ( m_pcRdCost->getUseLambdaScaleVSO())         
     
    13711293      }
    13721294
    1373       if( m_bUseSBACRD )
    1374       {
    13751295        m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    1376       }
    13771296      Bool isEndOfSlice        = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES
    13781297                                 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3);
     
    13851304      xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth);                                  // RD compare current larger prediction
    13861305    }                                                                                  // with sub partitioned prediction.
    1387     if (isAddLowestQP && (iQP == lowestQP))
    1388     {
    1389       iQP = iMinQP;
    1390     }
    1391   }
    1392 
     1306    }
    13931307
    13941308#if H_3D_VSO // M12
     
    14021316  }
    14031317#endif
    1404 
    14051318  rpcBestCU->copyToPic(uiDepth);                                                     // Copy Best data to Picture for next partition prediction.
    14061319
     
    16831596}
    16841597
    1685 #if RATE_CONTROL_INTRA
    16861598Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
    16871599{
     
    17981710  return(iSumHad);
    17991711}
    1800 #endif
    18011712
    18021713/** check RD costs for a CU block encoded with merge
     
    18161727#endif
    18171728  Int numValidMergeCand = 0;
     1729  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
    18181730
    18191731  for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui )
     
    18401752#else
    18411753  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    1842   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
    18431754#endif
    18441755
     
    19101821    memset( mergeCandBuffer, 0, MRG_MAX_NUM_CANDS_MEM*sizeof(Int) );
    19111822    rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
     1823#if !UPDATE_HM13
    19121824    rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
     1825#endif
    19131826    rpcTempCU->setARPWSubParts( (UChar)nARPW , 0 , uhDepth );
    19141827#if H_3D_IC
     
    19681881          // set MC parameters
    19691882          rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level
    1970           rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(),     0, uhDepth );
     1883          rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag,     0, uhDepth );
    19711884          rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    19721885#if H_3D_IC
     
    19821895          rpcTempCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMergeCand].m_acDvInfo, 0, 0, uhDepth );
    19831896#endif
    1984 
    19851897#if MTK_DDD_G0063
    19861898          if( rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewIndex() != 0 && iDDDCand == uiMergeCand )
     
    19941906          }
    19951907#endif
    1996 
    19971908#if H_3D_SPIVMP
    19981909          rpcTempCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMergeCand], 0, 0, uhDepth);
     
    20021913            Int iWidth = rpcTempCU->getWidth(0);
    20031914            Int iHeight = rpcTempCU->getHeight(0);
    2004 
    20051915            Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
    2006 
    20071916            rpcTempCU->getSPPara(iWidth, iHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
    2008 
    20091917            for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
    20101918            {
     
    20181926#endif
    20191927#if NTT_STORE_SPDV_VSP_G0148
     1928            {
    20201929          if ( vspFlag[uiMergeCand] )
    20211930          {
     
    20241933            Int width, height;
    20251934            rpcTempCU->getPartIndexAndSize( 0, partAddr, width, height );
    2026 
    20271935            if( uhInterDirNeighbours[ uiMergeCand ] & 0x01 )
    20281936            {
     
    20431951              rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    20441952            }
    2045 
    20461953            rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    20471954          }
    20481955          else
    2049 #endif
    20501956          {
     1957#endif
    20511958            rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    20521959            rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    20531960            rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
     1961#if NTT_STORE_SPDV_VSP_G0148
    20541962          }
     1963        }
     1964#endif
    20551965       // do MC
    20561966       m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
     
    21022012              if( rpcTempCU != rpcTempCUPre )
    21032013              {
    2104                 rpcTempCU->initEstData( uhDepth, orgQP );
     2014                rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    21052015                rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
    21062016              }
     
    21322042            if( rpcTempCU != rpcTempCUPre )
    21332043            {
    2134               rpcTempCU->initEstData( uhDepth, orgQP );
     2044              rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    21352045              rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
    21362046            }
     
    21602070          }
    21612071#endif
    2162           rpcTempCU->initEstData( uhDepth, orgQP );
     2072          rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag );
    21632073
    21642074      if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
     
    22312141#endif
    22322142{
     2143
     2144#if UPDATE_HM13
     2145#if H_3D
     2146  const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0);
     2147#endif
     2148#endif
    22332149#if  H_3D_FAST_TEXTURE_ENCODING
    22342150  if(!(bFMD && (ePartSize == SIZE_2Nx2N)))  //have  motion estimation or merge check
     
    22542170    if( bFirstTime == false && rpcTempCU->getSlice()->getVPS()->getUseAdvRP( iLayerId ) )
    22552171    {
     2172#if UPDATE_HM13
     2173      rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0),bTransquantBypassFlag );     
     2174#else
    22562175      rpcTempCU->initEstData( rpcTempCU->getDepth(0), rpcTempCU->getQP(0) );
     2176#endif
    22572177    }
    22582178#endif
     
    22742194  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
    22752195  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    2276   rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(),      0, uhDepth );
    2277  
    22782196#if MTK_DDD_G0063
    22792197  rpcTempCU->setUseDDD( false, 0, uhDepth );
     
    23282246#endif
    23292247
    2330 #if RATE_CONTROL_LAMBDA_DOMAIN  && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
     2248#if KWU_RC_MADPRED_E0227
    23312249  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    23322250  {
     
    23372255  }
    23382256#endif
    2339 #if !RATE_CONTROL_LAMBDA_DOMAIN  && KWU_RC_MADPRED_E0227
    2340   if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    2341   {
    2342     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    2343       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    2344       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    2345     m_temporalSAD = (Int)SAD;
    2346   }
    2347 #endif
    2348 
    23492257  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
    2350  
    23512258#if NTT_STORE_SPDV_VSP_G0148 // possible bug fix
    23522259  if( rpcTempCU->getQtRootCbf(0)==0 )
     
    23612268  else
    23622269#endif
     2270
    23632271  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    23642272#if H_3D_INTER_SDC
     
    23802288      {
    23812289        Int orgQP = rpcBestCU->getQP( 0 );
     2290#if UPDATE_HM13
     2291        rpcTempCU->initEstData( uhDepth, orgQP ,bTransquantBypassFlag );     
     2292#else
    23822293        rpcTempCU->initEstData( uhDepth, orgQP );
     2294#endif
    23832295        rpcTempCU->copyPartFrom( rpcBestCU, 0, uhDepth );
    23842296      }
     
    26572569  rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth );
    26582570  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    2659   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
    26602571 
    26612572  Bool bSeparateLumaChroma = true; // choose estimation mode
     
    26932604  setdQPFlag( bCodeDQP );
    26942605 
    2695   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     2606  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    26962607 
    26972608  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    2698   if(m_pcEncCfg->getUseSBACRD())
    2699   {
    27002609    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2701   }
    2702 
    27032610#if H_3D_VSO // M6
    27042611  if( m_pcRdCost->getUseLambdaScaleVSO()) 
     
    27082615  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    27092616 
    2710 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    2711   UChar uhDepth = rpcTempCU->getDepth( 0 );
    2712   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    2713   {
    2714     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    2715       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    2716       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    2717     m_spatialSAD = (Int)SAD;
    2718   }
    2719 #endif
    2720 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
    2721   UChar uhDepth = rpcTempCU->getDepth( 0 );
    2722   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    2723   {
    2724     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    2725       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    2726       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    2727     m_spatialSAD = (Int)SAD;
    2728   }
    2729 #endif
    2730 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
    2731   UChar uhDepth = rpcTempCU->getDepth( 0 );
    2732   if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    2733   {
    2734     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    2735       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    2736       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    2737     m_spatialSAD = (Int)SAD;
    2738   }
    2739 #endif
    27402617  xCheckDQP( rpcTempCU );
    27412618  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
     
    27602637  rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth );
    27612638  rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth );
    2762   rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );
    27632639
    27642640  m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
    27652641
    2766   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
     2642  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    27672643
    27682644  m_pcEntropyCoder->resetBits();
     
    27792655  m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true );
    27802656
    2781   if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
     2657  m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    27822658
    27832659  rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
    2784   if(m_pcEncCfg->getUseSBACRD())
    2785   {
    27862660    rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2787   }
    27882661#if H_3D_VSO // M44
    27892662  if ( m_pcRdCost->getUseVSO() )
     
    28252698    pcCU  = NULL;
    28262699
    2827     if( m_bUseSBACRD )  // store temp best CI for next CU coding
     2700    // store temp best CI for next CU coding
    28282701      m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
    28292702  }
     
    28422715      m_pcEntropyCoder->encodeQP( pcCU, 0, false );
    28432716      pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits
    2844       if(m_pcEncCfg->getUseSBACRD())
    2845       {
    28462717        pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded();
    2847       }
    28482718#if H_3D_VSO // M45
    28492719      if ( m_pcRdCost->getUseVSO() )     
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r833 r872  
    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  TEncSbac***             m_pppcRDSbacCoder;
    105105  TEncSbac*               m_pcRDGoOnSbacCoder;
    106   Bool                    m_bUseSBACRD;
    107106  TEncRateCtrl*           m_pcRateCtrl;
    108 #if RATE_CONTROL_LAMBDA_DOMAIN
    109 #if !M0036_RC_IMPROVEMENT
    110   UInt                    m_LCUPredictionSAD;
    111   Int                     m_addSADDepth;
    112   Int                     m_temporalSAD;
    113 #endif
    114 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     107#if KWU_RC_MADPRED_E0227
    115108  UInt                    m_LCUPredictionSAD;
    116109  Int                     m_addSADDepth;
     
    118111  Int                     m_spatialSAD;
    119112#endif
    120 #endif
    121 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
    122   UInt                    m_LCUPredictionSAD;
    123   Int                     m_addSADDepth;
    124   Int                     m_temporalSAD;
    125   Int                     m_spatialSAD;
    126 #endif
    127 
    128113public:
    129114  /// copy parameters from encoder class
     
    143128 
    144129  Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
    145 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
     130#if KWU_RC_MADPRED_E0227
    146131  UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
    147132#endif
    148 #if RATE_CONTROL_INTRA
    149133  Int   updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height );
    150 #endif
    151134protected:
    152135  Void  finishCU            ( TComDataCU*  pcCU, UInt uiAbsPartIdx,           UInt uiDepth        );
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r833 r872  
    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 (pcSlice->getSPS()->getUseSAO())
    54   {
    55     SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    56     pcSlice->setSaoEnabledFlag     (saoParam->bSaoFlag[0]);
    57     {
    58       pcSlice->setSaoEnabledFlagChroma   (saoParam->bSaoFlag[1]);
    59     }
    60   }
    61 
    6253  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
    6354  return;
     
    787778}
    788779
    789 /** Encode SAO Offset
    790  * \param  saoLcuParam SAO LCU paramters
    791  */
    792 Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)
    793 {
    794   UInt uiSymbol;
    795   Int i;
    796 
    797   uiSymbol = saoLcuParam->typeIdx + 1;
    798   if (compIdx!=2)
    799   {
    800     m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);
    801   }
    802   if (uiSymbol)
    803   {
    804     if (saoLcuParam->typeIdx < 4 && compIdx != 2)
    805     {
    806       saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;
    807     }
    808     Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;
    809     Int offsetTh = 1 << min(bitDepth - 5,5);
    810     if( saoLcuParam->typeIdx == SAO_BO )
    811     {
    812       for( i=0; i< saoLcuParam->length; i++)
    813       {
    814         UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);
    815         m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);
    816       } 
    817       for( i=0; i< saoLcuParam->length; i++)
    818       {
    819         if (saoLcuParam->offset[i] != 0)
    820         {
    821           UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;
    822           m_pcEntropyCoderIf->codeSAOSign(sign);
    823         }
    824       }
    825       uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
    826       m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);
    827     }
    828     else if( saoLcuParam->typeIdx < 4 )
    829     {
    830       m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);
    831       m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);
    832       m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);
    833       m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);
    834       if (compIdx!=2)
    835       {
    836         uiSymbol = (UInt) (saoLcuParam->subTypeIdx);
    837         m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);
    838       }
    839     }
    840   }
    841 }
    842 
    843 /** Encode SAO unit interleaving
    844 * \param  rx
    845 * \param  ry
    846 * \param  pSaoParam
    847 * \param  pcCU
    848 * \param  iCUAddrInSlice
    849 * \param  iCUAddrUpInSlice
    850 * \param  bLFCrossSliceBoundaryFlag
    851  */
    852 Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)
    853 {
    854   if (saoFlag)
    855   {
    856     if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)
    857     {
    858       m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);
    859     }
    860     else
    861     {
    862       saoLcuParam->mergeLeftFlag = 0;
    863     }
    864     if (saoLcuParam->mergeLeftFlag == 0)
    865     {
    866       if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )
    867       {
    868         m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);
    869       }
    870       else
    871       {
    872         saoLcuParam->mergeUpFlag = 0;
    873       }
    874       if (!saoLcuParam->mergeUpFlag)
    875       {
    876         encodeSaoOffset(saoLcuParam, compIdx);
    877       }
    878     }
    879   }
    880 }
    881 
    882780Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
    883781{
     
    996894}
    997895#endif
    998 
    999896//! \}
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r833 r872  
    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 *
     
    127127  virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    128128  virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0;
    129   virtual Void codeSAOSign          ( UInt code   ) = 0;
    130   virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
    131   virtual Void codeSaoMerge    ( UInt   uiCode  ) = 0;
    132   virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    133   virtual Void codeSaoUflc         ( UInt uiLength, UInt   uiCode ) = 0;
     129  virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
    134130  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    135131 
     
    232228 
    233229  Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
    234   Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
    235   Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     230  Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
    236231  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
    237232
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r773 r872  
    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#endif
    106106#endif
     107#if FIX1172
     108  m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP;
     109  m_associatedIRAPPOC  = 0;
     110#endif
    107111  return;
    108112}
     
    292296}
    293297
     298#if H_MV_HLS_7_SEI_P0204_26
     299SEISubBitstreamProperty *TEncGOP::xCreateSEISubBitstreamProperty( TComSPS *sps)
     300{
     301  SEISubBitstreamProperty *seiSubBitstreamProperty = new SEISubBitstreamProperty();
     302
     303  seiSubBitstreamProperty->m_activeVpsId = sps->getVPSId();
     304  /* These values can be determined by the encoder; for now we will use the input parameter */
     305  TEncTop *encTop = this->m_pcEncTop;
     306  seiSubBitstreamProperty->m_numAdditionalSubStreams = encTop->getNumAdditionalSubStreams();
     307  seiSubBitstreamProperty->m_subBitstreamMode        = encTop->getSubBitstreamMode();
     308  seiSubBitstreamProperty->m_outputLayerSetIdxToVps  = encTop->getOutputLayerSetIdxToVps();
     309  seiSubBitstreamProperty->m_highestSublayerId       = encTop->getHighestSublayerId();
     310  seiSubBitstreamProperty->m_avgBitRate              = encTop->getAvgBitRate();
     311  seiSubBitstreamProperty->m_maxBitRate              = encTop->getMaxBitRate();
     312
     313  return seiSubBitstreamProperty;
     314}
     315#endif
     316
    294317Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
    295318{
     
    342365    delete sei;
    343366  }
     367#if H_MV_HLS_7_SEI_P0204_26
     368  if( m_pcCfg->getSubBitstreamPropSEIEnabled() )
     369  {
     370    SEISubBitstreamProperty *sei = xCreateSEISubBitstreamProperty ( sps );
     371
     372    nalu = NALUnit(NAL_UNIT_PREFIX_SEI);
     373    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     374    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     375    writeRBSPTrailingBits(nalu.m_Bitstream);
     376    accessUnit.push_back(new NALUnitEBSP(nalu));
     377    delete sei;
     378  }
     379#endif
    344380}
    345381
     
    472508    }
    473509
    474     if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     510    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 )
    475511    {
    476512      m_iLastIDR = pocCurr;
     
    551587#if H_MV
    552588    // Set the nal unit type
    553     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
     589    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField));
    554590    if( pcSlice->getSliceType() == B_SLICE )
    555591    {
     
    559595      }
    560596    }
     597
     598// To be checked!
     599    if( pcSlice->getSliceType() == B_SLICE )
     600    {
     601      if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'I' )
     602      {
     603        pcSlice->setSliceType( I_SLICE );
     604      }
     605    }
    561606#else
    562607    if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P')
     
    564609      pcSlice->setSliceType(P_SLICE);
    565610    }
     611    if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='I')
     612    {
     613      pcSlice->setSliceType(I_SLICE);
     614    }
     615   
    566616    // Set the nal unit type
    567     pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
     617    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField));
    568618#endif
    569619    if(pcSlice->getTemporalLayerNonReferenceFlag())
     
    589639    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
    590640    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
    591 
    592 #if FIX1071
     641#if FIX1172
     642    if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     643      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     644      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     645      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     646      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     647      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA )  // IRAP picture
     648    {
     649      m_associatedIRAPType = pcSlice->getNalUnitType();
     650      m_associatedIRAPPOC = pocCurr;
     651    }
     652    pcSlice->setAssociatedIRAPType(m_associatedIRAPType);
     653    pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC);
     654#endif
     655
    593656    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
    594657    {
    595658      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
    596659    }
    597 #else
    598     if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)
    599     {
    600       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());
    601     }
    602 #endif
    603660    pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
    604661
    605     if(pcSlice->getTLayer() > 0)
     662    if(pcSlice->getTLayer() > 0
     663      &&  !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N     // Check if not a leading picture
     664          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R
     665          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N
     666          || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R )
     667        )
    606668    {
    607669      if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
     
    613675        else
    614676        {
    615           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
     677          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R);
    616678        }
    617679      }
     
    907969    pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag());
    908970
    909 #if RATE_CONTROL_LAMBDA_DOMAIN
    910971    Double lambda            = 0.0;
    911972    Int actualHeadBits       = 0;
     
    9441005      else if ( frameLevel == 0 )   // intra case, but use the model
    9451006      {
    946 #if RATE_CONTROL_INTRA
    9471007        m_pcSliceEncoder->calCostSliceI(pcPic);
    948 #endif
    9491008        if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
    9501009        {
    9511010          Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
    952 #if RATE_CONTROL_INTRA
    9531011          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
    954 #else
    955           bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );
    956 #endif
    9571012          if ( bits < 200 )
    9581013          {
     
    9631018
    9641019        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    965 #if RATE_CONTROL_INTRA
    9661020        m_pcRateCtrl->getRCPic()->getLCUInitTargetBits();
    9671021        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    968 #else
    969         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    970 #endif
    9711022        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    9721023      }
     
    9841035#endif
    9851036        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    986 #if RATE_CONTROL_INTRA
    9871037        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    988 #else
    989         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    990 #endif
    9911038        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    9921039#if KWU_RC_MADPRED_E0227
     
    10001047      m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda );
    10011048    }
    1002 #endif
    10031049
    10041050    UInt uiNumSlices = 1;
     
    12031249
    12041250    // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
    1205     if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() )
    1206     {
    1207       m_pcSAO->resetStats();
    1208       m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic );
     1251    if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() )
     1252    {
     1253      m_pcSAO->getPreDBFStatistics(pcPic);
    12091254    }
    12101255
     
    12181263    m_pcLoopFilter->loopFilterPic( pcPic );
    12191264
    1220     pcSlice = pcPic->getSlice(0);
    1221     if(pcSlice->getSPS()->getUseSAO())
    1222     {
    1223       std::vector<Bool> LFCrossSliceBoundaryFlag;
    1224       for(Int s=0; s< uiNumSlices; s++)
    1225       {
    1226         LFCrossSliceBoundaryFlag.push_back(  ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) );
    1227       }
    1228       m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1);
    1229       pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary);
    1230     }
    1231 
    1232 
    1233     pcSlice = pcPic->getSlice(0);
    1234 
    1235     if(pcSlice->getSPS()->getUseSAO())
    1236     {
    1237       m_pcSAO->createPicSaoInfo(pcPic);
    1238     }
    1239 
    12401265    /////////////////////////////////////////////////////////////////////////////////////////////////// File writing
    12411266    // Set entropy coder
     
    12541279      writeRBSPTrailingBits(nalu.m_Bitstream);
    12551280      accessUnit.push_back(new NALUnitEBSP(nalu));
    1256 #if RATE_CONTROL_LAMBDA_DOMAIN
    12571281      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1258 #endif
    12591282
    12601283#if H_MV
     
    12961319      writeRBSPTrailingBits(nalu.m_Bitstream);
    12971320      accessUnit.push_back(new NALUnitEBSP(nalu));
    1298 #if RATE_CONTROL_LAMBDA_DOMAIN
    12991321      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1300 #endif
    13011322
    13021323#if H_MV
     
    13131334      writeRBSPTrailingBits(nalu.m_Bitstream);
    13141335      accessUnit.push_back(new NALUnitEBSP(nalu));
    1315 #if RATE_CONTROL_LAMBDA_DOMAIN
    13161336      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1317 #endif
     1337     
    13181338#if PPS_FIX_DEPTH
    13191339      }
     
    13431363        {
    13441364          SOPcurrPOC += deltaPOC;
    1345           SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR);
     1365          SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR, isField);
    13461366          SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId;
    13471367          SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j);
     
    16211641          }
    16221642          m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    1623 #if RATE_CONTROL_LAMBDA_DOMAIN
    16241643          tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
    1625 #endif
    16261644          m_pcEntropyCoder->encodeSliceHeader(pcSlice);
    1627 #if RATE_CONTROL_LAMBDA_DOMAIN
    16281645          actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
    1629 #endif
    16301646
    16311647          // is it needed?
     
    17481764          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
    17491765          accessUnit.push_back(new NALUnitEBSP(nalu));
    1750 #if RATE_CONTROL_LAMBDA_DOMAIN
    17511766          actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1752 #endif
    17531767          bNALUAlignedWrittenToList = true;
    17541768          uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment
     
    17941808              m_pcEntropyCoder->resetEntropy();
    17951809              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
    1796               m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
    1797               SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam();
    1798 
    1799 #if SAO_CHROMA_LAMBDA
    1800 #if SAO_ENCODING_CHOICE
    1801               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth());
    1802 #else
    1803               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
    1804 #endif
    1805 #else
    1806               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda());
    1807 #endif
    1808               m_pcSAO->endSaoEnc();
     1810            Bool sliceEnabled[NUM_SAO_COMPONENTS];
     1811            m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice);
     1812            m_pcSAO->SAOProcess(pcPic
     1813              , sliceEnabled
     1814              , pcPic->getSlice(0)->getLambdas()
     1815#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1816              , m_pcCfg->getSaoLcuBoundary()
     1817#endif
     1818              );
    18091819              m_pcSAO->PCMLFDisableProcess(pcPic);
    1810             }
    1811 #if SAO_RDO
    1812             m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    1813 #endif
    1814             processingState = ENCODE_SLICE;
    1815 
     1820
     1821            //assign SAO slice header
    18161822            for(Int s=0; s< uiNumSlices; s++)
    18171823            {
    1818               if (pcSlice->getSPS()->getUseSAO())
    1819               {
    1820                 pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false);
     1824              pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]);
     1825              assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]);
     1826              pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]);
    18211827              }
    18221828            }
     1829          processingState = ENCODE_SLICE;
    18231830          }
    18241831          break;
     
    18311838        }
    18321839      } // end iteration over slices
    1833 
    1834       if(pcSlice->getSPS()->getUseSAO())
    1835       {
    1836         if(pcSlice->getSPS()->getUseSAO())
    1837         {
    1838           m_pcSAO->destroyPicSaoInfo();
    1839         }
    1840         pcPic->destroyNonDBFilterInfo();
    1841       }
    18421840#if H_3D
    18431841      pcPic->compressMotion(2);
     
    19191917
    19201918    //In case of field coding, compute the interlaced PSNR for both fields
    1921     if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     1919    if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) && (pcPic->getPOC()%m_iGopSize != 1))
    19221920    {
    19231921      //get complementary top field
     
    19311929      xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
    19321930    }
     1931    else if (isField && pcPic->getPOC()!= 0 && (pcPic->getPOC()%m_iGopSize == 0))
     1932    {
     1933      //get complementary bottom field
     1934      TComPic* pcPicBottom;
     1935      TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     1936      while ((*iterPic)->getPOC() != pcPic->getPOC()+1)
     1937      {
     1938        iterPic ++;
     1939      }
     1940      pcPicBottom = *(iterPic);
     1941      xCalculateInterlacedAddPSNR(pcPic, pcPicBottom, pcPic->getPicYuvRec(), pcPicBottom->getPicYuvRec(), accessUnit, dEncTime );
     1942    }
    19331943   
    19341944      if (digestStr)
     
    19471957        }
    19481958      }
    1949 #if RATE_CONTROL_LAMBDA_DOMAIN
    19501959      if ( m_pcCfg->getUseRateCtrl() )
    19511960      {
    1952 #if !M0036_RC_IMPROVEMENT
    1953         Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();
    1954 #endif
    19551961        Double avgQP     = m_pcRateCtrl->getRCPic()->calAverageQP();
    19561962        Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda();
     
    19591965          avgLambda = lambda;
    19601966        }
    1961 #if M0036_RC_IMPROVEMENT
    1962 #if RATE_CONTROL_INTRA
    19631967        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType());
    1964 #else
    1965         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );
    1966 #endif
    1967 #else
    1968         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );
    1969 #endif
    19701968        m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() );
    19711969
     
    19801978        }
    19811979      }
    1982 #else
    1983       if(m_pcCfg->getUseRateCtrl())
    1984       {
    1985         UInt  frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];
    1986         m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());
    1987       }
    1988 #endif
    19891980
    19901981      if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
     
    21732164      delete[] pcSubstreamsOut;
    21742165  }
    2175 #if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN
    2176   if(m_pcCfg->getUseRateCtrl())
    2177   {
    2178     m_pcRateCtrl->updateRCGOPStatus();
    2179   }
    2180 #endif
    21812166  delete pcBitstreamRedirect;
    21822167
     
    22622247  m_pcEntropyCoder->resetEntropy    ();
    22632248  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    2264   pcSlice = pcPic->getSlice(0);
    2265   if(pcSlice->getSPS()->getUseSAO())
    2266   {
    2267     std::vector<Bool> LFCrossSliceBoundaryFlag(1, true);
    2268     std::vector<Int>  sliceStartAddress;
    2269     sliceStartAddress.push_back(0);
    2270     sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU());
    2271     pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag);
    2272   }
    2273  
    2274   if( pcSlice->getSPS()->getUseSAO())
    2275   {
    2276     pcPic->destroyNonDBFilterInfo();
    2277   }
    2278  
    22792249  m_pcEntropyCoder->resetEntropy    ();
    22802250  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
     
    24542424    case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    24552425    case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
    2456     case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
     2426    case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
    24572427    case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    24582428    case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
     
    27022672    for (Int x = 0; x < width; x++)
    27032673    {
    2704       dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
    2705       dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     2674      dst[x] = isTff ? top[x] : bottom[x];
     2675      dst[stride+x] = isTff ? bottom[x] : top[x];
    27062676    }
    27072677    top += stride;
     
    28622832 * This function checks the configuration and returns the appropriate nal_unit_type for the picture.
    28632833 */
    2864 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR)
     2834NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR, Bool isField)
    28652835{
    28662836  if (pocCurr == 0)
     
    28682838    return NAL_UNIT_CODED_SLICE_IDR_W_RADL;
    28692839  }
    2870   if (pocCurr % m_pcCfg->getIntraPeriod() == 0)
     2840  if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0)
    28712841  {
    28722842    if (m_pcCfg->getDecodingRefreshType() == 1)
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r655 r872  
    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 *
     
    125125  std::vector<Int>        m_storedStartCUAddrForEncodingSlice;
    126126  std::vector<Int>        m_storedStartCUAddrForEncodingSliceSegment;
     127#if FIX1172
     128  NalUnitType             m_associatedIRAPType;
     129  Int                     m_associatedIRAPPOC;
     130#endif
    127131
    128132  std::vector<Int> m_vRVM_RP;
     
    181185
    182186  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
    183   NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
     187  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField );
    184188  Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& );
    185189protected:
     
    187191
    188192protected:
     193
    189194  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField );
    190 
    191195  Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
    192196  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField );
     
    208212
    209213  SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
     214#if H_MV_HLS_7_SEI_P0204_26
     215  SEISubBitstreamProperty *xCreateSEISubBitstreamProperty( TComSPS *sps);
     216#endif
    210217
    211218  Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
  • trunk/source/Lib/TLibEncoder/TEncPic.cpp

    r608 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r608 r872  
    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

    r655 r872  
    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 *
     
    4242using namespace std;
    4343
    44 #if RATE_CONTROL_LAMBDA_DOMAIN
    45 
    4644//sequence level
    4745TEncRCSeq::TEncRCSeq()
     
    6765  m_bitsLeft            = 0;
    6866  m_useLCUSeparateModel = false;
    69 #if M0036_RC_IMPROVEMENT
    7067  m_adaptiveBit         = 0;
    7168  m_lastLambda          = 0.0;
    72 #endif
    7369}
    7470
     
    7874}
    7975
    80 #if M0036_RC_IMPROVEMENT
    8176Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
    82 #else
    83 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
    84 #endif
    8577{
    8678  destroy();
     
    109101    m_betaUpdate  = 0.025;
    110102  }
    111 #if M0036_RC_IMPROVEMENT
    112103  else if ( m_seqTargetBpp < 0.2 )
    113104  {
     
    125116    m_betaUpdate  = 0.2;
    126117  }
    127 #else
    128   else
    129   {
    130     m_alphaUpdate = 0.1;
    131     m_betaUpdate  = 0.05;
    132   }
    133 #endif
    134118  m_averageBits     = (Int)(m_targetBits / totalFrames);
    135119  Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
     
    172156  m_framesLeft = m_totalFrames;
    173157  m_bitsLeft   = m_targetBits;
    174 #if M0036_RC_IMPROVEMENT
    175158  m_adaptiveBit = adaptiveBit;
    176159  m_lastLambda = 0.0;
    177 #endif
    178160}
    179161
     
    233215    for ( Int i=0; i<m_numberOfLevel; i++ )
    234216    {
    235 #if RATE_CONTROL_INTRA
    236217      if (i>0)
    237218      {
     
    244225        m_picPara[i].m_beta  = BETA2;
    245226      }
    246 #else
    247       m_picPara[i].m_alpha = 3.2003;
    248       m_picPara[i].m_beta  = -1.367;
    249 #endif
    250227    }
    251228  }
     
    271248      for ( Int j=0; j<m_numberOfLCU; j++)
    272249      {
    273 #if RATE_CONTROL_INTRA
    274250        m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
    275251        m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
    276 #else
    277         m_LCUPara[i][j].m_alpha = 3.2003;
    278         m_LCUPara[i][j].m_beta  = -1.367;
    279 #endif
    280252      }
    281253    }
     
    299271}
    300272
    301 #if !RATE_CONTROL_INTRA
    302 Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
    303 {
    304   Double bpp = ( (Double)orgBits ) / m_picHeight / m_picHeight;
    305   if ( bpp > 0.2 )
    306   {
    307     return orgBits * 5;
    308   }
    309   if ( bpp > 0.1 )
    310   {
    311     return orgBits * 7;
    312   }
    313   return orgBits * 10;
    314 }
    315 #endif
    316 
    317 #if M0036_RC_IMPROVEMENT
    318273Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
    319274{
     
    326281  delete[] bitsRatio;
    327282}
    328 #endif
    329283
    330284//GOP level
     
    349303  Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
    350304
    351 #if M0036_RC_IMPROVEMENT
    352305  if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
    353306  {
     
    409362    delete []equaCoeffB;
    410363  }
    411 #endif
    412364
    413365  m_picTargetBitInGOP = new Int[numPic];
     
    422374  {
    423375    currPicRatio = encRCSeq->getBitRatio( i );
    424 #if M0036_RC_IMPROVEMENT
    425376    m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
    426 #else
    427     m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
    428 #endif
    429377  }
    430378
     
    436384}
    437385
    438 #if M0036_RC_IMPROVEMENT
    439386Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
    440387{
     
    482429  return solution;
    483430}
    484 #endif
    485431
    486432Void TEncRCGOP::destroy()
     
    534480
    535481  m_LCUs         = NULL;
    536 #if !M0036_RC_IMPROVEMENT
    537   m_lastPicture  = NULL;
    538 #endif
    539 
    540482#if KWU_RC_MADPRED_E0227
    541483  m_lastIVPicture = NULL;
     
    543485
    544486  m_picActualHeaderBits = 0;
    545 #if !M0036_RC_IMPROVEMENT
    546   m_totalMAD            = 0.0;
    547 #endif
    548487  m_picActualBits       = 0;
    549488  m_picQP               = 0;
     
    574513  }
    575514
    576 #if M0036_RC_IMPROVEMENT
    577515  targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
    578 #else
    579   targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
    580 #endif
    581516
    582517  if ( targetBits < 100 )
     
    691626      m_LCUs[LCUIdx].m_lambda     = 0.0;
    692627      m_LCUs[LCUIdx].m_targetBits = 0;
    693 #if M0036_RC_IMPROVEMENT
    694628      m_LCUs[LCUIdx].m_bitWeight  = 1.0;
    695 #else
    696       m_LCUs[LCUIdx].m_MAD        = 0.0;
    697 #endif
    698629      Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
    699630      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
     
    708639  }
    709640  m_picActualHeaderBits = 0;
    710 #if !M0036_RC_IMPROVEMENT
    711   m_totalMAD            = 0.0;
    712 #endif
    713641  m_picActualBits       = 0;
    714642  m_picQP               = 0;
     
    723651
    724652
    725 #if !M0036_RC_IMPROVEMENT
    726   m_lastPicture = NULL;
    727   list<TEncRCPic*>::reverse_iterator it;
    728   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
    729   {
    730     if ( (*it)->getFrameLevel() == m_frameLevel )
    731     {
    732       m_lastPicture = (*it);
    733       break;
    734     }
    735   }
    736 #endif
    737 
    738653#if KWU_RC_MADPRED_E0227
    739654  list<TEncRCPic*>::reverse_iterator it;
     
    775690
    776691
    777 #if RATE_CONTROL_INTRA
    778692Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
    779 #else
    780 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
    781 #endif
    782693{
    783694  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    784695  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    785696  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
    786 #if RATE_CONTROL_INTRA
    787697  Double estLambda;
    788698  if (eSliceType == I_SLICE)
     
    794704    estLambda = alpha * pow( bpp, beta );
    795705  }
    796 #else
    797   Double estLambda = alpha * pow( bpp, beta );
    798 #endif 
    799706 
    800707  Double lastLevelLambda = -1.0;
     
    844751  m_estPicLambda = estLambda;
    845752
    846 #if M0036_RC_IMPROVEMENT
    847753  Double totalWeight = 0.0;
    848754  // initial BU bit allocation weight
    849755  for ( Int i=0; i<m_numberOfLCU; i++ )
    850756  {
    851 #if RC_FIX
    852757    Double alphaLCU, betaLCU;
    853758    if ( m_encRCSeq->getUseLCUSeparateModel() )
     
    861766      betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    862767    }
    863 #else
    864     Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
    865     Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
    866 #endif
    867768
    868769    m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
     
    879780    m_LCUs[i].m_bitWeight = BUTargetBits;
    880781  }
    881 #endif
    882782
    883783  return estLambda;
     
    989889
    990890
    991 #if RATE_CONTROL_INTRA
    992891Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
    993 #else
    994 Double TEncRCPic::getLCUTargetBpp()
    995 #endif
     892{
     893  Int   LCUIdx    = getLCUCoded();
     894  Double bpp      = -1.0;
     895  Int avgBits     = 0;
     896
     897  if (eSliceType == I_SLICE)
     898  {
     899    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
     900    Int bitrateWindow = min(4,noOfLCUsLeft);
     901    Double MAD      = getLCU(LCUIdx).m_costIntra;
     902
     903    if (m_remainingCostIntra > 0.1 )
     904    {
     905      Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
     906      avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
     907    }
     908    else
     909    {
     910      avgBits = Int( m_bitsLeft / m_LCULeft );
     911    }
     912    m_remainingCostIntra -= MAD;
     913  }
     914  else
     915  {
     916  Double totalWeight = 0;
     917  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
     918  {
     919    totalWeight += m_LCUs[i].m_bitWeight;
     920  }
     921  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
     922  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
     923  }
     924
     925  if ( avgBits < 1 )
     926  {
     927    avgBits = 1;
     928  }
     929
     930  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
     931  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
     932
     933  return bpp;
     934}
     935
     936
     937#if KWU_RC_MADPRED_E0227
     938Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
    996939{
    997940  Int   LCUIdx    = getLCUCoded();
     
    1003946#endif
    1004947
    1005 #if RATE_CONTROL_INTRA
    1006   if (eSliceType == I_SLICE){
    1007     Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
    1008     Int bitrateWindow = min(4,noOfLCUsLeft);
    1009     Double MAD      = getLCU(LCUIdx).m_costIntra;
    1010 
    1011     if (m_remainingCostIntra > 0.1 )
    1012     {
    1013       Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;
    1014       avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );
    1015     }
    1016     else
    1017     {
    1018       avgBits = Int( m_bitsLeft / m_LCULeft );
    1019     }
    1020     m_remainingCostIntra -= MAD;
    1021   }
    1022   else
    1023   {
    1024 #endif
    1025 #if M0036_RC_IMPROVEMENT
    1026   Double totalWeight = 0;
    1027   for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
    1028   {
    1029     totalWeight += m_LCUs[i].m_bitWeight;
    1030   }
    1031   Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
    1032   avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
    1033 #else
    1034   if ( m_lastPicture == NULL )
    1035   {
    1036     avgBits = Int( m_bitsLeft / m_LCULeft );
    1037   }
    1038   else
    1039   {
    1040     MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
    1041     totalMAD = m_lastPicture->getTotalMAD();
    1042     for ( Int i=0; i<LCUIdx; i++ )
    1043     {
    1044       totalMAD -= m_lastPicture->getLCU(i).m_MAD;
    1045     }
    1046 
    1047     if ( totalMAD > 0.1 )
    1048     {
    1049       avgBits = Int( m_bitsLeft * MAD / totalMAD );
    1050     }
    1051     else
    1052     {
    1053       avgBits = Int( m_bitsLeft / m_LCULeft );
    1054     }
    1055   }
    1056 #endif
    1057 #if RATE_CONTROL_INTRA
    1058   }
    1059 #endif
    1060 
    1061   if ( avgBits < 1 )
    1062   {
    1063     avgBits = 1;
    1064   }
    1065 
    1066   bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
    1067   m_LCUs[ LCUIdx ].m_targetBits = avgBits;
    1068 
    1069   return bpp;
    1070 }
    1071 
    1072 
    1073 #if KWU_RC_MADPRED_E0227
    1074 Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
    1075 {
    1076   Int   LCUIdx    = getLCUCoded();
    1077   Double bpp      = -1.0;
    1078   Int avgBits     = 0;
    1079 #if !M0036_RC_IMPROVEMENT
    1080   Double totalMAD = -1.0;
    1081   Double MAD      = -1.0;
    1082 #endif
    1083 
    1084948  Double totalMAD = -1.0;
    1085949  Double MAD      = -1.0;
     
    13001164    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    13011165
    1302 #if M0036_RC_IMPROVEMENT
    13031166    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    13041167    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1305 #else
    1306     alpha = Clip3( 0.05, 20.0, alpha );
    1307     beta  = Clip3( -3.0, -0.1, beta  );
    1308 #endif
    13091168
    13101169    TRCParameter rcPara;
     
    13191178  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    13201179  double lnbpp = log( bpp );
    1321 #if M0036_RC_IMPROVEMENT
    13221180  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1323 #else
    1324   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1325 #endif
    13261181  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    13271182
    1328 #if M0036_RC_IMPROVEMENT
    13291183  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    13301184  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1331 #else
    1332   alpha = Clip3( 0.05, 20.0, alpha );
    1333   beta  = Clip3( -3.0, -0.1, beta  );
    1334 #endif
    13351185  TRCParameter rcPara;
    13361186  rcPara.m_alpha = alpha;
     
    13401190}
    13411191
    1342 #if !M0036_RC_IMPROVEMENT
    1343 Double TEncRCPic::getEffectivePercentage()
    1344 {
    1345   Int effectivePiexels = 0;
    1346   Int totalPixels = 0;
    1347 
    1348   for ( Int i=0; i<m_numberOfLCU; i++ )
    1349   {
    1350     totalPixels += m_LCUs[i].m_numberOfPixel;
    1351     if ( m_LCUs[i].m_QP > 0 )
    1352     {
    1353       effectivePiexels += m_LCUs[i].m_numberOfPixel;
    1354     }
    1355   }
    1356 
    1357   Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;
    1358   return effectivePixelPercentage;
    1359 }
    1360 #endif
    1361 
    13621192Double TEncRCPic::calAverageQP()
    13631193{
     
    14141244}
    14151245
    1416 #if M0036_RC_IMPROVEMENT
    1417 #if RATE_CONTROL_INTRA
    14181246Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
    1419 #else
    1420 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
    1421 #endif
    1422 #else
    1423 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
    1424 #endif
    14251247{
    14261248  m_picActualHeaderBits = actualHeaderBits;
     
    14351257  }
    14361258  m_picLambda           = averageLambda;
    1437 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
    14381259#if KWU_RC_MADPRED_E0227
    14391260  m_totalMAD = 0;
    1440 #endif
    14411261  for ( Int i=0; i<m_numberOfLCU; i++ )
    14421262  {
     
    14471267  Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    14481268  Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    1449 #if RATE_CONTROL_INTRA
    14501269  if (eSliceType == I_SLICE)
    14511270  {
     
    14541273  else
    14551274  {
    1456 #endif
    14571275  // update parameters
    14581276  Double picActualBits = ( Double )m_picActualBits;
     
    14611279  Double inputLambda   = m_picLambda;
    14621280
    1463 #if M0036_RC_IMPROVEMENT
    14641281  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
    1465 #else
    1466   if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
    1467 #endif
    14681282  {
    14691283    alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
    14701284    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    14711285
    1472 #if M0036_RC_IMPROVEMENT
    14731286    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    14741287    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1475 #else
    1476     alpha = Clip3( 0.05, 20.0, alpha );
    1477     beta  = Clip3( -3.0, -0.1, beta  );
    1478 #endif
    14791288    TRCParameter rcPara;
    14801289    rcPara.m_alpha = alpha;
     
    14881297  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    14891298  double lnbpp = log( picActualBpp );
    1490 #if M0036_RC_IMPROVEMENT
    14911299  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1492 #else
    1493   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1494 #endif
    14951300  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    14961301
    1497 #if M0036_RC_IMPROVEMENT
    14981302  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    14991303  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1500 #else
    1501   alpha = Clip3( 0.05, 20.0, alpha );
    1502   beta  = Clip3( -3.0, -0.1, beta  );
    1503 #endif
    1504 #if RATE_CONTROL_INTRA
    1505   }
    1506 #endif
     1304  }
    15071305
    15081306  TRCParameter rcPara;
     
    15121310  m_encRCSeq->setPicPara( m_frameLevel, rcPara );
    15131311
    1514 #if M0036_RC_IMPROVEMENT
    15151312  if ( m_frameLevel == 1 )
    15161313  {
     
    15191316    m_encRCSeq->setLastLambda( updateLastLambda );
    15201317  }
    1521 #endif
    1522 }
    1523 
    1524 #if RATE_CONTROL_INTRA
     1318}
     1319
    15251320Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
    15261321{
     
    16111406  return estLambda;
    16121407}
    1613 #endif
    16141408
    16151409TEncRateCtrl::TEncRateCtrl()
     
    16451439}
    16461440
    1647 #if M0036_RC_IMPROVEMENT
    16481441#if KWU_RC_MADPRED_E0227
    16491442Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP], Int layerID )
     
    16511444Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    16521445#endif
    1653 #else
    1654 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    1655 #endif
    16561446{
    16571447  destroy();
     
    16681458
    16691459  Int numberOfLevel = 1;
    1670 #if M0036_RC_IMPROVEMENT
    16711460  Int adaptiveBit = 0;
    16721461  if ( keepHierBits > 0 )
    1673 #else
    1674   if ( keepHierBits )
    1675 #endif
    16761462  {
    16771463    numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
     
    16961482  }
    16971483
    1698 #if M0036_RC_IMPROVEMENT
    16991484  if ( keepHierBits > 0 )
    1700 #else
    1701   if ( keepHierBits )
    1702 #endif
    17031485  {
    17041486    Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
     
    17331515        bitsRatio[3] = 14;
    17341516      }
    1735 #if M0036_RC_IMPROVEMENT
    17361517      if ( keepHierBits == 2 )
    17371518      {
    17381519        adaptiveBit = 1;
    17391520      }
    1740 #endif
    17411521    }
    17421522    else if ( GOPSize == 8 && !isLowdelay )
     
    17861566        bitsRatio[7] = 1;
    17871567      }
    1788 #if M0036_RC_IMPROVEMENT
    17891568      if ( keepHierBits == 2 )
    17901569      {
    17911570        adaptiveBit = 2;
    17921571      }
    1793 #endif
    17941572    }
    17951573    else
    17961574    {
    1797 #if M0036_RC_IMPROVEMENT
    17981575      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
    1799 #else
    1800       printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
    1801 #endif
    18021576    }
    18031577  }
     
    18121586    }
    18131587  }
    1814 #if M0036_RC_IMPROVEMENT
    18151588  if ( keepHierBits > 0 )
    1816 #else
    1817   if ( keepHierBits )
    1818 #endif
    18191589  {
    18201590    if ( GOPSize == 4 && isLowdelay )
     
    18511621
    18521622  m_encRCSeq = new TEncRCSeq;
    1853 #if M0036_RC_IMPROVEMENT
    18541623  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
    1855 #else
    1856   m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
    1857 #endif
    18581624  m_encRCSeq->initBitsRatio( bitsRatio );
    18591625  m_encRCSeq->initGOPID2Level( GOPID2Level );
     
    18941660}
    18951661
    1896 #else
    1897 
    1898 #define ADJUSTMENT_FACTOR       0.60
    1899 #define HIGH_QSTEP_THRESHOLD    9.5238
    1900 #define HIGH_QSTEP_ALPHA        4.9371
    1901 #define HIGH_QSTEP_BETA         0.0922
    1902 #define LOW_QSTEP_ALPHA         16.7429
    1903 #define LOW_QSTEP_BETA          -1.1494
    1904 
    1905 #define MAD_PRED_Y1             1.0
    1906 #define MAD_PRED_Y2             0.0
    1907 
    1908 enum MAD_HISOTRY {
    1909   MAD_PPPrevious = 0,
    1910   MAD_PPrevious  = 1,
    1911   MAD_Previous   = 2
    1912 };
    1913 
    1914 Void    MADLinearModel::initMADLinearModel()
    1915 {
    1916   m_activeOn = false;
    1917   m_paramY1  = 1.0;
    1918   m_paramY2  = 0.0;
    1919   m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;
    1920 }
    1921 
    1922 Double  MADLinearModel::getMAD()
    1923 {
    1924   Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;
    1925 
    1926   if(costPredMAD < 0)
    1927   {
    1928     costPredMAD = m_costMADs[MAD_Previous];
    1929     m_paramY1   = MAD_PRED_Y1;
    1930     m_paramY2   = MAD_PRED_Y2;
    1931   }
    1932   return costPredMAD;
    1933 }
    1934 
    1935 Void    MADLinearModel::updateMADLiearModel()
    1936 {
    1937   Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));
    1938   Double dNewY2 =  (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));
    1939  
    1940   m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;
    1941   m_paramY2 =      0.20*m_paramY2+ 0.10*dNewY2;
    1942 }
    1943 
    1944 Void    MADLinearModel::updateMADHistory(Double dMAD)
    1945 {
    1946   m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];
    1947   m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];
    1948   m_costMADs[MAD_Previous  ] = dMAD;
    1949   m_activeOn = (m_costMADs[MAD_Previous  ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);
    1950 }
    1951 
    1952 
    1953 Void    PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()
    1954 {
    1955   m_paramHighX1 = HIGH_QSTEP_ALPHA;
    1956   m_paramHighX2 = HIGH_QSTEP_BETA;
    1957   m_paramLowX1  = LOW_QSTEP_ALPHA;
    1958   m_paramLowX2  = LOW_QSTEP_BETA;
    1959 }
    1960 
    1961 Int     PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)
    1962 {
    1963   Double qStep;
    1964   Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));
    1965  
    1966   if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)
    1967   {
    1968     qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));
    1969   }
    1970   else
    1971   {
    1972     qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));
    1973   }
    1974  
    1975   return xConvertQStep2QP(qStep);
    1976 }
    1977 
    1978 Void    PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)
    1979 {
    1980   Double qStep     = xConvertQP2QStep(qp);
    1981   Double invqStep = (1/qStep);
    1982   Double paramNewX1, paramNewX2;
    1983  
    1984   if(qStep >= HIGH_QSTEP_THRESHOLD)
    1985   {
    1986     paramNewX2    = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));
    1987     paramNewX1    = (23.3772-200*paramNewX2);
    1988     m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;
    1989     m_paramHighX2 = 0.70*HIGH_QSTEP_BETA  + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;
    1990   }
    1991   else
    1992   {
    1993     paramNewX2   = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));
    1994     paramNewX1   = (5.8091-9.5455*paramNewX2);
    1995     m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;
    1996     m_paramLowX2 = 0.90*LOW_QSTEP_BETA  + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;
    1997   }
    1998 }
    1999 
    2000 Bool    PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )
    2001 {
    2002   Double qStep = xConvertQP2QStep(qpReference);
    2003 
    2004   if (qStep > xConvertQP2QStep(MAX_QP)
    2005     ||qStep < xConvertQP2QStep(MIN_QP) )
    2006   {
    2007     return false;
    2008   }
    2009 
    2010   return true;
    2011 }
    2012 
    2013 Double  PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )
    2014 {
    2015   Int i;
    2016   Double qStep;
    2017   static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };
    2018 
    2019   qStep = mapQP2QSTEP[qp % 6];
    2020   for( i=0; i<(qp/6); i++)
    2021   {
    2022     qStep *= 2;
    2023   }
    2024 
    2025   return qStep;
    2026 }
    2027 
    2028 Int     PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )
    2029 {
    2030   Int per = 0, rem = 0;
    2031 
    2032   if( qStep < xConvertQP2QStep(MIN_QP))
    2033   {
    2034     return MIN_QP;
    2035   }
    2036   else if (qStep > xConvertQP2QStep(MAX_QP) )
    2037   {
    2038     return MAX_QP;
    2039   }
    2040 
    2041   while( qStep > xConvertQP2QStep(5) )
    2042   {
    2043     qStep /= 2.0;
    2044     per++;
    2045   }
    2046 
    2047   if (qStep <= 0.625)
    2048   {
    2049     rem = 0;
    2050   }
    2051   else if (qStep <= 0.703)
    2052   {
    2053     rem = 1;
    2054   }
    2055   else if (qStep <= 0.797)
    2056   {
    2057     rem = 2;
    2058   }
    2059   else if (qStep <= 0.891)
    2060   {
    2061     rem = 3;
    2062   }
    2063   else if (qStep <= 1.000)
    2064   {
    2065     rem = 4;
    2066   }
    2067   else
    2068   {
    2069     rem = 5;
    2070   }
    2071   return (per * 6 + rem);
    2072 }
    2073 
    2074 
    2075 Void  TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)
    2076 {
    2077   Int leftInHeight, leftInWidth;
    2078 
    2079   m_sourceWidthInLCU         = (sourceWidth  / maxCUWidth  ) + (( sourceWidth  %  maxCUWidth ) ? 1 : 0);
    2080   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0); 
    2081   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
    2082 
    2083   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
    2084   m_currBitrate              = ( targetKbps << 10 );
    2085 
    2086   m_frameRate                = frameRate;
    2087   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
    2088   m_nonRefFrameNum           = sizeGOP-m_refFrameNum;
    2089   m_sizeGOP                  = sizeGOP;
    2090   m_numOfPixels              = ((sourceWidth*sourceHeight*3)>>1);
    2091   m_indexGOP                 = 0;
    2092   m_indexFrame               = 0;
    2093   m_indexLCU                 = 0;
    2094   m_indexUnit                = 0;
    2095   m_indexRefFrame            = 0;
    2096   m_indexNonRefFrame         = 0;
    2097   m_occupancyVB              = 0;
    2098   m_initialOVB               = 0;
    2099   m_targetBufLevel           = 0;
    2100   m_initialTBL               = 0;
    2101   m_occupancyVBInFrame       = 0;
    2102   m_remainingBitsInGOP       = (m_currBitrate*sizeGOP/m_frameRate);
    2103   m_remainingBitsInFrame     = 0;
    2104   m_numUnitInFrame           = m_sourceWidthInLCU*m_sourceHeightInLCU;
    2105   m_cMADLinearModel.        initMADLinearModel();
    2106   m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();
    2107 
    2108   m_costRefAvgWeighting      = 0.0;
    2109   m_costNonRefAvgWeighting   = 0.0;
    2110   m_costAvgbpp               = 0.0; 
    2111   m_activeUnitLevelOn        = false;
    2112 
    2113   m_pcFrameData              = new FrameData   [sizeGOP+1];         initFrameData(qp);
    2114   m_pcLCUData                = new LCUData     [m_numUnitInFrame];  initUnitData (qp);
    2115 
    2116   for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight) 
    2117   {
    2118     leftInHeight = sourceHeight - i;
    2119     leftInHeight = min(leftInHeight, maxCUHeight);
    2120     for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)
    2121     {
    2122       leftInWidth = sourceWidth - j;
    2123       leftInWidth = min(leftInWidth, maxCUWidth);
    2124       m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;
    2125       m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;
    2126       m_pcLCUData[addressUnit].m_pixels       = ((leftInHeight*leftInWidth*3)>>1);
    2127     }
    2128   }
    2129 }
    2130 
    2131 Void  TEncRateCtrl::destroy()
    2132 {
    2133   if(m_pcFrameData)
    2134   {
    2135     delete [] m_pcFrameData;
    2136     m_pcFrameData = NULL;
    2137   }
    2138   if(m_pcLCUData)
    2139   {
    2140     delete [] m_pcLCUData;
    2141     m_pcLCUData = NULL;
    2142   }
    2143 }
    2144 
    2145 Void  TEncRateCtrl::initFrameData   (Int qp)
    2146 {
    2147   for(Int i = 0 ; i <= m_sizeGOP; i++)
    2148   {
    2149     m_pcFrameData[i].m_isReferenced = false;
    2150     m_pcFrameData[i].m_costMAD      = 0.0;
    2151     m_pcFrameData[i].m_bits         = 0;
    2152     m_pcFrameData[i].m_qp           = qp;
    2153   }
    2154 }
    2155 
    2156 Void  TEncRateCtrl::initUnitData    (Int qp)
    2157 {
    2158   for(Int i = 1 ; i < m_numUnitInFrame; i++)
    2159   {
    2160     m_pcLCUData[i].m_qp            = qp;
    2161     m_pcLCUData[i].m_bits          = 0;
    2162     m_pcLCUData[i].m_pixels        = 0;
    2163     m_pcLCUData[i].m_widthInPixel  = 0;
    2164     m_pcLCUData[i].m_heightInPixel = 0;
    2165     m_pcLCUData[i].m_costMAD       = 0.0;
    2166   }
    2167 }
    2168 
    2169 Int  TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)
    2170 {
    2171   Int numofReferenced = 0;
    2172   Int finalQP = 0;
    2173   FrameData* pcFrameData;
    2174 
    2175   m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);
    2176   pcFrameData     = &m_pcFrameData[m_indexPOCInGOP];
    2177    
    2178   if(m_indexFrame != 0)
    2179   {
    2180     if(isReferenced)
    2181     {
    2182       Double gamma = m_isLowdelay ? 0.5 : 0.25;
    2183       Double beta  = m_isLowdelay ? 0.9 : 0.6;
    2184       Int    numRemainingRefFrames  = m_refFrameNum    - m_indexRefFrame;
    2185       Int    numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;
    2186      
    2187       Double targetBitsOccupancy  = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));
    2188       Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));
    2189 
    2190       m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);
    2191  
    2192       if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)
    2193       {
    2194         finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;
    2195       }
    2196       else
    2197       {
    2198         Double costPredMAD   = m_cMADLinearModel.getMAD();
    2199         Int    qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;
    2200         Int    qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;
    2201         finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);
    2202         finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));
    2203         m_activeUnitLevelOn    = true;
    2204         m_remainingBitsInFrame = m_targetBits;
    2205         m_costAvgbpp           = (m_targetBits/(Double)m_numOfPixels);
    2206       }
    2207 
    2208       m_indexRefFrame++;
    2209     }
    2210     else
    2211     {
    2212       Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;
    2213       Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;
    2214        
    2215       if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp
    2216         ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)
    2217       {
    2218         finalQP = (fwdQP+bwdQP);
    2219       }
    2220       else if(bwdQP != fwdQP)
    2221       {
    2222         finalQP = ((bwdQP+fwdQP+2)>>1);
    2223       }
    2224       else
    2225       {
    2226         finalQP = bwdQP+2;
    2227       }
    2228       m_indexNonRefFrame++;
    2229     }
    2230   }
    2231   else
    2232   {
    2233     Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;
    2234     Int lastQPplus2  = m_pcFrameData[0].m_qp + 2;
    2235 
    2236     for(Int idx = 1; idx <= m_sizeGOP; idx++)
    2237     {
    2238       if(m_pcFrameData[idx].m_isReferenced)
    2239       {
    2240         finalQP += m_pcFrameData[idx].m_qp;
    2241         numofReferenced++;
    2242       }
    2243     }
    2244    
    2245     finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);
    2246     finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));
    2247 
    2248     Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;
    2249     Int    bufLevel  = m_occupancyVB + m_initialOVB;
    2250 
    2251     if(abs(bufLevel) > costAvgFrameBits)
    2252     {
    2253       if(bufLevel < 0)
    2254       {
    2255         finalQP -= 2;
    2256       }
    2257       else
    2258       {
    2259         finalQP += 2;
    2260       }
    2261     }
    2262     m_indexRefFrame++;
    2263   }
    2264   finalQP = max(MIN_QP, min(MAX_QP, finalQP));
    2265 
    2266   for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)
    2267   {
    2268     m_pcLCUData[indexLCU].m_qp = finalQP;
    2269   }
    2270 
    2271   pcFrameData->m_isReferenced = isReferenced;
    2272   pcFrameData->m_qp           = finalQP;
    2273 
    2274   return finalQP;
    2275 }
    2276 
    2277 Bool  TEncRateCtrl::calculateUnitQP ()
    2278 {
    2279   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2280   {
    2281     return false;
    2282   }
    2283   Int upperQPBound, lowerQPBound, finalQP;
    2284   Int    colQP        = m_pcLCUData[m_indexLCU].m_qp;
    2285   Double colMAD       = m_pcLCUData[m_indexLCU].m_costMAD;
    2286   Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;
    2287 
    2288 
    2289   Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));
    2290   Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));
    2291   Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);
    2292  
    2293 
    2294   if( m_indexLCU >= m_sourceWidthInLCU)
    2295   {
    2296     upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;
    2297     lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;
    2298   }
    2299   else
    2300   {
    2301     upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;
    2302     lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;
    2303   }
    2304 
    2305   if(targetBits < 0)
    2306   {
    2307     finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;
    2308   }
    2309   else
    2310   {
    2311     finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);
    2312   }
    2313  
    2314   finalQP = max(lowerQPBound, min(upperQPBound, finalQP));
    2315   m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));
    2316  
    2317   return true;
    2318 }
    2319 
    2320 Void  TEncRateCtrl::updateRCGOPStatus()
    2321 {
    2322   m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;
    2323  
    2324   FrameData cFrameData = m_pcFrameData[m_sizeGOP];
    2325   initFrameData();
    2326 
    2327   m_pcFrameData[0]   = cFrameData;
    2328   m_indexGOP++;
    2329   m_indexFrame       = 0;
    2330   m_indexRefFrame    = 0;
    2331   m_indexNonRefFrame = 0;
    2332 }
    2333 
    2334 Void  TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)
    2335 {
    2336   FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];
    2337   Int occupancyBits;
    2338   Double adjustmentBits;
    2339 
    2340   m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;
    2341   occupancyBits        = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));
    2342  
    2343   if( (occupancyBits < 0) && (m_initialOVB > 0) )
    2344   {
    2345     adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );
    2346 
    2347     if(m_initialOVB < 0)
    2348     {
    2349       adjustmentBits = m_initialOVB;
    2350       occupancyBits += (Int)adjustmentBits;
    2351       m_initialOVB   =  0;
    2352     }
    2353   }
    2354   else if( (occupancyBits > 0) && (m_initialOVB < 0) )
    2355   {
    2356     adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );
    2357    
    2358     if(occupancyBits < 0)
    2359     {
    2360       adjustmentBits = occupancyBits;
    2361       m_initialOVB  += (Int)adjustmentBits;
    2362       occupancyBits  =  0;
    2363     }
    2364   }
    2365 
    2366   if(m_indexGOP == 0)
    2367   {
    2368     m_initialOVB = occupancyBits;
    2369   }
    2370   else
    2371   {
    2372     m_occupancyVB= m_occupancyVB + occupancyBits;
    2373   }
    2374 
    2375   if(pcFrameData->m_isReferenced)
    2376   {
    2377     m_costRefAvgWeighting  = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);
    2378 
    2379     if(m_indexFrame == 0)
    2380     {
    2381       m_initialTBL = m_targetBufLevel  = (frameBits - (m_currBitrate/m_frameRate));
    2382     }
    2383     else
    2384     {
    2385       Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;
    2386       m_targetBufLevel =  m_targetBufLevel
    2387                             - (m_initialTBL/(m_refFrameNum-1))
    2388                             + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance))))
    2389                             - (m_currBitrate/m_frameRate);
    2390     }
    2391 
    2392     if(m_cMADLinearModel.IsUpdateAvailable())
    2393     {
    2394       m_cMADLinearModel.updateMADLiearModel();
    2395     }
    2396 
    2397     if(eSliceType != I_SLICE &&
    2398        m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))
    2399     {
    2400       m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);
    2401     }
    2402   }
    2403   else
    2404   {
    2405     m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);
    2406   }
    2407 
    2408   m_indexFrame++;
    2409   m_indexLCU             = 0;
    2410   m_indexUnit            = 0;
    2411   m_occupancyVBInFrame   = 0;
    2412   m_remainingBitsInFrame = 0;
    2413   m_codedPixels          = 0;
    2414   m_activeUnitLevelOn    = false;
    2415   m_costAvgbpp           = 0.0;
    2416 }
    2417 Void  TEncRateCtrl::updataRCUnitStatus ()
    2418 {
    2419   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2420   {
    2421     return;
    2422   }
    2423 
    2424   m_codedPixels  += m_pcLCUData[m_indexLCU-1].m_pixels;
    2425   m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;
    2426   m_occupancyVBInFrame   = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);
    2427 
    2428   if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )
    2429   {
    2430     m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(m_pcLCUData[m_indexLCU-1].m_qp, m_pcLCUData[m_indexLCU-1].m_bits, m_pcLCUData[m_indexLCU-1].m_pixels, m_pcLCUData[m_indexLCU-1].m_costMAD);
    2431   }
    2432 
    2433   m_indexUnit++;
    2434 }
    2435 
    2436 Void  TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)
    2437 {
    2438   Double costMAD = 0.0;
    2439  
    2440   for(Int i = 0; i < m_numUnitInFrame; i++)
    2441   {
    2442     costMAD    += m_pcLCUData[i].m_costMAD;
    2443   }
    2444  
    2445   m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);
    2446   m_pcFrameData[m_indexPOCInGOP].m_bits    = (Int)actualFrameBits;
    2447  
    2448   if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)
    2449   {
    2450     m_indexPrevPOCInGOP = m_indexPOCInGOP;
    2451     m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);
    2452   }
    2453 }
    2454 
    2455 Void  TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)
    2456 {
    2457   Int     x, y;
    2458   Double  costMAD = 0.0;
    2459 
    2460   Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2461   Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
    2462   Int   stride = pcCU->getPic()->getStride();
    2463 
    2464   Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
    2465   Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
    2466 
    2467   for( y = 0; y < height; y++ )
    2468   {
    2469     for( x = 0; x < width; x++ )
    2470     {
    2471       costMAD += abs( pOrg[x] - pRec[x] );
    2472     }
    2473     pOrg += stride;
    2474     pRec += stride;
    2475   }
    2476   m_pcLCUData[m_indexLCU  ].m_qp      = qp;
    2477   m_pcLCUData[m_indexLCU  ].m_costMAD = (costMAD /(Double)(width*height));
    2478   m_pcLCUData[m_indexLCU++].m_bits    = (Int)actualLCUBits;
    2479 }
    2480 
    2481 
    2482 #if KWU_RC_MADPRED_E0227
    2483 Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)
    2484 {
    2485   Int     x, y;
    2486   Double dMAD = 0.0;
    2487   Int Sum = 0;
    2488   Double SAD = 0.0;
    2489 
    2490   Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2491   Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
    2492   Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2493   Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
    2494 
    2495   Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
    2496   Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
    2497 
    2498   for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
    2499   {
    2500     for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
    2501     {
    2502       Sum += pDep[x];
    2503     }
    2504     pDep += iStride;
    2505   }
    2506 
    2507   Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
    2508   Double fL = focalLen * abs( basePos - curPos );
    2509   Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
    2510   Int   disparity = (Int)(direction*fL * z);
    2511   Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
    2512   Int disp = disparity;
    2513 
    2514   for( y = 0; y < height; y++ )
    2515   {
    2516     for( x = 0; x < width; x++ )
    2517     {
    2518       SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
    2519       - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
    2520     }
    2521     pOrg += iStride;
    2522     pRec += iStride;
    2523   }
    2524   m_pcLCUData[m_indexLCU].m_qp   = qp;
    2525   m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(width*height));
    2526   m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
    2527 }
    2528 #endif
    2529 
    2530 
    2531 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
    2532 {
    2533   Double adjustment  = ADJUSTMENT_FACTOR*reductionBits;
    2534   reductionBits     -= (Int)adjustment;
    2535   compensationBits  += (Int)adjustment;
    2536 
    2537   return adjustment;
    2538 }
    2539 
    2540 #endif
    2541 
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r655 r872  
    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 *
     
    5555//! \{
    5656
    57 #if RATE_CONTROL_LAMBDA_DOMAIN
    5857#include "../TLibEncoder/TEncCfg.h"
    5958#include <list>
     
    6564const Double g_RCWeightPicTargetBitInGOP    = 0.9;
    6665const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP;
    67 #if M0036_RC_IMPROVEMENT
    6866const Int g_RCIterationNum = 20;
    6967const Double g_RCWeightHistoryLambda = 0.5;
     
    7472const Double g_RCBetaMinValue  = -3.0;
    7573const Double g_RCBetaMaxValue  = -0.1;
    76 #endif
    77 
    78 #if RATE_CONTROL_INTRA
     74
    7975#define ALPHA     6.7542;
    8076#define BETA1     1.2517
    8177#define BETA2     1.7860
    82 #endif
    8378
    8479struct TRCLCU
     
    8883  Int m_targetBits;
    8984  Double m_lambda;
    90 #if M0036_RC_IMPROVEMENT
    9185  Double m_bitWeight;
    92 #else
    93   Double m_MAD;
    94 #endif
    9586  Int m_numberOfPixel;
    96 #if RATE_CONTROL_INTRA
    9787  Double m_costIntra;
    9888  Int m_targetBitsLeft;
    99 #endif
    100 
    10189#if KWU_RC_MADPRED_E0227
    10290  Double m_MAD;
    103 
    10491  Int m_CUWidth;
    10592  Int m_CUHeight;
     
    121108
    122109public:
    123 #if M0036_RC_IMPROVEMENT
    124110  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit );
    125 #else
    126   Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );
    127 #endif
    128111  Void destroy();
    129112  Void initBitsRatio( Int bitsRatio[] );
     
    132115  Void initLCUPara( TRCParameter** LCUPara = NULL );    // NULL to initial with default value
    133116  Void updateAfterPic ( Int bits );
    134 #if !RATE_CONTROL_INTRA
    135   Int  getRefineBitsForIntra( Int orgBits );
    136 #endif
    137 #if M0036_RC_IMPROVEMENT
    138117  Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB );
    139 #endif
    140118
    141119public:
     
    175153  Double getBetaUpdate()                { return m_betaUpdate; }
    176154
    177 #if M0036_RC_IMPROVEMENT
    178155  Int    getAdaptiveBits()              { return m_adaptiveBit;  }
    179156  Double getLastLambda()                { return m_lastLambda;   }
    180157  Void   setLastLambda( Double lamdba ) { m_lastLambda = lamdba; }
    181 #endif
    182158
    183159private:
     
    208184  Bool m_useLCUSeparateModel;
    209185
    210 #if M0036_RC_IMPROVEMENT
    211186  Int m_adaptiveBit;
    212187  Double m_lastLambda;
    213 #endif
    214188};
    215189
     
    227201private:
    228202  Int  xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize );
    229 #if M0036_RC_IMPROVEMENT
    230203  Void   xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    231204  Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    232 #endif
    233205
    234206public:
     
    266238  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC );
    267239#endif
    268 #if !RATE_CONTROL_INTRA
    269   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
    270 #endif
    271240  Int    estimatePicQP    ( Double lambda, list<TEncRCPic*>& listPreviousPictures );
    272 #if RATE_CONTROL_INTRA
    273241  Int    getRefineBitsForIntra(Int orgBits);
    274242  Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel);
     
    279247  Double getLCUTargetBpp(SliceType eSliceType);
    280248  Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP);
    281 #else
    282   Double getLCUTargetBpp();
    283 #endif
    284 
    285249#if KWU_RC_MADPRED_E0227
    286250  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity );
    287251#endif
    288 
    289252  Double getLCUEstLambda( Double bpp );
    290253  Int    getLCUEstQP( Double lambda, Int clipPicQP );
    291254
    292255  Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true );
    293 #if M0036_RC_IMPROVEMENT
    294 #if RATE_CONTROL_INTRA
    295256  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType);
    296 #else
    297   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );
    298 #endif
    299 #else
    300   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );
    301 #endif
    302257
    303258  Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
    304 
    305259#if KWU_RC_MADPRED_E0227
    306260  Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures );
    307261  Void setIVPic( TEncRCPic* baseRCPic );
    308 #endif
    309 
    310 #if !M0036_RC_IMPROVEMENT
    311   Double getEffectivePercentage();
    312262#endif
    313263  Double calAverageQP();
     
    326276  Int  getNumberOfLCU()                                   { return m_numberOfLCU; }
    327277  Int  getTargetBits()                                    { return m_targetBits; }
    328 #if !RATE_CONTROL_INTRA
    329   Void setTargetBits( Int bits )                          { m_targetBits = bits; }
    330 #endif
    331278  Int  getEstHeaderBits()                                 { return m_estHeaderBits; }
    332279  Int  getLCULeft()                                       { return m_LCULeft; }
     
    338285  TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
    339286  Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
    340 #if !M0036_RC_IMPROVEMENT
    341   Double getTotalMAD()                                    { return m_totalMAD; }
    342   Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
    343 #endif
    344 #if RATE_CONTROL_INTRA
    345287  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
    346288  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
    347289  Void getLCUInitTargetBits();
    348 #endif
    349 
    350290#if KWU_RC_MADPRED_E0227
    351291  Double getTotalMAD()                                    { return m_totalMAD; }
     
    368308  Void setLayerID(Int layerid)                              { m_LayerID = layerid; }
    369309#endif
    370 
    371310private:
    372311  TEncRCSeq* m_encRCSeq;
     
    387326  TRCLCU* m_LCUs;
    388327  Int m_picActualHeaderBits;    // only SH and potential APS
    389 #if !M0036_RC_IMPROVEMENT
    390   Double m_totalMAD;
    391 #endif
    392 #if RATE_CONTROL_INTRA
    393328  Double m_totalCostIntra;
    394329  Double m_remainingCostIntra;
    395 #endif
    396330  Int m_picActualBits;          // the whole picture, including header
    397331  Int m_picQP;                  // in integer form
    398332  Double m_picLambda;
    399 #if !M0036_RC_IMPROVEMENT
    400   TEncRCPic* m_lastPicture;
    401 #endif
    402 
    403333#if KWU_RC_MADPRED_E0227
    404334  Double m_totalMAD;
     
    417347
    418348public:
    419 #if M0036_RC_IMPROVEMENT
    420349#if KWU_RC_MADPRED_E0227
    421350  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID );
    422351#else
    423352  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    424 #endif
    425 #else
    426   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    427353#endif
    428354  Void destroy();
     
    443369  Void setLayerID(Int layerid)     { m_LayerID = layerid; }
    444370#endif
    445 
    446371private:
    447372  TEncRCSeq* m_encRCSeq;
     
    450375  list<TEncRCPic*> m_listRCPictures;
    451376  Int        m_RCQP;
    452 
    453377#if KWU_RC_MADPRED_E0227
    454378  Int m_LayerID;
     
    456380};
    457381
    458 #else
    459 
    460 // ====================================================================================================================
    461 // Class definition
    462 // ====================================================================================================================
    463 #define MAX_DELTA_QP    2
    464 #define MAX_CUDQP_DEPTH 0
    465 
    466 typedef struct FrameData
    467 {
    468   Bool       m_isReferenced;
    469   Int        m_qp;
    470   Int        m_bits;
    471   Double     m_costMAD;
    472 }FrameData;
    473 
    474 typedef struct LCUData
    475 {
    476   Int     m_qp;                ///<  coded QP
    477   Int     m_bits;              ///<  actually generated bits
    478   Int     m_pixels;            ///<  number of pixels for a unit
    479   Int     m_widthInPixel;      ///<  number of pixels for width
    480   Int     m_heightInPixel;     ///<  number of pixels for height
    481   Double  m_costMAD;           ///<  texture complexity for a unit
    482 }LCUData;
    483 
    484 class MADLinearModel
    485 {
    486 private:
    487   Bool   m_activeOn;
    488   Double m_paramY1;
    489   Double m_paramY2;
    490   Double m_costMADs[3];
    491 
    492 public:
    493   MADLinearModel ()   {};
    494   ~MADLinearModel()   {};
    495  
    496   Void    initMADLinearModel      ();
    497   Double  getMAD                  ();
    498   Void    updateMADLiearModel     ();
    499   Void    updateMADHistory        (Double costMAD);
    500   Bool    IsUpdateAvailable       ()              { return m_activeOn; }
    501 };
    502 
    503 class PixelBaseURQQuadraticModel
    504 {
    505 private:
    506   Double m_paramHighX1;
    507   Double m_paramHighX2;
    508   Double m_paramLowX1;
    509   Double m_paramLowX2;
    510 public:
    511   PixelBaseURQQuadraticModel () {};
    512   ~PixelBaseURQQuadraticModel() {};
    513 
    514   Void    initPixelBaseQuadraticModel       ();
    515   Int     getQP                             (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD);
    516   Void    updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD);
    517   Bool    checkUpdateAvailable              (Int qpReference );
    518   Double  xConvertQP2QStep                  (Int qp );
    519   Int     xConvertQStep2QP                  (Double qStep );
    520 };
    521 
    522 class TEncRateCtrl
    523 {
    524 private:
    525   Bool            m_isLowdelay;
    526   Int             m_prevBitrate;
    527   Int             m_currBitrate;
    528   Int             m_frameRate;
    529   Int             m_refFrameNum;
    530   Int             m_nonRefFrameNum;
    531   Int             m_numOfPixels;
    532   Int             m_sourceWidthInLCU;
    533   Int             m_sourceHeightInLCU;     
    534   Int             m_sizeGOP;
    535   Int             m_indexGOP;
    536   Int             m_indexFrame;
    537   Int             m_indexLCU;
    538   Int             m_indexUnit;
    539   Int             m_indexRefFrame;
    540   Int             m_indexNonRefFrame;
    541   Int             m_indexPOCInGOP;
    542   Int             m_indexPrevPOCInGOP;
    543   Int             m_occupancyVB;
    544   Int             m_initialOVB;
    545   Int             m_targetBufLevel;
    546   Int             m_initialTBL;
    547   Int             m_remainingBitsInGOP;
    548   Int             m_remainingBitsInFrame;
    549   Int             m_occupancyVBInFrame;
    550   Int             m_targetBits;
    551   Int             m_numUnitInFrame;
    552   Int             m_codedPixels;
    553   Bool            m_activeUnitLevelOn;
    554   Double          m_costNonRefAvgWeighting;
    555   Double          m_costRefAvgWeighting;
    556   Double          m_costAvgbpp;         
    557  
    558   FrameData*      m_pcFrameData;
    559   LCUData*        m_pcLCUData;
    560 
    561   MADLinearModel              m_cMADLinearModel;
    562   PixelBaseURQQuadraticModel  m_cPixelURQQuadraticModel;
    563  
    564 public:
    565   TEncRateCtrl         () {};
    566   virtual ~TEncRateCtrl() {};
    567 
    568   Void          create                (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight);
    569   Void          destroy               ();
    570 
    571   Void          initFrameData         (Int qp = 0);
    572   Void          initUnitData          (Int qp = 0);
    573   Int           getFrameQP            (Bool isReferenced, Int POC);
    574   Bool          calculateUnitQP       ();
    575   Int           getUnitQP             ()                                          { return m_pcLCUData[m_indexLCU].m_qp;  }
    576   Void          updateRCGOPStatus     ();
    577   Void          updataRCFrameStatus   (Int frameBits, SliceType eSliceType);
    578   Void          updataRCUnitStatus    ();
    579   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
    580 #if KWU_RC_MADPRED_E0227
    581   Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction);
    582 #endif
    583   Void          updateFrameData       (UInt64 actualFrameBits);
    584   Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
    585   Int           getGOPId              ()                                          { return m_indexFrame; }
    586 };
    587 #endif
    588 
    589 #endif
    590 
    591 
     382#endif
     383
     384
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r608 r872  
    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 *
     
    4545//! \{
    4646
    47 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    48 {
    49   m_pcEntropyCoder = NULL;
    50   m_pppcRDSbacCoder = NULL;
    51   m_pcRDGoOnSbacCoder = NULL;
    52   m_pppcBinCoderCABAC = NULL;           
    53   m_iCount = NULL;     
    54   m_iOffset = NULL;     
    55   m_iOffsetOrg = NULL; 
    56   m_iRate = NULL;       
    57   m_iDist = NULL;       
    58   m_dCost = NULL;       
    59   m_dCostPartBest = NULL;
    60   m_iDistOrg = NULL;     
    61   m_iTypePartBest = NULL;
    62 #if SAO_ENCODING_CHOICE_CHROMA
    63   m_depthSaoRate[0][0] = 0;
    64   m_depthSaoRate[0][1] = 0;
    65   m_depthSaoRate[0][2] = 0;
    66   m_depthSaoRate[0][3] = 0;
    67   m_depthSaoRate[1][0] = 0;
    68   m_depthSaoRate[1][1] = 0;
    69   m_depthSaoRate[1][2] = 0;
    70   m_depthSaoRate[1][3] = 0;
    71 #endif
    72 }
    73 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
    74 {
    75 
    76 }
    77 // ====================================================================================================================
    78 // Constants
    79 // ====================================================================================================================
    80 
    81 
    82 // ====================================================================================================================
    83 // Tables
    84 // ====================================================================================================================
    85 
    86 inline Double xRoundIbdi2(Int bitDepth, Double x)
    87 {
    88   return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));
    89 }
    9047
    9148/** rounding with IBDI
    9249 * \param  x
    9350 */
     51inline Double xRoundIbdi2(Int bitDepth, Double x)
     52{
     53  return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));
     54}
     55
    9456inline Double xRoundIbdi(Int bitDepth, Double x)
    9557{
     
    9860
    9961
    100 
    101 /** process SAO for one partition
    102  * \param  *psQTPart, iPartIdx, dLambda
    103  */
    104 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr)
    105 {
    106   Int iTypeIdx;
    107   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    108   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    109 
    110   Int64 iEstDist;
    111   Int iClassIdx;
    112   Int uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT((yCbCr == 0 ? g_bitDepthY : g_bitDepthC)-8);
    113   UInt uiDepth = pOnePart->PartLevel;
    114 
    115   m_iDistOrg [iPartIdx] =  0;
    116 
    117   Double  bestRDCostTableBo = MAX_DOUBLE;
    118   Int     bestClassTableBo    = 0;
    119   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    120   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    121 
    122   Int addr;
    123   Int allowMergeLeft;
    124   Int allowMergeUp;
    125   Int frameWidthInCU = m_pcPic->getFrameWidthInCU();
    126   SaoLcuParam  saoLcuParamRdo;
    127 
    128   for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++)
    129   {
    130     if( m_bUseSBACRD )
    131     {
    132       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    133       m_pcRDGoOnSbacCoder->resetBits();
    134     }
    135     else
    136     {
    137       m_pcEntropyCoder->resetEntropy();
    138       m_pcEntropyCoder->resetBits();
    139     }
    140 
    141     iEstDist = 0;
    142 
    143     if (iTypeIdx == -1)
    144     {     
    145       for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
    146       {
    147         for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
    148         {
    149           addr = ry * frameWidthInCU + rx;         
    150 
    151           // get bits for iTypeIdx = -1
    152           allowMergeLeft = 1;
    153           allowMergeUp   = 1;
    154           if (rx != 0)
    155           {
    156             // check tile id and slice id
    157             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()))
    158             {
    159               allowMergeLeft = 0;
    160             }
    161           }
    162           if (ry!=0)
    163           {
    164             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()))
    165             {
    166               allowMergeUp = 0;
    167             }
    168           }
    169 
    170           // reset
    171           resetSaoUnit(&saoLcuParamRdo);
    172 
    173           // set merge flag
    174           saoLcuParamRdo.mergeUpFlag   = 1;
    175           saoLcuParamRdo.mergeLeftFlag = 1;
    176 
    177           if (ry == pOnePart->StartCUY)
    178           {
    179             saoLcuParamRdo.mergeUpFlag = 0;
    180           }
    181          
    182           if (rx == pOnePart->StartCUX)
    183           {
    184             saoLcuParamRdo.mergeLeftFlag = 0;
    185           }
    186 
    187           m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
    188 
    189         }
    190       }
    191     }
    192 
    193     if (iTypeIdx>=0)
    194     {
    195       iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo);
    196       if( iTypeIdx == SAO_BO )
    197       {
    198         // Estimate Best Position
    199         Double currentRDCost = 0.0;
    200 
    201         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    202         {
    203           currentRDCost = 0.0;
    204           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    205           {
    206             currentRDCost += currentRdCostTableBo[uj];
    207           }
    208 
    209           if( currentRDCost < bestRDCostTableBo)
    210           {
    211             bestRDCostTableBo = currentRDCost;
    212             bestClassTableBo  = i;
    213           }
    214         }
    215 
    216         // Re code all Offsets
    217         // Code Center
    218         for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++)
    219         {
    220           iEstDist += currentDistortionTableBo[iClassIdx];
    221         }
    222       }
    223 
    224       for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++)
    225       {
    226         for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++)
    227         {
    228           addr = ry * frameWidthInCU + rx;         
    229 
    230           // get bits for iTypeIdx = -1
    231           allowMergeLeft = 1;
    232           allowMergeUp   = 1;
    233           if (rx != 0)
    234           {
    235             // check tile id and slice id
    236             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()))
    237             {
    238               allowMergeLeft = 0;
    239             }
    240           }
    241           if (ry!=0)
    242           {
    243             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()))
    244             {
    245               allowMergeUp = 0;
    246             }
    247           }
    248 
    249           // reset
    250           resetSaoUnit(&saoLcuParamRdo);
    251          
    252           // set merge flag
    253           saoLcuParamRdo.mergeUpFlag   = 1;
    254           saoLcuParamRdo.mergeLeftFlag = 1;
    255 
    256           if (ry == pOnePart->StartCUY)
    257           {
    258             saoLcuParamRdo.mergeUpFlag = 0;
    259           }
    260          
    261           if (rx == pOnePart->StartCUX)
    262           {
    263             saoLcuParamRdo.mergeLeftFlag = 0;
    264           }
    265 
    266           // set type and offsets
    267           saoLcuParamRdo.typeIdx = iTypeIdx;
    268           saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0;
    269           saoLcuParamRdo.length = m_iNumClass[iTypeIdx];
    270           for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++)
    271           {
    272             saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1];
    273           }
    274 
    275           m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry,  &saoLcuParamRdo, 1,  1,  allowMergeLeft, allowMergeUp);
    276 
    277         }
    278       }
    279 
    280       m_iDist[iPartIdx][iTypeIdx] = iEstDist;
    281       m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits();
    282 
    283       m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]);
    284 
    285       if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx])
    286       {
    287         m_iDistOrg [iPartIdx] = 0;
    288         m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx];
    289         m_iTypePartBest[iPartIdx] = iTypeIdx;
    290         if( m_bUseSBACRD )
    291           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    292       }
    293     }
    294     else
    295     {
    296       if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] )
    297       {
    298         m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ;
    299         m_iTypePartBest[iPartIdx] = -1;
    300         if( m_bUseSBACRD )
    301         {
    302           m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] );
    303         }
    304       }
    305     }
    306   }
    307 
    308   pOnePart->bProcessed = true;
    309   pOnePart->bSplit     = false;
    310   pOnePart->iMinDist   =        m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx];
    311   pOnePart->iMinRate   = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0);
    312   pOnePart->dMinCost   = pOnePart->iMinDist + dLambda * pOnePart->iMinRate;
    313   pOnePart->iBestType  = m_iTypePartBest[iPartIdx];
    314   if (pOnePart->iBestType != -1)
    315   {
    316     //     pOnePart->bEnableFlag =  1;
    317     pOnePart->iLength = m_iNumClass[pOnePart->iBestType];
    318     Int minIndex = 0;
    319     if( pOnePart->iBestType == SAO_BO )
    320     {
    321       pOnePart->subTypeIdx = bestClassTableBo;
    322       minIndex = pOnePart->subTypeIdx;
    323     }
    324     for (Int i=0; i< pOnePart->iLength ; i++)
    325     {
    326       pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1];
    327     }
    328 
    329   }
    330   else
    331   {
    332     //     pOnePart->bEnableFlag = 0;
    333     pOnePart->iLength     = 0;
    334   }
    335 }
    336 
    337 /** Run partition tree disable
    338  */
    339 Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx)
    340 {
    341   SAOQTPart*  pOnePart= &(psQTPart[iPartIdx]);
    342   pOnePart->bSplit      = false;
    343   pOnePart->iLength     =  0;
    344   pOnePart->iBestType   = -1;
    345 
    346   if (pOnePart->PartLevel < m_uiMaxSplitLevel)
    347   {
    348     for (Int i=0; i<NUM_DOWN_PART; i++)
    349     {
    350       disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    351     }
    352   }
    353 }
    354 
    355 /** Run quadtree decision function
    356  * \param  iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal
    357  */
    358 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr)
    359 {
    360   SAOQTPart*  pOnePart = &(psQTPart[iPartIdx]);
    361 
    362   UInt uiDepth = pOnePart->PartLevel;
    363   UInt uhNextDepth = uiDepth+1;
    364 
    365   if (iPartIdx == 0)
    366   {
    367     dCostFinal = 0;
    368   }
    369 
    370   //SAO for this part
    371   if(!pOnePart->bProcessed)
    372   {
    373     rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr);
    374   }
    375 
    376   //SAO for sub 4 parts
    377   if (pOnePart->PartLevel < iMaxLevel)
    378   {
    379     Double      dCostNotSplit = dLambda + pOnePart->dMinCost;
    380     Double      dCostSplit    = dLambda;
    381 
    382     for (Int i=0; i< NUM_DOWN_PART ;i++)
    383     {
    384       if( m_bUseSBACRD ) 
    385       {
    386         if ( 0 == i) //initialize RD with previous depth buffer
    387         {
    388           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    389         }
    390         else
    391         {
    392           m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    393         }
    394       } 
    395       runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr);
    396       dCostSplit += dCostFinal;
    397       if( m_bUseSBACRD )
    398       {
    399         m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]);
    400       }
    401     }
    402 
    403     if(dCostSplit < dCostNotSplit)
    404     {
    405       dCostFinal = dCostSplit;
    406       pOnePart->bSplit      = true;
    407       pOnePart->iLength     =  0;
    408       pOnePart->iBestType   = -1;
    409       if( m_bUseSBACRD )
    410       {
    411         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]);
    412       }
    413     }
    414     else
    415     {
    416       dCostFinal = dCostNotSplit;
    417       pOnePart->bSplit = false;
    418       for (Int i=0; i<NUM_DOWN_PART; i++)
    419       {
    420         disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]);
    421       }
    422       if( m_bUseSBACRD )
    423       {
    424         m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);
    425       }
    426     }
    427   }
    428   else
    429   {
    430     dCostFinal = pOnePart->dMinCost;
    431   }
    432 }
    433 
    434 /** delete allocated memory of TEncSampleAdaptiveOffset class.
    435  */
    436 Void TEncSampleAdaptiveOffset::destroyEncBuffer()
    437 {
    438   for (Int i=0;i<m_iNumTotalParts;i++)
    439   {
    440     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    441     {
    442       if (m_iCount [i][j])
    443       {
    444         delete [] m_iCount [i][j];
    445       }
    446       if (m_iOffset[i][j])
    447       {
    448         delete [] m_iOffset[i][j];
    449       }
    450       if (m_iOffsetOrg[i][j])
    451       {
    452         delete [] m_iOffsetOrg[i][j];
    453       }
    454     }
    455     if (m_iRate[i])
    456     {
    457       delete [] m_iRate[i];
    458     }
    459     if (m_iDist[i])
    460     {
    461       delete [] m_iDist[i];
    462     }
    463     if (m_dCost[i])
    464     {
    465       delete [] m_dCost[i];
    466     }
    467     if (m_iCount [i])
    468     {
    469       delete [] m_iCount [i];
    470     }
    471     if (m_iOffset[i])
    472     {
    473       delete [] m_iOffset[i];
    474     }
    475     if (m_iOffsetOrg[i])
    476     {
    477       delete [] m_iOffsetOrg[i];
    478     }
    479 
    480   }
    481   if (m_iDistOrg)
    482   {
    483     delete [] m_iDistOrg ; m_iDistOrg = NULL;
    484   }
    485   if (m_dCostPartBest)
    486   {
    487     delete [] m_dCostPartBest ; m_dCostPartBest = NULL;
    488   }
    489   if (m_iTypePartBest)
    490   {
    491     delete [] m_iTypePartBest ; m_iTypePartBest = NULL;
    492   }
    493   if (m_iRate)
    494   {
    495     delete [] m_iRate ; m_iRate = NULL;
    496   }
    497   if (m_iDist)
    498   {
    499     delete [] m_iDist ; m_iDist = NULL;
    500   }
    501   if (m_dCost)
    502   {
    503     delete [] m_dCost ; m_dCost = NULL;
    504   }
    505   if (m_iCount)
    506   {
    507     delete [] m_iCount  ; m_iCount = NULL;
    508   }
    509   if (m_iOffset)
    510   {
    511     delete [] m_iOffset ; m_iOffset = NULL;
    512   }
    513   if (m_iOffsetOrg)
    514   {
    515     delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL;
    516   }
    517   Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
    518 
    519   for (Int i=0;i<numLcu;i++)
    520   {
    521     for (Int j=0;j<3;j++)
    522     {
    523       for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
    524       {
    525         if (m_count_PreDblk [i][j][k])
    526         {
    527           delete [] m_count_PreDblk [i][j][k];
    528         }
    529         if (m_offsetOrg_PreDblk[i][j][k])
    530         {
    531           delete [] m_offsetOrg_PreDblk[i][j][k];
    532         }
    533       }
    534       if (m_count_PreDblk [i][j])
    535       {
    536         delete [] m_count_PreDblk [i][j];
    537       }
    538       if (m_offsetOrg_PreDblk[i][j])
    539       {
    540         delete [] m_offsetOrg_PreDblk[i][j];
    541       }
    542     }
    543     if (m_count_PreDblk [i])
    544     {
    545       delete [] m_count_PreDblk [i];
    546     }
    547     if (m_offsetOrg_PreDblk[i])
    548     {
    549       delete [] m_offsetOrg_PreDblk[i];
    550     }
    551   }
    552   if (m_count_PreDblk)
    553   {
    554     delete [] m_count_PreDblk  ; m_count_PreDblk = NULL;
    555   }
    556   if (m_offsetOrg_PreDblk)
    557   {
    558     delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL;
    559   }
    560 
    561   Int iMaxDepth = 4;
    562   Int iDepth;
    563   for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    564   {
    565     for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    566     {
    567       delete m_pppcRDSbacCoder[iDepth][iCIIdx];
    568       delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
    569     }
    570   }
    571 
    572   for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    573   {
    574     delete [] m_pppcRDSbacCoder[iDepth];
    575     delete [] m_pppcBinCoderCABAC[iDepth];
    576   }
    577 
    578   delete [] m_pppcRDSbacCoder;
    579   delete [] m_pppcBinCoderCABAC;
    580 }
    581 
    582 /** create Encoder Buffer for SAO
    583  * \param
    584  */
    585 Void TEncSampleAdaptiveOffset::createEncBuffer()
    586 {
    587   m_iDistOrg = new Int64 [m_iNumTotalParts];
    588   m_dCostPartBest = new Double [m_iNumTotalParts];
    589   m_iTypePartBest = new Int [m_iNumTotalParts];
    590 
    591   m_iRate = new Int64* [m_iNumTotalParts];
    592   m_iDist = new Int64* [m_iNumTotalParts];
    593   m_dCost = new Double*[m_iNumTotalParts];
    594 
    595   m_iCount  = new Int64 **[m_iNumTotalParts];
    596   m_iOffset = new Int64 **[m_iNumTotalParts];
    597   m_iOffsetOrg = new Int64 **[m_iNumTotalParts];
    598 
    599   for (Int i=0;i<m_iNumTotalParts;i++)
    600   {
    601     m_iRate[i] = new Int64  [MAX_NUM_SAO_TYPE];
    602     m_iDist[i] = new Int64  [MAX_NUM_SAO_TYPE];
    603     m_dCost[i] = new Double [MAX_NUM_SAO_TYPE];
    604 
    605     m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE];
    606     m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    607     m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE];
    608 
    609     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    610     {
    611       m_iCount [i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    612       m_iOffset[i][j]   = new Int64 [MAX_NUM_SAO_CLASS];
    613       m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS];
    614     }
    615   }
    616   Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight;
    617   m_count_PreDblk  = new Int64 ***[numLcu];
    618   m_offsetOrg_PreDblk = new Int64 ***[numLcu];
    619   for (Int i=0; i<numLcu; i++)
    620   {
    621     m_count_PreDblk[i]  = new Int64 **[3];
    622     m_offsetOrg_PreDblk[i] = new Int64 **[3];
    623 
    624     for (Int j=0;j<3;j++)
    625     {
    626       m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
    627       m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE];
    628 
    629       for (Int k=0;k<MAX_NUM_SAO_TYPE;k++)
    630       {
    631         m_count_PreDblk [i][j][k]   = new Int64 [MAX_NUM_SAO_CLASS];
    632         m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS];
    633       }
    634     }
    635   }
    636 
    637   Int iMaxDepth = 4;
    638   m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1];
    639 #if FAST_BIT_EST
    640   m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1];
    641 #else
    642   m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1];
    643 #endif
    644 
    645   for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ )
    646   {
    647     m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
    648 #if FAST_BIT_EST
    649     m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
    650 #else
    651     m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
    652 #endif
    653     for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
    654     {
    655       m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
    656 #if FAST_BIT_EST
    657       m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
    658 #else
    659       m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
    660 #endif
    661       m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
    662     }
    663   }
    664 }
    665 
    666 /** Start SAO encoder
    667  * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder
    668  */
    669 Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder)
    670 {
    671     m_bUseSBACRD = true;
    672   m_pcPic = pcPic;
    673   m_pcEntropyCoder = pcEntropyCoder;
    674 
     62TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
     63{
     64  m_pppcRDSbacCoder = NULL;           
     65  m_pcRDGoOnSbacCoder = NULL;
     66  m_pppcBinCoderCABAC = NULL;   
     67  m_statData = NULL;
     68#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     69  m_preDBFstatData = NULL;
     70#endif
     71}
     72
     73TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
     74{
     75  destroyEncData();
     76}
     77
     78#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     79Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed)
     80#else
     81Void TEncSampleAdaptiveOffset::createEncData()
     82#endif
     83{
     84
     85  //cabac coder for RDO
     86  m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS];
     87  m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS];
     88
     89  for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++)
     90  {
     91    m_pppcRDSbacCoder[cs] = new TEncSbac;
     92    m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter;
     93    m_pppcRDSbacCoder   [cs]->init( m_pppcBinCoderCABAC [cs] );
     94  }
     95
     96
     97  //statistics
     98  m_statData = new SAOStatData**[m_numCTUsPic];
     99  for(Int i=0; i< m_numCTUsPic; i++)
     100  {
     101    m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     102    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     103    {
     104      m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     105    }
     106  }
     107#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     108  if(isPreDBFSamplesUsed)
     109  {
     110    m_preDBFstatData = new SAOStatData**[m_numCTUsPic];
     111    for(Int i=0; i< m_numCTUsPic; i++)
     112    {
     113      m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     114      for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     115      {
     116        m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     117      }
     118    }
     119
     120  }
     121#endif
     122
     123#if SAO_ENCODING_CHOICE
     124  ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate));
     125#endif
     126
     127  for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     128  {
     129    m_skipLinesR[SAO_Y ][typeIdc]= 5;
     130    m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     131
     132    m_skipLinesB[SAO_Y ][typeIdc]= 4;
     133    m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     134
     135#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     136    if(isPreDBFSamplesUsed)
     137    {
     138      switch(typeIdc)
     139      {
     140      case SAO_TYPE_EO_0:
     141        {
     142          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     143          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     144
     145          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     146          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     147        }
     148        break;
     149      case SAO_TYPE_EO_90:
     150        {
     151          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     152          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     153
     154          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     155          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     156        }
     157        break;
     158      case SAO_TYPE_EO_135:
     159      case SAO_TYPE_EO_45:
     160        {
     161          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     162          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     163
     164          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     165          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     166        }
     167        break;
     168      case SAO_TYPE_BO:
     169        {
     170          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     171          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     172
     173          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     174          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     175        }
     176        break;
     177      default:
     178        {
     179          printf("Not a supported type");
     180          assert(0);
     181          exit(-1);
     182        }
     183      }
     184    }
     185#endif   
     186  }
     187
     188}
     189
     190Void TEncSampleAdaptiveOffset::destroyEncData()
     191{
     192  if(m_pppcRDSbacCoder != NULL)
     193  {
     194    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     195    {
     196      delete m_pppcRDSbacCoder[cs];
     197    }
     198    delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL;
     199  }
     200
     201  if(m_pppcBinCoderCABAC != NULL)
     202  {
     203    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     204    {
     205      delete m_pppcBinCoderCABAC[cs];
     206    }
     207    delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL;
     208  }
     209
     210  if(m_statData != NULL)
     211  {
     212    for(Int i=0; i< m_numCTUsPic; i++)
     213    {
     214      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     215      {
     216        delete[] m_statData[i][compIdx];
     217      }
     218      delete[] m_statData[i];
     219    }
     220    delete[] m_statData; m_statData = NULL;
     221  }
     222#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     223  if(m_preDBFstatData != NULL)
     224  {
     225    for(Int i=0; i< m_numCTUsPic; i++)
     226    {
     227      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     228      {
     229        delete[] m_preDBFstatData[i][compIdx];
     230      }
     231      delete[] m_preDBFstatData[i];
     232    }
     233    delete[] m_preDBFstatData; m_preDBFstatData = NULL;
     234  }
     235
     236#endif
     237}
     238
     239Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice)
     240{
    675241  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
    676   m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0));
    677   m_pcEntropyCoder->resetEntropy();
    678   m_pcEntropyCoder->resetBits();
    679 
    680   if( m_bUseSBACRD )
    681   {
    682     m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
    683     m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]);
    684   }
    685 }
    686 
    687 /** End SAO encoder
    688  */
    689 Void TEncSampleAdaptiveOffset::endSaoEnc()
    690 {
    691   m_pcPic = NULL;
    692   m_pcEntropyCoder = NULL;
    693 }
    694 
    695 inline Int xSign(Int x)
    696 {
    697   return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31)));
    698 }
    699 
    700 /** Calculate SAO statistics for non-cross-slice or non-cross-tile processing
    701  * \param  pRecStart to-be-filtered block buffer pointer
    702  * \param  pOrgStart original block buffer pointer
    703  * \param  stride picture buffer stride
    704  * \param  ppStat statistics buffer
    705  * \param  ppCount counter buffer
    706  * \param  width block width
    707  * \param  height block height
    708  * \param  pbBorderAvail availabilities of block border pixels
    709  */
    710 Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr)
    711 {
    712   Int64 *stats, *count;
    713   Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1;
    714   Pel *pOrg, *pRec;
    715   UInt edgeType;
    716   Int x, y;
    717   Pel *pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    718 
    719   //--------- Band offset-----------//
    720   stats = ppStats[SAO_BO];
    721   count = ppCount[SAO_BO];
    722   pOrg   = pOrgStart;
    723   pRec   = pRecStart;
    724   for (y=0; y< height; y++)
    725   {
    726     for (x=0; x< width; x++)
    727     {
    728       classIdx = pTableBo[pRec[x]];
    729       if (classIdx)
    730       {
    731         stats[classIdx] += (pOrg[x] - pRec[x]);
    732         count[classIdx] ++;
    733       }
    734     }
    735     pOrg += stride;
    736     pRec += stride;
    737   }
    738   //---------- Edge offset 0--------------//
    739   stats = ppStats[SAO_EO_0];
    740   count = ppCount[SAO_EO_0];
    741   pOrg   = pOrgStart;
    742   pRec   = pRecStart;
    743 
    744 
    745   startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    746   endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
    747   for (y=0; y< height; y++)
    748   {
    749     signLeft = xSign(pRec[startX] - pRec[startX-1]);
    750     for (x=startX; x< endX; x++)
    751     {
    752       signRight =  xSign(pRec[x] - pRec[x+1]);
    753       edgeType =  signRight + signLeft + 2;
    754       signLeft  = -signRight;
    755 
    756       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    757       count[m_auiEoTable[edgeType]] ++;
    758     }
    759     pRec  += stride;
    760     pOrg += stride;
    761   }
    762 
    763   //---------- Edge offset 1--------------//
    764   stats = ppStats[SAO_EO_1];
    765   count = ppCount[SAO_EO_1];
    766   pOrg   = pOrgStart;
    767   pRec   = pRecStart;
    768 
    769   startY = (pbBorderAvail[SGU_T]) ? 0 : 1;
    770   endY   = (pbBorderAvail[SGU_B]) ? height : height-1;
    771   if (!pbBorderAvail[SGU_T])
    772   {
    773     pRec  += stride;
    774     pOrg  += stride;
    775   }
    776 
    777   for (x=0; x< width; x++)
    778   {
    779     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
    780   }
    781   for (y=startY; y<endY; y++)
    782   {
    783     for (x=0; x< width; x++)
    784     {
    785       signDown     =  xSign(pRec[x] - pRec[x+stride]);
    786       edgeType    =  signDown + m_iUpBuff1[x] + 2;
    787       m_iUpBuff1[x] = -signDown;
    788 
    789       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    790       count[m_auiEoTable[edgeType]] ++;
    791     }
    792     pOrg += stride;
    793     pRec += stride;
    794   }
    795   //---------- Edge offset 2--------------//
    796   stats = ppStats[SAO_EO_2];
    797   count = ppCount[SAO_EO_2];
    798   pOrg   = pOrgStart;
    799   pRec   = pRecStart;
    800 
    801   posShift= stride + 1;
    802 
    803   startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ;
    804   endX   = (pbBorderAvail[SGU_R]) ? width : (width-1);
    805 
    806   //prepare 2nd line upper sign
    807   pRec += stride;
    808   for (x=startX; x< endX+1; x++)
    809   {
    810     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
    811   }
    812 
    813   //1st line
    814   pRec -= stride;
    815   if(pbBorderAvail[SGU_TL])
    816   {
    817     x= 0;
    818     edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    819     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    820     count[m_auiEoTable[edgeType]] ++;
    821   }
    822   if(pbBorderAvail[SGU_T])
    823   {
    824     for(x= 1; x< endX; x++)
    825     {
    826       edgeType      =  xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2;
    827       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    828       count[m_auiEoTable[edgeType]] ++;
    829     }
    830   }
    831   pRec   += stride;
    832   pOrg   += stride;
    833 
    834   //middle lines
    835   for (y= 1; y< height-1; y++)
    836   {
    837     for (x=startX; x<endX; x++)
    838     {
    839       signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
    840       edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    841       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    842       count[m_auiEoTable[edgeType]] ++;
    843 
    844       m_iUpBufft[x+1] = -signDown1;
    845     }
    846     m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]);
    847 
    848     ipSwap     = m_iUpBuff1;
    849     m_iUpBuff1 = m_iUpBufft;
    850     m_iUpBufft = ipSwap;
    851 
    852     pRec  += stride;
    853     pOrg  += stride;
    854   }
    855 
    856   //last line
    857   if(pbBorderAvail[SGU_B])
    858   {
    859     for(x= startX; x< width-1; x++)
    860     {
    861       edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    862       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    863       count[m_auiEoTable[edgeType]] ++;
    864     }
    865   }
    866   if(pbBorderAvail[SGU_BR])
    867   {
    868     x= width -1;
    869     edgeType =  xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    870     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    871     count[m_auiEoTable[edgeType]] ++;
    872   }
    873 
    874   //---------- Edge offset 3--------------//
    875 
    876   stats = ppStats[SAO_EO_3];
    877   count = ppCount[SAO_EO_3];
    878   pOrg   = pOrgStart;
    879   pRec   = pRecStart;
    880 
    881   posShift     = stride - 1;
    882   startX = (pbBorderAvail[SGU_L]) ? 0 : 1;
    883   endX   = (pbBorderAvail[SGU_R]) ? width : (width -1);
    884 
    885   //prepare 2nd line upper sign
    886   pRec += stride;
    887   for (x=startX-1; x< endX; x++)
    888   {
    889     m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]);
    890   }
    891 
    892 
    893   //first line
    894   pRec -= stride;
    895   if(pbBorderAvail[SGU_T])
    896   {
    897     for(x= startX; x< width -1; x++)
    898     {
    899       edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    900       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    901       count[m_auiEoTable[edgeType]] ++;
    902     }
    903   }
    904   if(pbBorderAvail[SGU_TR])
    905   {
    906     x= width-1;
    907     edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2;
    908     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    909     count[m_auiEoTable[edgeType]] ++;
    910   }
    911   pRec  += stride;
    912   pOrg  += stride;
    913 
    914   //middle lines
    915   for (y= 1; y< height-1; y++)
    916   {
    917     for(x= startX; x< endX; x++)
    918     {
    919       signDown1      =  xSign(pRec[x] - pRec[x+ posShift]) ;
    920       edgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    921 
    922       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    923       count[m_auiEoTable[edgeType]] ++;
    924       m_iUpBuff1[x-1] = -signDown1;
    925 
    926     }
    927     m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
    928 
    929     pRec  += stride;
    930     pOrg  += stride;
    931   }
    932 
    933   //last line
    934   if(pbBorderAvail[SGU_BL])
    935   {
    936     x= 0;
    937     edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    938     stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    939     count[m_auiEoTable[edgeType]] ++;
    940 
    941   }
    942   if(pbBorderAvail[SGU_B])
    943   {
    944     for(x= 1; x< endX; x++)
    945     {
    946       edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2;
    947       stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]);
    948       count[m_auiEoTable[edgeType]] ++;
    949     }
    950   }
    951 }
    952 
    953 /** Calculate SAO statistics for current LCU
    954  * \param  iAddr,  iPartIdx,  iYCbCr
    955  */
    956 Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr)
    957 {
    958   if(!m_bUseNIF)
    959   {
    960     calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr);
    961   }
    962   else
    963   {
    964     Int64** ppStats = m_iOffsetOrg[iPartIdx];
    965     Int64** ppCount = m_iCount    [iPartIdx];
    966 
    967     //parameters
    968     Int  isChroma = (iYCbCr != 0)? 1:0;
    969     Int  stride   = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride());
    970     Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr);
    971     Pel* pPicRec  = getPicYuvAddr(m_pcYuvTmp, iYCbCr);
    972 
    973     std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks());
    974 
    975     //variables
    976     UInt  xPos, yPos, width, height;
    977     Bool* pbBorderAvail;
    978     UInt  posOffset;
    979 
    980     for(Int i=0; i< vFilterBlocks.size(); i++)
    981     {
    982       xPos        = vFilterBlocks[i].posX   >> isChroma;
    983       yPos        = vFilterBlocks[i].posY   >> isChroma;
    984       width       = vFilterBlocks[i].width  >> isChroma;
    985       height      = vFilterBlocks[i].height >> isChroma;
    986       pbBorderAvail = vFilterBlocks[i].isBorderAvailable;
    987 
    988       posOffset = (yPos* stride) + xPos;
    989 
    990       calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail, iYCbCr);
    991     }
    992   }
    993 
    994 }
    995 
    996 /** Calculate SAO statistics for current LCU without non-crossing slice
    997  * \param  iAddr,  iPartIdx,  iYCbCr
    998  */
    999 Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr)
    1000 {
    1001   Int x,y;
    1002   TComDataCU *pTmpCu = m_pcPic->getCU(iAddr);
    1003   TComSPS *pTmpSPS =  m_pcPic->getSlice(0)->getSPS();
    1004 
    1005   Pel* pOrg;
    1006   Pel* pRec;
    1007   Int iStride;
    1008   Int iLcuHeight = pTmpSPS->getMaxCUHeight();
    1009   Int iLcuWidth  = pTmpSPS->getMaxCUWidth();
    1010   UInt uiLPelX   = pTmpCu->getCUPelX();
    1011   UInt uiTPelY   = pTmpCu->getCUPelY();
    1012   UInt uiRPelX;
    1013   UInt uiBPelY;
    1014   Int64* iStats;
    1015   Int64* iCount;
    1016   Int iClassIdx;
    1017   Int iPicWidthTmp;
    1018   Int iPicHeightTmp;
    1019   Int iStartX;
    1020   Int iStartY;
    1021   Int iEndX;
    1022   Int iEndY;
    1023   Pel* pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    1024 
    1025   Int iIsChroma = (iYCbCr!=0)? 1:0;
    1026   Int numSkipLine = iIsChroma? 2:4;
    1027   if (m_saoLcuBasedOptimization == 0)
    1028   {
    1029     numSkipLine = 0;
    1030   }
    1031 
    1032   Int numSkipLineRight = iIsChroma? 3:5;
    1033   if (m_saoLcuBasedOptimization == 0)
    1034   {
    1035     numSkipLineRight = 0;
    1036   }
    1037 
    1038   iPicWidthTmp  = m_iPicWidth  >> iIsChroma;
    1039   iPicHeightTmp = m_iPicHeight >> iIsChroma;
    1040   iLcuWidth     = iLcuWidth    >> iIsChroma;
    1041   iLcuHeight    = iLcuHeight   >> iIsChroma;
    1042   uiLPelX       = uiLPelX      >> iIsChroma;
    1043   uiTPelY       = uiTPelY      >> iIsChroma;
    1044   uiRPelX       = uiLPelX + iLcuWidth  ;
    1045   uiBPelY       = uiTPelY + iLcuHeight ;
    1046   uiRPelX       = uiRPelX > iPicWidthTmp  ? iPicWidthTmp  : uiRPelX;
    1047   uiBPelY       = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY;
    1048   iLcuWidth     = uiRPelX - uiLPelX;
    1049   iLcuHeight    = uiBPelY - uiTPelY;
    1050 
    1051   iStride    =  (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride();
    1052 
    1053 //if(iSaoType == BO_0 || iSaoType == BO_1)
    1054   {
    1055     if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    1056     {
    1057       numSkipLine = iIsChroma? 1:3;
    1058       numSkipLineRight = iIsChroma? 2:4;
    1059     }
    1060     iStats = m_iOffsetOrg[iPartIdx][SAO_BO];
    1061     iCount = m_iCount    [iPartIdx][SAO_BO];
    1062 
    1063     pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    1064     pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    1065 
    1066     iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
    1067     iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine;
    1068     for (y=0; y<iEndY; y++)
    1069     {
    1070       for (x=0; x<iEndX; x++)
    1071       {
    1072         iClassIdx = pTableBo[pRec[x]];
    1073         if (iClassIdx)
    1074         {
    1075           iStats[iClassIdx] += (pOrg[x] - pRec[x]);
    1076           iCount[iClassIdx] ++;
    1077         }
    1078       }
    1079       pOrg += iStride;
    1080       pRec += iStride;
    1081     }
    1082 
    1083   }
    1084   Int iSignLeft;
    1085   Int iSignRight;
    1086   Int iSignDown;
    1087   Int iSignDown1;
    1088   Int iSignDown2;
    1089 
    1090   UInt uiEdgeType;
    1091 
    1092 //if (iSaoType == EO_0  || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3)
    1093   {
    1094   //if (iSaoType == EO_0)
    1095     {
    1096       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    1097       {
    1098         numSkipLine = iIsChroma? 1:3;
    1099         numSkipLineRight = iIsChroma? 3:5;
    1100       }
    1101       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0];
    1102       iCount = m_iCount    [iPartIdx][SAO_EO_0];
    1103 
    1104       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    1105       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    1106 
    1107       iStartX = (uiLPelX == 0) ? 1 : 0;
    1108       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    1109       for (y=0; y<iLcuHeight-numSkipLine; y++)
    1110       {
    1111         iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]);
    1112         for (x=iStartX; x< iEndX; x++)
    1113         {
    1114           iSignRight =  xSign(pRec[x] - pRec[x+1]);
    1115           uiEdgeType =  iSignRight + iSignLeft + 2;
    1116           iSignLeft  = -iSignRight;
    1117 
    1118           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1119           iCount[m_auiEoTable[uiEdgeType]] ++;
    1120         }
    1121         pOrg += iStride;
    1122         pRec += iStride;
    1123       }
    1124     }
    1125 
    1126   //if (iSaoType == EO_1)
    1127     {
    1128       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    1129       {
    1130         numSkipLine = iIsChroma? 2:4;
    1131         numSkipLineRight = iIsChroma? 2:4;
    1132       }
    1133       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1];
    1134       iCount = m_iCount    [iPartIdx][SAO_EO_1];
    1135 
    1136       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    1137       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    1138 
    1139       iStartY = (uiTPelY == 0) ? 1 : 0;
    1140       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight;
    1141       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    1142       if (uiTPelY == 0)
    1143       {
    1144         pOrg += iStride;
    1145         pRec += iStride;
    1146       }
    1147 
    1148       for (x=0; x< iLcuWidth; x++)
    1149       {
    1150         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]);
    1151       }
    1152       for (y=iStartY; y<iEndY; y++)
    1153       {
    1154         for (x=0; x<iEndX; x++)
    1155         {
    1156           iSignDown     =  xSign(pRec[x] - pRec[x+iStride]);
    1157           uiEdgeType    =  iSignDown + m_iUpBuff1[x] + 2;
    1158           m_iUpBuff1[x] = -iSignDown;
    1159 
    1160           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1161           iCount[m_auiEoTable[uiEdgeType]] ++;
    1162         }
    1163         pOrg += iStride;
    1164         pRec += iStride;
    1165       }
    1166     }
    1167   //if (iSaoType == EO_2)
    1168     {
    1169       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    1170       {
    1171         numSkipLine = iIsChroma? 2:4;
    1172         numSkipLineRight = iIsChroma? 3:5;
    1173       }
    1174       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2];
    1175       iCount = m_iCount    [iPartIdx][SAO_EO_2];
    1176 
    1177       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    1178       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    1179 
    1180       iStartX = (uiLPelX == 0) ? 1 : 0;
    1181       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    1182 
    1183       iStartY = (uiTPelY == 0) ? 1 : 0;
    1184       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    1185       if (uiTPelY == 0)
    1186       {
    1187         pOrg += iStride;
    1188         pRec += iStride;
    1189       }
    1190 
    1191       for (x=iStartX; x<iEndX; x++)
    1192       {
    1193         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]);
    1194       }
    1195       for (y=iStartY; y<iEndY; y++)
    1196       {
    1197         iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]);
    1198         for (x=iStartX; x<iEndX; x++)
    1199         {
    1200           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride+1]) ;
    1201           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    1202           m_iUpBufft[x+1] = -iSignDown1;
    1203           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1204           iCount[m_auiEoTable[uiEdgeType]] ++;
    1205         }
    1206         m_iUpBufft[iStartX] = iSignDown2;
    1207         ipSwap     = m_iUpBuff1;
    1208         m_iUpBuff1 = m_iUpBufft;
    1209         m_iUpBufft = ipSwap;
    1210 
    1211         pRec += iStride;
    1212         pOrg += iStride;
    1213       }
    1214     }
    1215   //if (iSaoType == EO_3  )
    1216     {
    1217       if( m_saoLcuBasedOptimization && m_saoLcuBoundary )
    1218       {
    1219         numSkipLine = iIsChroma? 2:4;
    1220         numSkipLineRight = iIsChroma? 3:5;
    1221       }
    1222       iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3];
    1223       iCount = m_iCount    [iPartIdx][SAO_EO_3];
    1224 
    1225       pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr);
    1226       pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr);
    1227 
    1228       iStartX = (uiLPelX == 0) ? 1 : 0;
    1229       iEndX   = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight;
    1230 
    1231       iStartY = (uiTPelY == 0) ? 1 : 0;
    1232       iEndY   = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine;
    1233       if (iStartY == 1)
    1234       {
    1235         pOrg += iStride;
    1236         pRec += iStride;
    1237       }
    1238 
    1239       for (x=iStartX-1; x<iEndX; x++)
    1240       {
    1241         m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]);
    1242       }
    1243 
    1244       for (y=iStartY; y<iEndY; y++)
    1245       {
    1246         for (x=iStartX; x<iEndX; x++)
    1247         {
    1248           iSignDown1      =  xSign(pRec[x] - pRec[x+iStride-1]) ;
    1249           uiEdgeType      =  iSignDown1 + m_iUpBuff1[x] + 2;
    1250           m_iUpBuff1[x-1] = -iSignDown1;
    1251           iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1252           iCount[m_auiEoTable[uiEdgeType]] ++;
    1253         }
    1254         m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]);
    1255 
    1256         pRec += iStride;
    1257         pOrg += iStride;
    1258       }
    1259     }
    1260   }
    1261 }
    1262 
    1263 
    1264 Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic )
    1265 {
    1266   Int addr, yCbCr;
    1267   Int x,y;
    1268   TComSPS *pTmpSPS =  pcPic->getSlice(0)->getSPS();
    1269 
    1270   Pel* pOrg;
    1271   Pel* pRec;
    1272   Int stride;
    1273   Int lcuHeight = pTmpSPS->getMaxCUHeight();
    1274   Int lcuWidth  = pTmpSPS->getMaxCUWidth();
    1275   UInt rPelX;
    1276   UInt bPelY;
    1277   Int64* stats;
    1278   Int64* count;
    1279   Int classIdx;
    1280   Int picWidthTmp = 0;
    1281   Int picHeightTmp = 0;
    1282   Int startX;
    1283   Int startY;
    1284   Int endX;
    1285   Int endY;
    1286   Int firstX, firstY;
    1287 
    1288   Int idxY;
    1289   Int idxX;
    1290   Int frameHeightInCU = m_iNumCuInHeight;
    1291   Int frameWidthInCU  = m_iNumCuInWidth;
    1292   Int j, k;
    1293 
    1294   Int isChroma;
    1295   Int numSkipLine, numSkipLineRight;
    1296 
    1297   UInt lPelX, tPelY;
    1298   TComDataCU *pTmpCu;
    1299   Pel* pTableBo;
    1300 
    1301   for (idxY = 0; idxY< frameHeightInCU; idxY++)
    1302   {
    1303     for (idxX = 0; idxX< frameWidthInCU; idxX++)
    1304     {
    1305       lcuHeight = pTmpSPS->getMaxCUHeight();
    1306       lcuWidth  = pTmpSPS->getMaxCUWidth();
    1307       addr     = idxX  + frameWidthInCU*idxY;
    1308       pTmpCu = pcPic->getCU(addr);
    1309       lPelX   = pTmpCu->getCUPelX();
    1310       tPelY   = pTmpCu->getCUPelY();
    1311       for( yCbCr = 0; yCbCr < 3; yCbCr++ )
    1312       {
    1313         isChroma = (yCbCr!=0)? 1:0;
    1314 
    1315         for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
    1316         {
    1317           for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
    1318           {
    1319             m_count_PreDblk    [addr][yCbCr][j][k] = 0;
    1320             m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0;
    1321           } 
    1322         }
    1323         if( yCbCr == 0 )
    1324         {
    1325           picWidthTmp  = m_iPicWidth;
    1326           picHeightTmp = m_iPicHeight;
    1327         }
    1328         else if( yCbCr == 1 )
    1329         {
    1330           picWidthTmp  = m_iPicWidth  >> isChroma;
    1331           picHeightTmp = m_iPicHeight >> isChroma;
    1332           lcuWidth     = lcuWidth    >> isChroma;
    1333           lcuHeight    = lcuHeight   >> isChroma;
    1334           lPelX       = lPelX      >> isChroma;
    1335           tPelY       = tPelY      >> isChroma;
    1336         }
    1337         rPelX       = lPelX + lcuWidth  ;
    1338         bPelY       = tPelY + lcuHeight ;
    1339         rPelX       = rPelX > picWidthTmp  ? picWidthTmp  : rPelX;
    1340         bPelY       = bPelY > picHeightTmp ? picHeightTmp : bPelY;
    1341         lcuWidth     = rPelX - lPelX;
    1342         lcuHeight    = bPelY - tPelY;
    1343 
    1344         stride    =  (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride();
    1345         pTableBo = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo;
    1346 
    1347         //if(iSaoType == BO)
    1348 
    1349         numSkipLine = isChroma? 1:3;
    1350         numSkipLineRight = isChroma? 2:4;
    1351 
    1352         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO];
    1353         count = m_count_PreDblk[addr][yCbCr][SAO_BO];
    1354 
    1355         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    1356         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    1357 
    1358         startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
    1359         startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
    1360 
    1361         for (y=0; y<lcuHeight; y++)
    1362         {
    1363           for (x=0; x<lcuWidth; x++)
    1364           {
    1365             if( x < startX && y < startY )
    1366               continue;
    1367 
    1368             classIdx = pTableBo[pRec[x]];
    1369             if (classIdx)
    1370             {
    1371               stats[classIdx] += (pOrg[x] - pRec[x]);
    1372               count[classIdx] ++;
    1373             }
    1374           }
    1375           pOrg += stride;
    1376           pRec += stride;
    1377         }
    1378 
    1379         Int signLeft;
    1380         Int signRight;
    1381         Int signDown;
    1382         Int signDown1;
    1383         Int signDown2;
    1384 
    1385         UInt uiEdgeType;
    1386 
    1387         //if (iSaoType == EO_0)
    1388 
    1389         numSkipLine = isChroma? 1:3;
    1390         numSkipLineRight = isChroma? 3:5;
    1391 
    1392         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0];
    1393         count = m_count_PreDblk[addr][yCbCr][SAO_EO_0];
    1394 
    1395         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    1396         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    1397 
    1398         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    1399         startY   = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine;
    1400         firstX   = (lPelX == 0) ? 1 : 0;
    1401         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    1402 
    1403         for (y=0; y<lcuHeight; y++)
    1404         {
    1405           signLeft = xSign(pRec[firstX] - pRec[firstX-1]);
    1406           for (x=firstX; x< endX; x++)
    1407           {
    1408             signRight =  xSign(pRec[x] - pRec[x+1]);
    1409             uiEdgeType =  signRight + signLeft + 2;
    1410             signLeft  = -signRight;
    1411 
    1412             if( x < startX && y < startY )
    1413               continue;
    1414 
    1415             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1416             count[m_auiEoTable[uiEdgeType]] ++;
    1417           }
    1418           pOrg += stride;
    1419           pRec += stride;
    1420         }
    1421 
    1422         //if (iSaoType == EO_1)
    1423 
    1424         numSkipLine = isChroma? 2:4;
    1425         numSkipLineRight = isChroma? 2:4;
    1426 
    1427         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1];
    1428         count = m_count_PreDblk[addr][yCbCr][SAO_EO_1];
    1429 
    1430         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    1431         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    1432 
    1433         startX   = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight;
    1434         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    1435         firstY = (tPelY == 0) ? 1 : 0;
    1436         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    1437         if (firstY == 1)
    1438         {
    1439           pOrg += stride;
    1440           pRec += stride;
    1441         }
    1442 
    1443         for (x=0; x< lcuWidth; x++)
    1444         {
    1445           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]);
    1446         }
    1447         for (y=firstY; y<endY; y++)
    1448         {
    1449           for (x=0; x<lcuWidth; x++)
    1450           {
    1451             signDown     =  xSign(pRec[x] - pRec[x+stride]);
    1452             uiEdgeType    =  signDown + m_iUpBuff1[x] + 2;
    1453             m_iUpBuff1[x] = -signDown;
    1454 
    1455             if( x < startX && y < startY )
    1456               continue;
    1457 
    1458             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1459             count[m_auiEoTable[uiEdgeType]] ++;
    1460           }
    1461           pOrg += stride;
    1462           pRec += stride;
    1463         }
    1464 
    1465         //if (iSaoType == EO_2)
    1466 
    1467         numSkipLine = isChroma? 2:4;
    1468         numSkipLineRight = isChroma? 3:5;
    1469 
    1470         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2];
    1471         count = m_count_PreDblk[addr][yCbCr][SAO_EO_2];
    1472 
    1473         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    1474         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    1475 
    1476         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    1477         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    1478         firstX   = (lPelX == 0) ? 1 : 0;
    1479         firstY = (tPelY == 0) ? 1 : 0;
    1480         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    1481         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    1482         if (firstY == 1)
    1483         {
    1484           pOrg += stride;
    1485           pRec += stride;
    1486         }
    1487 
    1488         for (x=firstX; x<endX; x++)
    1489         {
    1490           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]);
    1491         }
    1492         for (y=firstY; y<endY; y++)
    1493         {
    1494           signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]);
    1495           for (x=firstX; x<endX; x++)
    1496           {
    1497             signDown1      =  xSign(pRec[x] - pRec[x+stride+1]) ;
    1498             uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    1499             m_iUpBufft[x+1] = -signDown1;
    1500 
    1501             if( x < startX && y < startY )
    1502               continue;
    1503 
    1504             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1505             count[m_auiEoTable[uiEdgeType]] ++;
    1506           }
    1507           m_iUpBufft[firstX] = signDown2;
    1508           ipSwap     = m_iUpBuff1;
    1509           m_iUpBuff1 = m_iUpBufft;
    1510           m_iUpBufft = ipSwap;
    1511 
    1512           pRec += stride;
    1513           pOrg += stride;
    1514         }
    1515 
    1516         //if (iSaoType == EO_3)
    1517 
    1518         numSkipLine = isChroma? 2:4;
    1519         numSkipLineRight = isChroma? 3:5;
    1520 
    1521         stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3];
    1522         count = m_count_PreDblk[addr][yCbCr][SAO_EO_3];
    1523 
    1524         pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr);
    1525         pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr);
    1526 
    1527         startX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight;
    1528         startY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine;
    1529         firstX   = (lPelX == 0) ? 1 : 0;
    1530         firstY = (tPelY == 0) ? 1 : 0;
    1531         endX   = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth;
    1532         endY   = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight;
    1533         if (firstY == 1)
    1534         {
    1535           pOrg += stride;
    1536           pRec += stride;
    1537         }
    1538 
    1539         for (x=firstX-1; x<endX; x++)
    1540         {
    1541           m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]);
    1542         }
    1543 
    1544         for (y=firstY; y<endY; y++)
    1545         {
    1546           for (x=firstX; x<endX; x++)
    1547           {
    1548             signDown1      =  xSign(pRec[x] - pRec[x+stride-1]) ;
    1549             uiEdgeType      =  signDown1 + m_iUpBuff1[x] + 2;
    1550             m_iUpBuff1[x-1] = -signDown1;
    1551 
    1552             if( x < startX && y < startY )
    1553               continue;
    1554 
    1555             stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]);
    1556             count[m_auiEoTable[uiEdgeType]] ++;
    1557           }
    1558           m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]);
    1559 
    1560           pRec += stride;
    1561           pOrg += stride;
    1562         }
    1563       }
    1564     }
    1565   }
    1566 }
    1567 
    1568 
    1569 /** get SAO statistics
    1570  * \param  *psQTPart,  iYCbCr
    1571  */
    1572 Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr)
    1573 {
    1574   Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx;
    1575   Int i;
    1576   Int iNumTotalType = MAX_NUM_SAO_TYPE;
    1577   Int LcuIdxX;
    1578   Int LcuIdxY;
    1579   Int iAddr;
    1580   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    1581   Int iDownPartIdx;
    1582   Int iPartStart;
    1583   Int iPartEnd;
    1584   SAOQTPart*  pOnePart;
    1585 
    1586   if (m_uiMaxSplitLevel == 0)
    1587   {
    1588     iPartIdx = 0;
    1589     pOnePart = &(psQTPart[iPartIdx]);
    1590     for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
    1591     {
    1592       for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
    1593       {
    1594         iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    1595         calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
    1596       }
    1597     }
    1598   }
    1599   else
    1600   {
    1601     for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++)
    1602     {
    1603       pOnePart = &(psQTPart[iPartIdx]);
    1604       for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
    1605       {
    1606         for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
    1607         {
    1608           iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX;
    1609           calcSaoStatsCu(iAddr, iPartIdx, iYCbCr);
    1610         }
    1611       }
    1612     }
    1613     for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- )
    1614     {
    1615       iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0;
    1616       iPartEnd   = m_aiNumCulPartsLevel[iLevelIdx];
    1617 
    1618       for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++)
    1619       {
    1620         pOnePart = &(psQTPart[iPartIdx]);
    1621         for (i=0; i< NUM_DOWN_PART; i++)
    1622         {
    1623           iDownPartIdx = pOnePart->DownPartsIdx[i];
    1624           for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++)
    1625           {
    1626             for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++)
    1627             {
    1628               m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx];
    1629               m_iCount [iPartIdx][iTypeIdx][iClassIdx]    += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx];
    1630             }
    1631           }
    1632         }
    1633       }
    1634     }
    1635   }
    1636 }
    1637 
    1638 /** reset offset statistics
    1639  * \param
    1640  */
    1641 Void TEncSampleAdaptiveOffset::resetStats()
    1642 {
    1643   for (Int i=0;i<m_iNumTotalParts;i++)
    1644   {
    1645     m_dCostPartBest[i] = MAX_DOUBLE;
    1646     m_iTypePartBest[i] = -1;
    1647     m_iDistOrg[i] = 0;
    1648     for (Int j=0;j<MAX_NUM_SAO_TYPE;j++)
    1649     {
    1650       m_iDist[i][j] = 0;
    1651       m_iRate[i][j] = 0;
    1652       m_dCost[i][j] = 0;
    1653       for (Int k=0;k<MAX_NUM_SAO_CLASS;k++)
    1654       {
    1655         m_iCount [i][j][k] = 0;
    1656         m_iOffset[i][j][k] = 0;
    1657         m_iOffsetOrg[i][j][k] = 0;
    1658       } 
    1659     }
    1660   }
    1661 }
    1662 
    1663 #if SAO_CHROMA_LAMBDA
    1664 /** Sample adaptive offset process
    1665  * \param pcSaoParam
    1666  * \param dLambdaLuma
    1667  * \param dLambdaChroma
    1668  */
    1669 #if SAO_ENCODING_CHOICE
    1670 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth)
    1671 #else
    1672 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
    1673 #endif
    1674 #else
    1675 /** Sample adaptive offset process
    1676  * \param dLambda
    1677  */
    1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)
    1679 #endif
    1680 {
    1681   if(m_bUseNIF)
    1682   {
    1683     m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp);
    1684   }
    1685 
    1686   m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0);
    1687   m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0);
    1688   m_iOffsetThY = 1 << min(g_bitDepthY - 5, 5);
    1689   m_iOffsetThC = 1 << min(g_bitDepthC - 5, 5);
    1690   resetSAOParam(pcSaoParam);
    1691   if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary )
    1692   {
    1693     resetStats();
    1694   }
    1695   Double dCostFinal = 0;
    1696   if ( m_saoLcuBasedOptimization)
    1697   {
    1698 #if SAO_ENCODING_CHOICE
    1699     rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth);
    1700 #else
    1701     rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma);
    1702 #endif
    1703   }
    1704   else
    1705   {
    1706     pcSaoParam->bSaoFlag[0] = 1;
    1707     pcSaoParam->bSaoFlag[1] = 0;
    1708     dCostFinal = 0;
    1709     Double lambdaRdo =  dLambdaLuma;
    1710     resetStats();
    1711     getSaoStats(pcSaoParam->psSaoPart[0], 0);
    1712     runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0);
    1713     pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0;
    1714     if(pcSaoParam->bSaoFlag[0])
    1715     {
    1716       convertQT2SaoUnit(pcSaoParam, 0, 0);
    1717       assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0],  pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0);
    1718     }
    1719   }
    1720   if (pcSaoParam->bSaoFlag[0])
    1721   {
    1722     processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0);
    1723   }
    1724   if (pcSaoParam->bSaoFlag[1])
    1725   {
    1726     processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1);
    1727     processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2);
    1728   }
    1729 }
    1730 /** Check merge SAO unit
    1731  * \param saoUnitCurr current SAO unit
    1732  * \param saoUnitCheck SAO unit tobe check
    1733  * \param dir direction
    1734  */
    1735 Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir)
    1736 {
    1737   Int i ;
    1738   Int countDiff = 0;
    1739   if (saoUnitCurr->partIdx != saoUnitCheck->partIdx)
    1740   {
    1741     if (saoUnitCurr->typeIdx !=-1)
    1742     {
    1743       if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
    1744       {
    1745         for (i=0;i<saoUnitCurr->length;i++)
    1746         {
    1747           countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]);
    1748         }
    1749         countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx);
    1750         if (countDiff ==0)
    1751         {
    1752           saoUnitCurr->partIdx = saoUnitCheck->partIdx;
    1753           if (dir == 1)
    1754           {
    1755             saoUnitCurr->mergeUpFlag = 1;
    1756             saoUnitCurr->mergeLeftFlag = 0;
    1757           }
    1758           else
    1759           {
    1760             saoUnitCurr->mergeUpFlag = 0;
    1761             saoUnitCurr->mergeLeftFlag = 1;
    1762           }
    1763         }
    1764       }
    1765     }
    1766     else
    1767     {
    1768       if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx)
    1769       {
    1770         saoUnitCurr->partIdx = saoUnitCheck->partIdx;
    1771         if (dir == 1)
    1772         {
    1773           saoUnitCurr->mergeUpFlag = 1;
    1774           saoUnitCurr->mergeLeftFlag = 0;
    1775         }
    1776         else
    1777         {
    1778           saoUnitCurr->mergeUpFlag = 0;
    1779           saoUnitCurr->mergeLeftFlag = 1;
    1780         }
    1781       }
    1782     }
    1783   }
    1784 }
    1785 /** Assign SAO unit syntax from picture-based algorithm
    1786  * \param saoLcuParam SAO LCU parameters
    1787  * \param saoPart SAO part
    1788  * \param oneUnitFlag SAO one unit flag
    1789  * \param iYCbCr color component Index
    1790  */
    1791 Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr)
    1792 {
    1793   if (saoPart->bSplit == 0)
    1794   {
    1795     oneUnitFlag = 1;
    1796   }
    1797   else
    1798   {
    1799     Int i,j, addr, addrUp, addrLeft,  idx, idxUp, idxLeft,  idxCount;
    1800 
    1801     oneUnitFlag = 0;
    1802 
    1803     idxCount = -1;
    1804     saoLcuParam[0].mergeUpFlag = 0;
    1805     saoLcuParam[0].mergeLeftFlag = 0;
    1806 
    1807     for (j=0;j<m_iNumCuInHeight;j++)
    1808     {
    1809       for (i=0;i<m_iNumCuInWidth;i++)
    1810       {
    1811         addr     = i + j*m_iNumCuInWidth;
    1812         addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1;
    1813         addrUp   = (addr<m_iNumCuInWidth)      ? -1 : addr - m_iNumCuInWidth;
    1814         idx      = saoLcuParam[addr].partIdxTmp;
    1815         idxLeft  = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp;
    1816         idxUp    = (addrUp == -1)   ? -1 : saoLcuParam[addrUp].partIdxTmp;
    1817 
    1818         if(idx!=idxLeft && idx!=idxUp)
    1819         {
    1820           saoLcuParam[addr].mergeUpFlag   = 0; idxCount++;
    1821           saoLcuParam[addr].mergeLeftFlag = 0;
    1822           saoLcuParam[addr].partIdx = idxCount;
    1823         }
    1824         else if (idx==idxLeft)
    1825         {
    1826           saoLcuParam[addr].mergeUpFlag   = 1;
    1827           saoLcuParam[addr].mergeLeftFlag = 1;
    1828           saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx;
    1829         }
    1830         else if (idx==idxUp)
    1831         {
    1832           saoLcuParam[addr].mergeUpFlag   = 1;
    1833           saoLcuParam[addr].mergeLeftFlag = 0;
    1834           saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx;
    1835         }
    1836         if (addrUp != -1)
    1837         {
    1838           checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1);
    1839         }
    1840         if (addrLeft != -1)
    1841         {
    1842           checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0);
    1843         }
    1844       }
    1845     }
    1846   }
    1847 }
    1848 /** rate distortion optimization of all SAO units
    1849  * \param saoParam SAO parameters
    1850  * \param lambda
    1851  * \param lambdaChroma
    1852  */
    1853 #if SAO_ENCODING_CHOICE
    1854 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth)
    1855 #else
    1856 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma)
    1857 #endif
    1858 {
    1859 
    1860   Int idxY;
    1861   Int idxX;
    1862   Int frameHeightInCU = saoParam->numCuInHeight;
    1863   Int frameWidthInCU  = saoParam->numCuInWidth;
    1864   Int j, k;
    1865   Int addr = 0;
    1866   Int addrUp = -1;
    1867   Int addrLeft = -1;
    1868   Int compIdx = 0;
    1869   SaoLcuParam mergeSaoParam[3][2];
    1870   Double compDistortion[3];
    1871 
    1872   saoParam->bSaoFlag[0] = true;
    1873   saoParam->bSaoFlag[1] = true;
    1874   saoParam->oneUnitFlag[0] = false;
    1875   saoParam->oneUnitFlag[1] = false;
    1876   saoParam->oneUnitFlag[2] = false;
     242  m_pcRDGoOnSbacCoder->setSlice(pcSlice);
     243  m_pcRDGoOnSbacCoder->resetEntropy();
     244  m_pcRDGoOnSbacCoder->resetBits();
     245
     246  m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]);
     247}
     248
     249
     250
     251Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     252#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     253                                         , Bool isPreDBFSamplesUsed
     254#endif
     255                                          )
     256{
     257  TComPicYuv* orgYuv= pPic->getPicYuvOrg();
     258  TComPicYuv* resYuv= pPic->getPicYuvRec();
     259  m_lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2];
     260  TComPicYuv* srcYuv = m_tempPicYuv;
     261  resYuv->copyToPic(srcYuv);
     262  srcYuv->setBorderExtension(false);
     263  srcYuv->extendPicBorder();
     264
     265  //collect statistics
     266  getStatistics(m_statData, orgYuv, srcYuv, pPic);
     267#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     268  if(isPreDBFSamplesUsed)
     269  {
     270    addPreDBFStatistics(m_statData);
     271  }
     272#endif
     273  //slice on/off
     274  decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth());
     275
     276  //block on/off
     277  SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters
     278  decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam());
     279  delete[] reconParams;
     280
     281}
     282
     283#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     284Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic)
     285{
     286  getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true);
     287}
     288
     289Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats)
     290{
     291  for(Int n=0; n< m_numCTUsPic; n++)
     292  {
     293    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     294    {
     295      for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     296      {
     297        blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc];
     298      }
     299    }
     300  }
     301}
     302
     303#endif
     304
     305Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic
     306#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     307                          , Bool isCalculatePreDeblockSamples
     308#endif
     309                          )
     310{
     311  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
     312
     313  for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
     314  {
     315    Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
     316    Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     317    Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
     318    Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
     319
     320    pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     321
     322    //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities.
     323    //For simplicity, here only picture boundaries are considered.
     324
     325    isRightAvail      = (xPos + m_maxCUWidth  < m_picWidth );
     326    isBelowAvail      = (yPos + m_maxCUHeight < m_picHeight);
     327    isBelowRightAvail = (isRightAvail && isBelowAvail);
     328    isBelowLeftAvail  = ((xPos > 0) && (isBelowAvail));
     329    isAboveRightAvail = ((yPos > 0) && (isRightAvail));
     330
     331    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     332    {
     333      Bool isLuma     = (compIdx == SAO_Y);
     334      Int  formatShift= isLuma?0:1;
     335
     336      Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
     337      Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
     338
     339      Int  orgStride  = isLuma?orgYuv->getStride():orgYuv->getCStride();
     340      Pel* orgBlk     = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift);
     341
     342      getBlkStats(compIdx, blkStats[ctu][compIdx] 
     343                , srcBlk, orgBlk, srcStride, orgStride, (width  >> formatShift), (height >> formatShift)
     344                , isLeftAvail,  isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail
     345#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     346                , isCalculatePreDeblockSamples
     347#endif
     348                );
     349
     350    }
     351  }
     352}
     353
     354Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer)
     355{
     356  //decide sliceEnabled[compIdx]
     357  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     358  {
     359    // reset flags & counters
     360    sliceEnabled[compIdx] = true;
    1877361
    1878362#if SAO_ENCODING_CHOICE
    1879363#if SAO_ENCODING_CHOICE_CHROMA
    1880   Int numNoSao[2];
    1881   numNoSao[0] = 0;// Luma
    1882   numNoSao[1] = 0;// Chroma
    1883   if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE )
    1884   {
    1885     saoParam->bSaoFlag[0] = false;
    1886   }
    1887   if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA )
    1888   {
    1889     saoParam->bSaoFlag[1] = false;
    1890   }
    1891 #else
    1892   Int numNoSao = 0;
    1893 
    1894   if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE )
    1895   {
    1896     saoParam->bSaoFlag[0] = false;
    1897     saoParam->bSaoFlag[1] = false;
    1898   }
    1899 #endif
    1900 #endif
    1901 
    1902   for (idxY = 0; idxY< frameHeightInCU; idxY++)
    1903   {
    1904     for (idxX = 0; idxX< frameWidthInCU; idxX++)
    1905     {
    1906       addr     = idxX  + frameWidthInCU*idxY;
    1907       addrUp   = addr < frameWidthInCU ? -1:idxX   + frameWidthInCU*(idxY-1);
    1908       addrLeft = idxX == 0               ? -1:idxX-1 + frameWidthInCU*idxY;
    1909       Int allowMergeLeft = 1;
    1910       Int allowMergeUp   = 1;
    1911       UInt rate;
    1912       Double bestCost, mergeCost;
    1913       if (idxX!=0)
    1914       {
    1915         // check tile id and slice id
    1916         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()))
    1917         {
    1918           allowMergeLeft = 0;
    1919         }
    1920       }
    1921       else
    1922       {
    1923         allowMergeLeft = 0;
    1924       }
    1925       if (idxY!=0)
    1926       {
    1927         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()))
    1928         {
    1929           allowMergeUp = 0;
    1930         }
    1931       }
    1932       else
    1933       {
    1934         allowMergeUp = 0;
    1935       }
    1936 
    1937       compDistortion[0] = 0;
    1938       compDistortion[1] = 0;
    1939       compDistortion[2] = 0;
    1940       m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    1941       if (allowMergeLeft)
    1942       {
    1943         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    1944       }
    1945       if (allowMergeUp)
    1946       {
    1947         m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    1948       }
    1949       m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    1950       // reset stats Y, Cb, Cr
    1951       for ( compIdx=0;compIdx<3;compIdx++)
    1952       {
    1953         for ( j=0;j<MAX_NUM_SAO_TYPE;j++)
    1954         {
    1955           for ( k=0;k< MAX_NUM_SAO_CLASS;k++)
    1956           {
    1957             m_iOffset   [compIdx][j][k] = 0;
    1958             if( m_saoLcuBasedOptimization && m_saoLcuBoundary ){
    1959               m_iCount    [compIdx][j][k] = m_count_PreDblk    [addr][compIdx][j][k];
    1960               m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k];
    1961             }
    1962             else
    1963             {
    1964               m_iCount    [compIdx][j][k] = 0;
    1965               m_iOffsetOrg[compIdx][j][k] = 0;
    1966             }
    1967           } 
    1968         }
    1969         saoParam->saoLcuParam[compIdx][addr].typeIdx       =  -1;
    1970         saoParam->saoLcuParam[compIdx][addr].mergeUpFlag   = 0;
    1971         saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0;
    1972         saoParam->saoLcuParam[compIdx][addr].subTypeIdx    = 0;
    1973 #if SAO_ENCODING_CHOICE
    1974   if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) )
    1975 #endif
    1976         {
    1977           calcSaoStatsCu(addr, compIdx,  compIdx);
    1978 
    1979        }
    1980       }
    1981       saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0,  lambda, &mergeSaoParam[0][0], &compDistortion[0]);
    1982       sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]);
    1983      if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    1984       {
    1985         // Cost of new SAO_params
    1986         m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    1987         m_pcRDGoOnSbacCoder->resetBits();
    1988         if (allowMergeLeft)
    1989         {
    1990           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    1991         }
    1992         if (allowMergeUp)
    1993         {
    1994           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0);
    1995         }
    1996         for ( compIdx=0;compIdx<3;compIdx++)
    1997         {
    1998         if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1]))
    1999           {
    2000            m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    2001           }
    2002         }
    2003 
    2004         rate = m_pcEntropyCoder->getNumberOfWrittenBits();
    2005         bestCost = compDistortion[0] + (Double)rate;
    2006         m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    2007 
    2008         // Cost of Merge
    2009         for(Int mergeUp=0; mergeUp<2; ++mergeUp)
    2010         {
    2011           if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) )
    2012           {
    2013             m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    2014             m_pcRDGoOnSbacCoder->resetBits();
    2015             if (allowMergeLeft)
    2016             {
    2017               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp);
    2018             }
    2019             if ( allowMergeUp && (mergeUp==1) )
    2020             {
    2021               m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1);
    2022             }
    2023 
    2024             rate = m_pcEntropyCoder->getNumberOfWrittenBits();
    2025             mergeCost = compDistortion[mergeUp+1] + (Double)rate;
    2026             if (mergeCost < bestCost)
    2027             {
    2028               bestCost = mergeCost;
    2029               m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);             
    2030               for ( compIdx=0;compIdx<3;compIdx++)
    2031               {
    2032                 mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp;
    2033                 mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp;
    2034                 if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1]))
    2035                 {
    2036                   copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] );             
    2037                 }
    2038               }
    2039             }
    2040           }
    2041         }
    2042 #if SAO_ENCODING_CHOICE
    2043 #if SAO_ENCODING_CHOICE_CHROMA
    2044 if( saoParam->saoLcuParam[0][addr].typeIdx == -1)
    2045 {
    2046   numNoSao[0]++;
    2047 }
    2048 if( saoParam->saoLcuParam[1][addr].typeIdx == -1)
    2049 {
    2050   numNoSao[1]+=2;
    2051 }
    2052 #else
    2053         for ( compIdx=0;compIdx<3;compIdx++)
    2054         {
    2055           if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1)
    2056           {
    2057             numNoSao++;
    2058           }
    2059         }
    2060 #endif
    2061 #endif
    2062         m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    2063         m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    2064       }
    2065     }
    2066   }
    2067 #if SAO_ENCODING_CHOICE
    2068 #if SAO_ENCODING_CHOICE_CHROMA
    2069   if( !saoParam->bSaoFlag[0])
    2070   {
    2071     m_depthSaoRate[0][depth] = 1.0;
    2072   }
    2073   else
    2074   {
    2075     m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU);
    2076   }
    2077   if( !saoParam->bSaoFlag[1])
    2078   {
    2079     m_depthSaoRate[1][depth] = 1.0;
    2080   }
    2081   else
    2082   {
    2083     m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2);
    2084   }
    2085 #else
    2086   if( depth == 0)
    2087   {
    2088     // update SAO Rate
    2089     m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3);
    2090   }
    2091 #endif
    2092 #endif
    2093 
    2094 }
    2095 /** rate distortion optimization of SAO unit
    2096  * \param saoParam SAO parameters
    2097  * \param addr address
    2098  * \param addrUp above address
    2099  * \param addrLeft left address
    2100  * \param yCbCr color component index
    2101  * \param lambda
    2102  */
    2103 inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo)
    2104 {
    2105   Int64 estDist = 0;
    2106   Int classIdx;
    2107   Int bitDepth = (compIdx==0) ? g_bitDepthY : g_bitDepthC;
    2108   Int saoBitIncrease = (compIdx==0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC;
    2109   Int saoOffsetTh = (compIdx==0) ? m_iOffsetThY : m_iOffsetThC;
    2110 
    2111   for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ?  m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++)
    2112   {
    2113     if( typeIdx == SAO_BO)
    2114     {
    2115       currentDistortionTableBo[classIdx-1] = 0;
    2116       currentRdCostTableBo[classIdx-1] = lambda;
    2117     }
    2118     if(m_iCount [compIdx][typeIdx][classIdx])
    2119     {
    2120       m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi(bitDepth, (Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<(bitDepth-8)) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<saoBitIncrease));
    2121       m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-saoOffsetTh+1, saoOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]);
    2122       if (typeIdx < 4)
    2123       {
    2124         if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 )
    2125         {
    2126           m_iOffset[compIdx][typeIdx][classIdx] = 0;
    2127         }
    2128         if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3)
    2129         {
    2130           m_iOffset[compIdx][typeIdx][classIdx] = 0;
    2131         }
    2132       }
    2133       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 );
    2134     }
    2135     else
    2136     {
    2137       m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0;
    2138       m_iOffset[compIdx][typeIdx][classIdx] = 0;
    2139     }
    2140     if( typeIdx != SAO_BO )
    2141     {
    2142       estDist   += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << saoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift);
    2143     }
    2144 
    2145   }
    2146   return estDist;
    2147 }
    2148 
    2149 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift)
    2150 {
    2151   return (( count*offset*offset-offsetOrg*offset*2 ) >> shift);
    2152 }
    2153 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 )
    2154 {
    2155   //Clean up, best_q_offset.
    2156   Int64 iterOffset, tempOffset;
     364    // decide slice-level on/off based on previous results
     365    if( (picTempLayer > 0)
     366      && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )
     367    {
     368      sliceEnabled[compIdx] = false;
     369    }
     370#else
     371    // decide slice-level on/off based on previous results
     372    if( (picTempLayer > 0)
     373      && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) )
     374    {
     375      sliceEnabled[compIdx] = false;
     376    }
     377#endif
     378#endif
     379  }
     380}
     381
     382Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData)
     383{
     384  Int64 dist=0;
     385  Int inputBitDepth    = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ;
     386  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8);
     387
     388  switch(typeIdc)
     389  {
     390    case SAO_TYPE_EO_0:
     391    case SAO_TYPE_EO_90:
     392    case SAO_TYPE_EO_135:
     393    case SAO_TYPE_EO_45:
     394      {
     395        for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++)
     396        {
     397          dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift);
     398        }       
     399      }
     400      break;
     401    case SAO_TYPE_BO:
     402      {
     403        for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++)
     404        {
     405          Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ;
     406          dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift);
     407        }
     408      }
     409      break;
     410    default:
     411      {
     412        printf("Not a supported type");
     413        assert(0);
     414        exit(-1);
     415      }
     416  }
     417
     418  return dist;
     419}
     420
     421inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift)
     422{
     423  return (( count*offset*offset-diffSum*offset*2 ) >> shift);
     424}
     425
     426
     427inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh )
     428{
     429  Int iterOffset, tempOffset;
    2157430  Int64 tempDist, tempRate;
    2158431  Double tempCost, tempMinCost;
    2159   Int64 offsetOutput = 0;
     432  Int offsetOutput = 0;
    2160433  iterOffset = offsetInput;
    2161434  // 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.
     
    2163436  while (iterOffset != 0)
    2164437  {
    2165     // Calculate the bits required for signalling the offset
    2166     tempRate = (typeIdx == SAO_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
    2167     if (abs((Int)iterOffset)==offsetTh-1)
     438    // Calculate the bits required for signaling the offset
     439    tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     440    if (abs((Int)iterOffset)==offsetTh) //inclusive
    2168441    { 
    2169442      tempRate --;
    2170443    }
    2171     // Do the dequntization before distorion calculation
     444    // Do the dequantization before distortion calculation
    2172445    tempOffset  = iterOffset << bitIncrease;
    2173     tempDist    = estSaoDist( count, tempOffset, offsetOrg, shift);
     446    tempDist    = estSaoDist( count, tempOffset, diffSum, shift);
    2174447    tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
    2175448    if(tempCost < tempMinCost)
     
    2177450      tempMinCost = tempCost;
    2178451      offsetOutput = iterOffset;
    2179       if(typeIdx == SAO_BO)
    2180       {
    2181         currentDistortionTableBo[classIdx-1] = (Int) tempDist;
    2182         currentRdCostTableBo[classIdx-1] = tempCost;
    2183       }
     452      bestDist = tempDist;
     453      bestCost = tempCost;
    2184454    }
    2185455    iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
     
    2189459
    2190460
    2191 Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion)
    2192 {
    2193   Int typeIdx;
    2194 
    2195   Int64 estDist;
    2196   Int classIdx;
    2197   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(((yCbCr==0)?g_bitDepthY:g_bitDepthC)-8);
    2198   Int64 bestDist;
    2199 
    2200   SaoLcuParam*  saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]);
    2201   SaoLcuParam*  saoLcuParamNeighbor = NULL;
    2202 
    2203   resetSaoUnit(saoLcuParam);
    2204   resetSaoUnit(&compSaoParam[0]);
    2205   resetSaoUnit(&compSaoParam[1]);
    2206 
    2207 
    2208   Double dCostPartBest = MAX_DOUBLE;
    2209 
    2210   Double  bestRDCostTableBo = MAX_DOUBLE;
    2211   Int     bestClassTableBo    = 0;
    2212   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    2213   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    2214 
    2215 
    2216   SaoLcuParam   saoLcuParamRdo;   
    2217   Double   estRate = 0;
    2218 
    2219   resetSaoUnit(&saoLcuParamRdo);
    2220 
    2221   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     461Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo)
     462{
     463  Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC;
     464  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
     465  Int offsetTh = g_saoMaxOffsetQVal[compIdx];  //inclusive
     466
     467  ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     468
     469  //derive initial offsets
     470  Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES);
     471  for(Int classIdx=0; classIdx< numClasses; classIdx++)
     472  {
     473    if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN)  )
     474    {
     475      continue; //offset will be zero
     476    }
     477
     478    if(statData.count[classIdx] == 0)
     479    {
     480      continue; //offset will be zero
     481    }
     482
     483    quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8))
     484                                                                  /
     485                                                          (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx])
     486                                               );
     487    quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]);
     488  }
     489
     490  // adjust offsets
     491  switch(typeIdc)
     492  {
     493    case SAO_TYPE_EO_0:
     494    case SAO_TYPE_EO_90:
     495    case SAO_TYPE_EO_135:
     496    case SAO_TYPE_EO_45:
     497      {
     498        Int64 classDist;
     499        Double classCost;
     500        for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 
     501        {         
     502          if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     503          if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     504          if(classIdx==SAO_CLASS_EO_HALF_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     505          if(classIdx==SAO_CLASS_EO_FULL_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     506
     507          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     508          {
     509            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );
     510          }
     511        }
     512     
     513        typeAuxInfo =0;
     514      }
     515      break;
     516    case SAO_TYPE_BO:
     517      {
     518        Int64  distBOClasses[NUM_SAO_BO_CLASSES];
     519        Double costBOClasses[NUM_SAO_BO_CLASSES];
     520        ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES);
     521        for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++)
     522        {         
     523          costBOClasses[classIdx]= m_lambda[compIdx];
     524          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     525          {
     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 );
     527          }
     528        }
     529
     530        //decide the starting band index
     531        Double minCost = MAX_DOUBLE, cost;
     532        for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++)
     533        {
     534          cost  = costBOClasses[band  ];
     535          cost += costBOClasses[band+1];
     536          cost += costBOClasses[band+2];
     537          cost += costBOClasses[band+3];
     538
     539          if(cost < minCost)
     540          {
     541            minCost = cost;
     542            typeAuxInfo = band;
     543          }
     544        }
     545        //clear those unused classes
     546        Int clearQuantOffset[NUM_SAO_BO_CLASSES];
     547        ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES);
     548        for(Int i=0; i< 4; i++)
     549        {
     550          Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES;
     551          clearQuantOffset[band] = quantOffsets[band];
     552        }
     553        ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES);       
     554      }
     555      break;
     556    default:
     557      {
     558        printf("Not a supported type");
     559        assert(0);
     560        exit(-1);
     561      }
     562
     563  }
     564
     565
     566}
     567
     568
     569Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     570{
     571  Double minCost, cost;
     572  Int rate;
     573  UInt previousWrittenBits;
     574  Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS];
     575  SAOOffset testOffset[NUM_SAO_COMPONENTS];
     576  Int compIdx;
     577  Int invQuantOffset[MAX_NUM_SAO_CLASSES];
     578
     579  modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0;
     580
     581  //pre-encode merge flags
     582  modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     583  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     584  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);
     585  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     586
     587  //------ luma --------//
     588  compIdx = SAO_Y;
     589  //"off" case as initial cost
     590  modeParam[compIdx].modeIdc = SAO_MODE_OFF;
    2222591  m_pcRDGoOnSbacCoder->resetBits();
    2223  m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
    2224  
    2225   dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
    2226   copySaoUnit(saoLcuParam, &saoLcuParamRdo );
    2227   bestDist = 0;
    2228  
    2229 
    2230 
    2231   for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
    2232   {
    2233     estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    2234 
    2235     if( typeIdx == SAO_BO )
    2236     {
    2237       // Estimate Best Position
    2238       Double currentRDCost = 0.0;
    2239 
    2240       for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    2241       {
    2242         currentRDCost = 0.0;
    2243         for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
    2244         {
    2245           currentRDCost += currentRdCostTableBo[uj];
    2246         }
    2247 
    2248         if( currentRDCost < bestRDCostTableBo)
    2249         {
    2250           bestRDCostTableBo = currentRDCost;
    2251           bestClassTableBo  = i;
    2252         }
    2253       }
    2254 
    2255       // Re code all Offsets
    2256       // Code Center
    2257       estDist = 0;
    2258       for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++)
    2259       {
    2260         estDist += currentDistortionTableBo[classIdx];
    2261       }
    2262     }
    2263     resetSaoUnit(&saoLcuParamRdo);
    2264     saoLcuParamRdo.length = m_iNumClass[typeIdx];
    2265     saoLcuParamRdo.typeIdx = typeIdx;
    2266     saoLcuParamRdo.mergeLeftFlag = 0;
    2267     saoLcuParamRdo.mergeUpFlag   = 0;
    2268     saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0;
    2269     for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++)
    2270     {
    2271       saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1];
    2272     }
    2273     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     592  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
     593  modeDist[compIdx] = 0;
     594  minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits());
     595  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     596  if(sliceEnabled[compIdx])
     597  {
     598    for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     599    {
     600      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     601      testOffset[compIdx].typeIdc = typeIdc;
     602
     603      //derive coded offset
     604      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     605
     606      //inversed quantized offsets
     607      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     608
     609      //get distortion
     610      dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     611
     612      //get rate
     613      m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     614      m_pcRDGoOnSbacCoder->resetBits();
     615      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     616      rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     617      cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate);
     618      if(cost < minCost)
     619      {
     620        minCost = cost;
     621        modeDist[compIdx] = dist[compIdx];
     622        modeParam[compIdx]= testOffset[compIdx];
     623        m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     624      }
     625    }
     626  }
     627  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     628  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     629
     630  //------ chroma --------//
     631  //"off" case as initial cost
     632  cost = 0;
     633  previousWrittenBits = 0;
     634  m_pcRDGoOnSbacCoder->resetBits();
     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;
     648
     649  //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function
     650
     651  for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     652  {
     653    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
    2274654    m_pcRDGoOnSbacCoder->resetBits();
    2275     m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr);
    2276 
    2277     estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    2278     m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate);
    2279 
    2280     if(m_dCost[yCbCr][typeIdx] < dCostPartBest)
    2281     {
    2282       dCostPartBest = m_dCost[yCbCr][typeIdx];
    2283       copySaoUnit(saoLcuParam, &saoLcuParamRdo );
    2284       bestDist = estDist;       
    2285     }
    2286   }
    2287   compDistortion[0] += ((Double)bestDist/lambda);
    2288   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    2289  m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr);
    2290   m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    2291 
    2292 
    2293   // merge left or merge up
    2294 
    2295   for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
    2296   {
    2297     saoLcuParamNeighbor = NULL;
    2298     if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
    2299     {
    2300       saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]);
    2301     }
    2302     else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
    2303     {
    2304       saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]);
    2305     }
    2306     if (saoLcuParamNeighbor!=NULL)
    2307     {
    2308       estDist = 0;
    2309       typeIdx = saoLcuParamNeighbor->typeIdx;
    2310       if (typeIdx>=0)
    2311       {
    2312         Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0;
    2313         Int   merge_iOffset;
    2314         for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
    2315         {
    2316           merge_iOffset = saoLcuParamNeighbor->offset[classIdx];
    2317           estDist   += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1],  shift);
    2318         }
    2319       }
    2320       else
    2321       {
    2322         estDist = 0;
    2323       }
    2324 
    2325       copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor );
    2326       compSaoParam[idxNeighbor].mergeUpFlag   = idxNeighbor;
    2327       compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor;
    2328 
    2329       compDistortion[idxNeighbor+1] += ((Double)estDist/lambda);
    2330     }
    2331   }
    2332 }
    2333 Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion)
    2334 {
    2335   Int typeIdx;
    2336 
    2337   Int64 estDist[2];
    2338   Int classIdx;
    2339   Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8);
    2340   Int64 bestDist = 0;
    2341 
    2342   SaoLcuParam*  saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])};
    2343   SaoLcuParam*  saoLcuParamNeighbor[2] = {NULL, NULL};
    2344   SaoLcuParam*  saoMergeParam[2][2];
    2345   saoMergeParam[0][0] = &crSaoParam[0];
    2346   saoMergeParam[0][1] = &crSaoParam[1];
    2347   saoMergeParam[1][0] = &cbSaoParam[0];
    2348   saoMergeParam[1][1] = &cbSaoParam[1];
    2349 
    2350   resetSaoUnit(saoLcuParam[0]);
    2351   resetSaoUnit(saoLcuParam[1]);
    2352   resetSaoUnit(saoMergeParam[0][0]);
    2353   resetSaoUnit(saoMergeParam[0][1]);
    2354   resetSaoUnit(saoMergeParam[1][0]);
    2355   resetSaoUnit(saoMergeParam[1][1]);
    2356 
    2357 
    2358   Double costPartBest = MAX_DOUBLE;
    2359 
    2360   Double  bestRDCostTableBo;
    2361   Int     bestClassTableBo[2]    = {0, 0};
    2362   Int     currentDistortionTableBo[MAX_NUM_SAO_CLASS];
    2363   Double  currentRdCostTableBo[MAX_NUM_SAO_CLASS];
    2364 
    2365   SaoLcuParam   saoLcuParamRdo[2];   
    2366   Double   estRate = 0;
    2367 
    2368   resetSaoUnit(&saoLcuParamRdo[0]);
    2369   resetSaoUnit(&saoLcuParamRdo[1]);
    2370 
    2371   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
     655    previousWrittenBits = 0;
     656    cost = 0;
     657
     658    for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     659    {
     660      if(!sliceEnabled[compIdx])
     661      {
     662        testOffset[compIdx].modeIdc = SAO_MODE_OFF;
     663        dist[compIdx]= 0;
     664        continue;
     665      }
     666      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     667      testOffset[compIdx].typeIdc = typeIdc;
     668
     669      //derive offset & get distortion
     670      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     671      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     672      dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     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
     681    if(cost < minCost)
     682    {
     683      minCost = cost;
     684      for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     685      {
     686        modeDist [compIdx] = dist      [compIdx];
     687        modeParam[compIdx] = testOffset[compIdx];
     688      }
     689    }
     690  }
     691
     692
     693  //----- re-gen rate & normalized cost----//
     694  modeNormCost = 0;
     695  for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++)
     696  {
     697    modeNormCost += (Double)modeDist[component] / m_lambda[component];
     698  }
     699  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
    2372700  m_pcRDGoOnSbacCoder->resetBits();
    2373   m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1);
    2374   m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2);
    2375  
    2376   costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ;
    2377   copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
    2378   copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
    2379 
    2380   for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++)
    2381   {
    2382     if( typeIdx == SAO_BO )
    2383     {
    2384       // Estimate Best Position
    2385       for(Int compIdx = 0; compIdx < 2; compIdx++)
    2386       {
    2387         Double currentRDCost = 0.0;
    2388         bestRDCostTableBo = MAX_DOUBLE;
    2389         estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    2390         for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++)
    2391         {
    2392           currentRDCost = 0.0;
    2393           for(UInt uj = i; uj < i+SAO_BO_LEN; uj++)
     701  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     702  modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     703
     704}
     705
     706Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     707{
     708  Int mergeListSize = (Int)mergeList.size();
     709  modeNormCost = MAX_DOUBLE;
     710
     711  Double cost;
     712  SAOBlkParam testBlkParam;
     713
     714  for(Int mergeType=0; mergeType< mergeListSize; mergeType++)
     715  {
     716    if(mergeList[mergeType] == NULL)
     717    {
     718      continue;
     719    }
     720
     721    testBlkParam = *(mergeList[mergeType]);
     722    //normalized distortion
     723    Double normDist=0;
     724    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     725    {
     726      testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE;
     727      testBlkParam[compIdx].typeIdc = mergeType;
     728
     729      SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx];
     730
     731      if( mergedOffsetParam.modeIdc != SAO_MODE_OFF)
     732      {
     733        //offsets have been reconstructed. Don't call inversed quantization function.
     734        normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))
     735                       /m_lambda[compIdx]
     736                    );
     737      }
     738
     739    }
     740
     741    //rate
     742    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     743    m_pcRDGoOnSbacCoder->resetBits();
     744    m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     745    Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     746
     747    cost = normDist+(Double)rate;
     748
     749    if(cost < modeNormCost)
     750    {
     751      modeNormCost = cost;
     752      modeParam    = testBlkParam;
     753      m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     754    }
     755  }
     756
     757  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     758
     759
     760}
     761
     762Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams)
     763{
     764  Bool isAllBlksDisabled = false;
     765  if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr])
     766  {
     767    isAllBlksDisabled = true;
     768  }
     769
     770  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]);
     771
     772  SAOBlkParam modeParam;
     773  Double minCost, modeCost;
     774
     775  for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     776  {
     777    if(isAllBlksDisabled)
     778    {
     779      codedParams[ctu].reset();
     780      continue;
     781    }
     782
     783    m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]);
     784
     785    //get merge list
     786    std::vector<SAOBlkParam*> mergeList;
     787    getMergeList(pic, ctu, reconParams, mergeList);
     788
     789    minCost = MAX_DOUBLE;
     790    for(Int mode=0; mode < NUM_SAO_MODES; mode++)
     791    {
     792      switch(mode)
     793      {
     794      case SAO_MODE_OFF:
     795        {
     796          continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case.
     797        }
     798        break;
     799      case SAO_MODE_NEW:
     800        {
     801          deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     802
     803        }
     804        break;
     805      case SAO_MODE_MERGE:
     806        {
     807          deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     808        }
     809        break;
     810      default:
     811        {
     812          printf("Not a supported SAO mode\n");
     813          assert(0);
     814          exit(-1);
     815        }
     816      }
     817
     818      if(modeCost < minCost)
     819      {
     820        minCost = modeCost;
     821        codedParams[ctu] = modeParam;
     822        m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     823
     824      }
     825    } //mode
     826    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     827
     828    //apply reconstructed offsets
     829    reconParams[ctu] = codedParams[ctu];
     830    reconstructBlkSAOParam(reconParams[ctu], mergeList);
     831    offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic);
     832  } //ctu
     833
     834#if SAO_ENCODING_CHOICE
     835  Int picTempLayer = pic->getSlice(0)->getDepth();
     836  Int numLcusForSAOOff[NUM_SAO_COMPONENTS];
     837  numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0;
     838
     839  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     840  {
     841    for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     842    {
     843      if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF)
     844      {
     845        numLcusForSAOOff[compIdx]++;
     846      }
     847    }
     848  }
     849#if SAO_ENCODING_CHOICE_CHROMA
     850  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     851  {
     852    m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic;
     853  }
     854#else
     855  if (picTempLayer == 0)
     856  {
     857    m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);
     858  }
     859#endif                                             
     860#endif
     861}
     862
     863
     864Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 
     865                        , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height
     866                        , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     867#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     868                        , Bool isCalculatePreDeblockSamples
     869#endif
     870                        )
     871{
     872  if(m_lineBufWidth != m_maxCUWidth)
     873  {
     874    m_lineBufWidth = m_maxCUWidth;
     875
     876    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     877    m_signLineBuf1 = new Char[m_lineBufWidth+1];
     878
     879    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     880    m_signLineBuf2 = new Char[m_lineBufWidth+1];
     881  }
     882
     883  Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX;
     884  Char signLeft, signRight, signDown;
     885  Int64 *diff, *count;
     886  Pel *srcLine, *orgLine;
     887  Int* skipLinesR = m_skipLinesR[compIdx];
     888  Int* skipLinesB = m_skipLinesB[compIdx];
     889
     890  for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++)
     891  {
     892    SAOStatData& statsData= statsDataTypes[typeIdx];
     893    statsData.reset();
     894
     895    srcLine = srcBlk;
     896    orgLine = orgBlk;
     897    diff    = statsData.diff;
     898    count   = statsData.count;
     899    switch(typeIdx)
     900    {
     901    case SAO_TYPE_EO_0:
     902      {
     903        diff +=2;
     904        count+=2;
     905        endY   = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height;
     906#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     907        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     908                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     909                                                 ;
     910#else
     911        startX = isLeftAvail ? 0 : 1;
     912#endif
     913#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     914        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     915                                                 : (isRightAvail ? width : (width - 1))
     916                                                 ;
     917#else
     918        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     919#endif
     920        for (y=0; y<endY; y++)
     921        {
     922          signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     923          for (x=startX; x<endX; x++)
    2394924          {
    2395             currentRDCost += currentRdCostTableBo[uj];
     925            signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     926            edgeType  =  signRight + signLeft;
     927            signLeft  = -signRight;
     928
     929            diff [edgeType] += (orgLine[x] - srcLine[x]);
     930            count[edgeType] ++;
    2396931          }
    2397 
    2398           if( currentRDCost < bestRDCostTableBo)
     932          srcLine  += srcStride;
     933          orgLine  += orgStride;
     934        }
     935#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     936        if(isCalculatePreDeblockSamples)
     937        {
     938          if(isBelowAvail)
    2399939          {
    2400             bestRDCostTableBo = currentRDCost;
    2401             bestClassTableBo[compIdx]  = i;
     940            startX = isLeftAvail  ? 0 : 1;
     941            endX   = isRightAvail ? width : (width -1);
     942
     943            for(y=0; y<skipLinesB[typeIdx]; y++)
     944            {
     945              signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     946              for (x=startX; x<endX; x++)
     947              {
     948                signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     949                edgeType  =  signRight + signLeft;
     950                signLeft  = -signRight;
     951
     952                diff [edgeType] += (orgLine[x] - srcLine[x]);
     953                count[edgeType] ++;
     954              }
     955              srcLine  += srcStride;
     956              orgLine  += orgStride;
     957            }
    2402958          }
    2403959        }
    2404 
    2405         // Re code all Offsets
    2406         // Code Center
    2407         estDist[compIdx] = 0;
    2408         for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++)
    2409         {
    2410           estDist[compIdx] += currentDistortionTableBo[classIdx];
    2411         }
    2412       }
    2413     }
    2414     else
    2415     {
    2416       estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    2417       estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo);
    2418     }
    2419 
    2420     m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    2421     m_pcRDGoOnSbacCoder->resetBits();
    2422 
    2423     for(Int compIdx = 0; compIdx < 2; compIdx++)
    2424     {
    2425       resetSaoUnit(&saoLcuParamRdo[compIdx]);
    2426       saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx];
    2427       saoLcuParamRdo[compIdx].typeIdx = typeIdx;
    2428       saoLcuParamRdo[compIdx].mergeLeftFlag = 0;
    2429       saoLcuParamRdo[compIdx].mergeUpFlag   = 0;
    2430       saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0;
    2431       for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++)
    2432       {
    2433         saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1];
    2434       }
    2435 
    2436       m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1);
    2437     }
    2438     estRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    2439     m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1])  + lambda * (Double) estRate);
    2440    
    2441     if(m_dCost[1][typeIdx] < costPartBest)
    2442     {
    2443       costPartBest = m_dCost[1][typeIdx];
    2444       copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] );
    2445       copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] );
    2446       bestDist = (estDist[0]+estDist[1]);       
    2447     }
    2448   }
    2449 
    2450   distortion[0] += ((Double)bestDist/lambda);
    2451   m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]);
    2452   m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1);
    2453   m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2);
    2454   m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] );
    2455 
    2456   // merge left or merge up
    2457 
    2458   for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++)
    2459   {
    2460     for(Int compIdx = 0; compIdx < 2; compIdx++)
    2461     {
    2462       saoLcuParamNeighbor[compIdx] = NULL;
    2463       if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0)
    2464       {
    2465         saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]);
    2466       }
    2467       else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1)
    2468       {
    2469         saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]);
    2470       }
    2471       if (saoLcuParamNeighbor[compIdx]!=NULL)
    2472       {
    2473         estDist[compIdx] = 0;
    2474         typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx;
    2475         if (typeIdx>=0)
    2476         {
    2477           Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0;
    2478           Int   merge_iOffset;
    2479           for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++)
     960#endif
     961      }
     962      break;
     963    case SAO_TYPE_EO_90:
     964      {
     965        diff +=2;
     966        count+=2;
     967        Char *signUpLine = m_signLineBuf1;
     968
     969#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     970        startX = (!isCalculatePreDeblockSamples) ? 0
     971                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     972                                                 ;
     973#endif
     974        startY = isAboveAvail ? 0 : 1;
     975#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     976        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     977                                                 : width
     978                                                 ;
     979#else
     980        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : width ;
     981#endif
     982        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     983        if (!isAboveAvail)
     984        {
     985          srcLine += srcStride;
     986          orgLine += orgStride;
     987        }
     988
     989        Pel* srcLineAbove = srcLine - srcStride;
     990#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     991        for (x=startX; x<endX; x++)
     992#else
     993        for (x=0; x< endX; x++)
     994#endif
     995        {
     996          signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
     997        }
     998
     999        Pel* srcLineBelow;
     1000        for (y=startY; y<endY; y++)
     1001        {
     1002          srcLineBelow = srcLine + srcStride;
     1003
     1004#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1005          for (x=startX; x<endX; x++)
     1006#else
     1007          for (x=0; x<endX; x++)
     1008#endif
    24801009          {
    2481             merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx];
    2482             estDist[compIdx]   += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1],  shift);
     1010            signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
     1011            edgeType  = signDown + signUpLine[x];
     1012            signUpLine[x]= -signDown;
     1013
     1014            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1015            count[edgeType] ++;
    24831016          }
    2484         }
    2485         else
    2486         {
    2487           estDist[compIdx] = 0;
    2488         }
    2489 
    2490         copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] );
    2491         saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag   = idxNeighbor;
    2492         saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor;
    2493         distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda);
    2494       }
    2495     }
    2496   }
     1017          srcLine += srcStride;
     1018          orgLine += orgStride;
     1019        }
     1020#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1021        if(isCalculatePreDeblockSamples)
     1022        {
     1023          if(isBelowAvail)
     1024          {
     1025            startX = 0;
     1026            endX   = width;
     1027
     1028            for(y=0; y<skipLinesB[typeIdx]; y++)
     1029            {
     1030              srcLineBelow = srcLine + srcStride;
     1031              srcLineAbove = srcLine - srcStride;
     1032
     1033              for (x=startX; x<endX; x++)
     1034              {
     1035                edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
     1036                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1037                count[edgeType] ++;
     1038              }
     1039              srcLine  += srcStride;
     1040              orgLine  += orgStride;
     1041            }
     1042          }
     1043        }
     1044#endif
     1045
     1046      }
     1047      break;
     1048    case SAO_TYPE_EO_135:
     1049      {
     1050        diff +=2;
     1051        count+=2;
     1052        Char *signUpLine, *signDownLine, *signTmpLine;
     1053
     1054        signUpLine  = m_signLineBuf1;
     1055        signDownLine= m_signLineBuf2;
     1056
     1057#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1058        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1059                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1060                                                 ;
     1061#else
     1062        startX = isLeftAvail ? 0 : 1 ;
     1063#endif
     1064
     1065#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1066        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1))
     1067                                                 : (isRightAvail ? width : (width - 1))
     1068                                                 ;
     1069#else
     1070        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     1071#endif
     1072        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1073
     1074        //prepare 2nd line's upper sign
     1075        Pel* srcLineBelow = srcLine + srcStride;
     1076        for (x=startX; x<endX+1; x++)
     1077        {
     1078          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
     1079        }
     1080
     1081        //1st line
     1082        Pel* srcLineAbove = srcLine - srcStride;
     1083#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1084        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0    : 1) : startX;
     1085        firstLineEndX   = (!isCalculatePreDeblockSamples) ? (isAboveAvail     ? endX : 1) : endX;
     1086#else
     1087        firstLineStartX = isAboveLeftAvail ? 0    : 1;
     1088        firstLineEndX   = isAboveAvail     ? endX : 1;
     1089#endif
     1090        for(x=firstLineStartX; x<firstLineEndX; x++)
     1091        {
     1092          edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
     1093          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1094          count[edgeType] ++;
     1095        }
     1096        srcLine  += srcStride;
     1097        orgLine  += orgStride;
     1098
     1099
     1100        //middle lines
     1101        for (y=1; y<endY; y++)
     1102        {
     1103          srcLineBelow = srcLine + srcStride;
     1104
     1105          for (x=startX; x<endX; x++)
     1106          {
     1107            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
     1108            edgeType = signDown + signUpLine[x];
     1109            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1110            count[edgeType] ++;
     1111
     1112            signDownLine[x+1] = -signDown;
     1113          }
     1114          signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
     1115
     1116          signTmpLine  = signUpLine;
     1117          signUpLine   = signDownLine;
     1118          signDownLine = signTmpLine;
     1119
     1120          srcLine += srcStride;
     1121          orgLine += orgStride;
     1122        }
     1123#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1124        if(isCalculatePreDeblockSamples)
     1125        {
     1126          if(isBelowAvail)
     1127          {
     1128            startX = isLeftAvail  ? 0     : 1 ;
     1129            endX   = isRightAvail ? width : (width -1);
     1130
     1131            for(y=0; y<skipLinesB[typeIdx]; y++)
     1132            {
     1133              srcLineBelow = srcLine + srcStride;
     1134              srcLineAbove = srcLine - srcStride;
     1135
     1136              for (x=startX; x< endX; x++)
     1137              {
     1138                edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
     1139                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1140                count[edgeType] ++;
     1141              }
     1142              srcLine  += srcStride;
     1143              orgLine  += orgStride;
     1144            }
     1145          }
     1146        }
     1147#endif
     1148      }
     1149      break;
     1150    case SAO_TYPE_EO_45:
     1151      {
     1152        diff +=2;
     1153        count+=2;
     1154        Char *signUpLine = m_signLineBuf1+1;
     1155
     1156#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1157        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1158                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1159                                                 ;
     1160#else
     1161        startX = isLeftAvail ? 0 : 1;
     1162#endif
     1163#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1164        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1165                                                 : (isRightAvail ? width : (width - 1))
     1166                                                 ;
     1167#else
     1168        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1);
     1169#endif
     1170        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1171
     1172        //prepare 2nd line upper sign
     1173        Pel* srcLineBelow = srcLine + srcStride;
     1174        for (x=startX-1; x<endX; x++)
     1175        {
     1176          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
     1177        }
     1178
     1179
     1180        //first line
     1181        Pel* srcLineAbove = srcLine - srcStride;
     1182#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1183        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX)
     1184                                                          : startX
     1185                                                          ;
     1186        firstLineEndX   = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX)
     1187                                                          : endX
     1188                                                          ;
     1189#else
     1190        firstLineStartX = isAboveAvail ? startX : endX;
     1191        firstLineEndX   = (!isRightAvail && isAboveRightAvail) ? width : endX;
     1192#endif
     1193        for(x=firstLineStartX; x<firstLineEndX; x++)
     1194        {
     1195          edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
     1196          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1197          count[edgeType] ++;
     1198        }
     1199
     1200        srcLine += srcStride;
     1201        orgLine += orgStride;
     1202
     1203        //middle lines
     1204        for (y=1; y<endY; y++)
     1205        {
     1206          srcLineBelow = srcLine + srcStride;
     1207
     1208          for(x=startX; x<endX; x++)
     1209          {
     1210            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
     1211            edgeType = signDown + signUpLine[x];
     1212
     1213            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1214            count[edgeType] ++;
     1215
     1216            signUpLine[x-1] = -signDown;
     1217          }
     1218          signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
     1219          srcLine  += srcStride;
     1220          orgLine  += orgStride;
     1221        }
     1222#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1223        if(isCalculatePreDeblockSamples)
     1224        {
     1225          if(isBelowAvail)
     1226          {
     1227            startX = isLeftAvail  ? 0     : 1 ;
     1228            endX   = isRightAvail ? width : (width -1);
     1229
     1230            for(y=0; y<skipLinesB[typeIdx]; y++)
     1231            {
     1232              srcLineBelow = srcLine + srcStride;
     1233              srcLineAbove = srcLine - srcStride;
     1234
     1235              for (x=startX; x<endX; x++)
     1236              {
     1237                edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
     1238                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1239                count[edgeType] ++;
     1240              }
     1241              srcLine  += srcStride;
     1242              orgLine  += orgStride;
     1243            }
     1244          }
     1245        }
     1246#endif
     1247      }
     1248      break;
     1249    case SAO_TYPE_BO:
     1250      {
     1251#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1252        startX = (!isCalculatePreDeblockSamples)?0
     1253                                                :( isRightAvail?(width- skipLinesR[typeIdx]):width)
     1254                                                ;
     1255        endX   = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width )
     1256                                                :width
     1257                                                ;
     1258#else
     1259        endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width;
     1260#endif
     1261        endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height;
     1262        Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     1263        for (y=0; y< endY; y++)
     1264        {
     1265#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1266          for (x=startX; x< endX; x++)
     1267#else
     1268          for (x=0; x< endX; x++)
     1269#endif
     1270          {
     1271
     1272            Int bandIdx= srcLine[x] >> shiftBits;
     1273            diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1274            count[bandIdx] ++;
     1275          }
     1276          srcLine += srcStride;
     1277          orgLine += orgStride;
     1278        }
     1279#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1280        if(isCalculatePreDeblockSamples)
     1281        {
     1282          if(isBelowAvail)
     1283          {
     1284            startX = 0;
     1285            endX   = width;
     1286
     1287            for(y= 0; y< skipLinesB[typeIdx]; y++)
     1288            {
     1289              for (x=startX; x< endX; x++)
     1290              {
     1291                Int bandIdx= srcLine[x] >> shiftBits;
     1292                diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1293                count[bandIdx] ++;
     1294              }
     1295              srcLine  += srcStride;
     1296              orgLine  += orgStride;
     1297
     1298            }
     1299
     1300          }
     1301        }
     1302#endif
     1303      }
     1304      break;
     1305    default:
     1306      {
     1307        printf("Not a supported SAO types\n");
     1308        assert(0);
     1309        exit(-1);
     1310      }
     1311    }
     1312  }
    24971313}
    24981314
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r608 r872  
    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
     56enum SAOCabacStateLablesRDO //CABAC state labels
     57{
     58  SAO_CABACSTATE_PIC_INIT =0,
     59  SAO_CABACSTATE_BLK_CUR,
     60  SAO_CABACSTATE_BLK_NEXT,
     61  SAO_CABACSTATE_BLK_MID,
     62  SAO_CABACSTATE_BLK_TEMP,
     63  NUM_SAO_CABACSTATE_LABELS
     64};
     65
     66struct SAOStatData //data structure for SAO statistics
     67{
     68  Int64 diff[MAX_NUM_SAO_CLASSES];
     69  Int64 count[MAX_NUM_SAO_CLASSES];
     70
     71  SAOStatData(){}
     72  ~SAOStatData(){}
     73  Void reset()
     74  {
     75    ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     76    ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     77  }
     78  const SAOStatData& operator=(const SAOStatData& src)
     79  {
     80    ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     81    ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     82    return *this;
     83  }
     84#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     85  const SAOStatData& operator+= (const SAOStatData& src)
     86  {
     87    for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++)
     88    {
     89      diff[i] += src.diff[i];
     90      count[i] += src.count[i];
     91    }
     92    return *this;
     93  }
     94#endif
     95};
     96
    5697class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
    5798{
    58 private:
    59   TEncEntropy*      m_pcEntropyCoder;
    60   TEncSbac***       m_pppcRDSbacCoder;              ///< for CABAC
    61   TEncSbac*         m_pcRDGoOnSbacCoder;
    62 #if FAST_BIT_EST
    63   TEncBinCABACCounter*** m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
    64 #else
    65   TEncBinCABAC***   m_pppcBinCoderCABAC;            ///< temporal CABAC state storage for RD computation
    66 #endif
    67  
    68   Int64  ***m_iCount;      //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    69   Int64  ***m_iOffset;     //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    70   Int64  ***m_iOffsetOrg;  //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    71   Int64  ****m_count_PreDblk;      //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    72   Int64  ****m_offsetOrg_PreDblk;  //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];
    73   Int64  **m_iRate;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    74   Int64  **m_iDist;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    75   Double **m_dCost;        //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];
    76   Double *m_dCostPartBest; //[MAX_NUM_SAO_PART];
    77   Int64  *m_iDistOrg;      //[MAX_NUM_SAO_PART];
    78   Int    *m_iTypePartBest; //[MAX_NUM_SAO_PART];
    79   Int     m_iOffsetThY;
    80   Int     m_iOffsetThC;
    81   Bool    m_bUseSBACRD;
    82 #if SAO_ENCODING_CHOICE
    83 #if SAO_ENCODING_CHOICE_CHROMA
    84   Double  m_depthSaoRate[2][4];
    85 #else
    86   Double  m_depth0SaoRate;
    87 #endif
    88 #endif
    89 
    9099public:
    91   TEncSampleAdaptiveOffset         ();
     100  TEncSampleAdaptiveOffset();
    92101  virtual ~TEncSampleAdaptiveOffset();
    93102
    94   Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder);
    95   Void endSaoEnc();
    96   Void resetStats();
    97 #if SAO_CHROMA_LAMBDA
     103  //interface
     104#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     105  Void createEncData(Bool isPreDBFSamplesUsed);
     106#else
     107  Void createEncData();
     108#endif
     109  Void destroyEncData();
     110  Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ;
     111  Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     112#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     113                , Bool isPreDBFSamplesUsed
     114#endif
     115                );
     116public: //methods
     117#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     118  Void getPreDBFStatistics(TComPic* pPic);
     119#endif
     120private: //methods
     121  Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic
     122#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     123                   , Bool isCalculatePreDeblockSamples = false
     124#endif
     125                   );
     126  Void decidePicParams(Bool* sliceEnabled, Int picTempLayer);
     127  Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams);
     128  Void getBlkStats(Int compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     129#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     130                  , Bool isCalculatePreDeblockSamples
     131#endif
     132                  );
     133  Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     134  Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     135  Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData);
     136  Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo);
     137  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift);
     138  inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh );
     139#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     140  Void addPreDBFStatistics(SAOStatData*** blkStats);
     141#endif
     142private: //members
     143  //for RDO
     144  TEncSbac**             m_pppcRDSbacCoder;           
     145  TEncSbac*              m_pcRDGoOnSbacCoder;
     146  TEncBinCABACCounter**  m_pppcBinCoderCABAC;   
     147  Double                 m_lambda[NUM_SAO_COMPONENTS];
     148
     149  //statistics
     150  SAOStatData***         m_statData; //[ctu][comp][classes]
     151#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     152  SAOStatData***         m_preDBFstatData;
     153#endif
    98154#if SAO_ENCODING_CHOICE
    99   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
    100 #else
    101   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
     155  Double                 m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER];
    102156#endif
    103 #else
    104   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);
    105 #endif
    106 
    107   Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr);
    108   Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr);
    109  
    110   Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx);
    111   Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr);
    112   Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr);
    113   Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr);
    114   Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr);
    115   Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic );
    116   Void destroyEncBuffer();
    117   Void createEncBuffer();
    118   Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam,  SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr);
    119   Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir);
    120 #if SAO_ENCODING_CHOICE
    121   Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth);
    122 #else
    123   Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma);
    124 #endif
    125   Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion);
    126   Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion);
    127   inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift);
    128   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 );
    129   inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo);
    130   Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; }
    131   Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
     157  Int                    m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
     158  Int                    m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
    132159};
    133 
    134160//! \}
    135161
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r833 r872  
    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 *
     
    8484, m_cCUAbsSCModel             ( 1,             1,               NUM_ABS_FLAG_CTX              , m_contextModels + m_numContextModels, m_numContextModels)
    8585, m_cMVPIdxSCModel            ( 1,             1,               NUM_MVP_IDX_CTX               , m_contextModels + m_numContextModels, m_numContextModels)
    86 , m_cCUAMPSCModel             ( 1,             1,               NUM_CU_AMP_CTX                , m_contextModels + m_numContextModels, m_numContextModels)
    8786, m_cSaoMergeSCModel          ( 1,             1,               NUM_SAO_MERGE_FLAG_CTX   , m_contextModels + m_numContextModels, m_numContextModels)
    8887, m_cSaoTypeIdxSCModel        ( 1,             1,               NUM_SAO_TYPE_IDX_CTX          , m_contextModels + m_numContextModels, m_numContextModels)
     
    153152#endif
    154153  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    155   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
    156154  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    157155  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
     
    254252#endif
    255253      curCost += m_cCUPartSizeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PART_SIZE );
    256       curCost += m_cCUAMPSCModel.calcCost             ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS );
    257254      curCost += m_cCUPredModeSCModel.calcCost        ( curSliceType, qp, (UChar*)INIT_PRED_MODE );
    258255      curCost += m_cCUIntraPredSCModel.calcCost       ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE );
     
    326323#endif
    327324  m_cCUPartSizeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PART_SIZE );
    328   m_cCUAMPSCModel.initBuffer             ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );
    329325  m_cCUPredModeSCModel.initBuffer        ( eSliceType, iQp, (UChar*)INIT_PRED_MODE );
    330326  m_cCUIntraPredSCModel.initBuffer       ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE );
     
    348344  m_cTransformSkipSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG );
    349345  m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG );
    350 
    351346#if H_3D_DIM
    352347  m_cDepthIntraModeSCModel.initBuffer    ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE );
     
    794789        if (eSize == SIZE_2NxN)
    795790        {
    796           m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 ));
     791          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    797792        }
    798793        else
    799794        {
    800           m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 ));         
     795          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    801796          m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1));
    802797        }
     
    818813        if (eSize == SIZE_Nx2N)
    819814        {
    820           m_pcBinIf->encodeBin(1, m_cCUAMPSCModel.get( 0, 0, 0 ));
     815          m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    821816        }
    822817        else
    823818        {
    824           m_pcBinIf->encodeBin(0, m_cCUAMPSCModel.get( 0, 0, 0 ));
     819          m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 ));
    825820          m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1));
    826821        }
     
    21342129  {
    21352130    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
    2136     m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 );
     2131    m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
    21372132  }
    21382133}
     
    23372332}
    23382333
     2334Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
     2335{
     2336  UInt uiSymbol;
     2337  if(!sliceEnabled)
     2338  {
     2339    assert(ctbParam.modeIdc == SAO_MODE_OFF);
     2340    return;
     2341  }
     2342
     2343  //type
     2344  if(compIdx == SAO_Y || compIdx == SAO_Cb)
     2345  {
     2346    //sao_type_idx_luma or sao_type_idx_chroma
     2347    if(ctbParam.modeIdc == SAO_MODE_OFF)
     2348    {
     2349      uiSymbol =0;
     2350    }
     2351    else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO
     2352    {
     2353      uiSymbol = 1;
     2354    }
     2355    else
     2356    {
     2357      assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO
     2358      uiSymbol = 2;
     2359    }
     2360    codeSaoTypeIdx(uiSymbol);
     2361  }
     2362
     2363  if(ctbParam.modeIdc == SAO_MODE_NEW)
     2364  {
     2365    Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES;
     2366    Int offset[4];
     2367    Int k=0;
     2368    for(Int i=0; i< numClasses; i++)
     2369    {
     2370      if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN)
     2371      {
     2372        continue;
     2373      }
     2374      Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?(  (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES   ):i;
     2375      offset[k] = ctbParam.offset[classIdx];
     2376      k++;
     2377    }
     2378
     2379    for(Int i=0; i< 4; i++)
     2380    {
     2381      codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     2382    }
     2383
     2384
     2385    if(ctbParam.typeIdc == SAO_TYPE_BO)
     2386    {
     2387      for(Int i=0; i< 4; i++)
     2388      {
     2389        if(offset[i] != 0)
     2390        {
     2391          codeSAOSign((offset[i]< 0)?1:0);
     2392        }
     2393      }
     2394
     2395      codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position
     2396    }
     2397    else //EO
     2398    {
     2399      if(compIdx == SAO_Y || compIdx == SAO_Cb)
     2400      {
     2401        assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0);
     2402        codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma
     2403      }
     2404    }
     2405
     2406  }
     2407}
     2408
     2409
     2410Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam
     2411                              , Bool* sliceEnabled
     2412                              , Bool leftMergeAvail
     2413                              , Bool aboveMergeAvail
     2414                              , Bool onlyEstMergeInfo // = false
     2415                              )
     2416{
     2417
     2418  Bool isLeftMerge = false;
     2419  Bool isAboveMerge= false;
     2420
     2421  if(leftMergeAvail)
     2422  {
     2423    isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT));
     2424    codeSaoMerge( isLeftMerge?1:0  ); //sao_merge_left_flag
     2425  }
     2426
     2427  if( aboveMergeAvail && !isLeftMerge)
     2428  {
     2429    isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE));
     2430    codeSaoMerge( isAboveMerge?1:0  ); //sao_merge_left_flag
     2431  }
     2432
     2433  if(onlyEstMergeInfo)
     2434  {
     2435    return; //only for RDO
     2436  }
     2437
     2438  if(!isLeftMerge && !isAboveMerge) //not merge mode
     2439  {
     2440    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     2441    {
     2442      codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);
     2443    }
     2444  }
     2445}
     2446
    23392447#if H_3D_INTER_SDC
    23402448#if QC_SDC_UNIFY_G0130
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r833 r872  
    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 *
     
    111111  Void  codeScalingList      ( TComScalingList* /*scalingList*/     ){ assert (0);  return;};
    112112
     113  Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
     114  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
     115                    , Bool* sliceEnabled
     116                    , Bool leftMergeAvail
     117                    , Bool aboveMergeAvail
     118                    , Bool onlyEstMergeInfo = false
     119                    );
     120
    113121private:
    114122  Void  xWriteUnarySymbol    ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset );
     
    245253  ContextModel3DBuffer m_cMVPIdxSCModel;
    246254 
    247   ContextModel3DBuffer m_cCUAMPSCModel;
    248255  ContextModel3DBuffer m_cSaoMergeSCModel;
    249256  ContextModel3DBuffer m_cSaoTypeIdxSCModel;
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r833 r872  
    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 *
     
    202202  m_pppcRDSbacCoder     = pppcRDSbacCoder;
    203203  m_pcRDGoOnSbacCoder   = pcRDGoOnSbacCoder;
    204  
    205   m_bUseSBACRD          = pppcRDSbacCoder ? true : false;
    206204 
    207205  for (Int iDir = 0; iDir < 2; iDir++)
     
    728726  Pel*  piRefPos;
    729727  Int iRefStride = m_filteredBlock[0][0].getStride();
    730 #if NS_HAD
    731   m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    732 #else
    733728  m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() );
    734 #endif
    735729 
    736730  const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ);
     
    745739    piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr();
    746740    if ( horVal == 2 && ( verVal & 1 ) == 0 )
     741    {
    747742      piRefPos += 1;
     743    }
    748744    if ( ( horVal & 1 ) == 0 && verVal == 2 )
     745    {
    749746      piRefPos += iRefStride;
     747    }
    750748    cMvTest = pcMvRefine[i];
    751749    cMvTest += rcMvFrac;
     
    787785  UInt  uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth;
    788786
    789   {
    790787    if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 )
    791788    {
     
    812809      }
    813810    }
    814   }
    815811 
    816812  if ( bChroma )
     
    819815    {
    820816      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) )
     817      {
    821818        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth );
     819      }
    822820      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) )
     821      {
    823822        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth );
    824823    }
     824  }
    825825  }
    826826
     
    835835  }
    836836 
    837   {
    838837    //===== Cbfs =====
    839838    if( bLuma )
     
    842841    }
    843842  }
    844 }
    845843
    846844Void
     
    12121210  {
    12131211    Int scalingListType = 0 + g_eTTable[(Int)TEXT_LUMA];
    1214     assert(scalingListType < 6);
     1212    assert(scalingListType < SCALING_LIST_NUM);
    12151213    m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip );
    12161214  }
     
    14121410
    14131411#if RDOQ_CHROMA_LAMBDA
    1414     m_pcTrQuant->selectLambda      (TEXT_CHROMA); 
     1412    m_pcTrQuant->selectLambda(eText);
    14151413#endif
    14161414    m_pcTrQuant->transformNxN      ( pcCU, piResi, uiStride, pcCoeff,
     
    14251423    {
    14261424      Int scalingListType = 0 + g_eTTable[(Int)eText];
    1427       assert(scalingListType < 6);
     1425      assert(scalingListType < SCALING_LIST_NUM);
    14281426      m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma );
    14291427    }
     
    14641462 
    14651463  //===== update distortion =====
    1466 #if WEIGHTED_CHROMA_DISTORTION
    14671464  ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText );
    1468 #else
    1469   ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
    1470 #endif
    14711465}
    14721466
     
    15531547  checkTransformSkip         &= (widthTransformSkip == 4 && heightTransformSkip == 4);
    15541548  checkTransformSkip         &= (!pcCU->getCUTransquantBypass(0));
    1555   checkTransformSkip         &= (!((pcCU->getQP( 0 ) == 0) && (pcCU->getSlice()->getSPS()->getUseLossless())));
    15561549  if ( m_pcEncCfg->getUseTransformSkipFast() )
    15571550  {
     
    15631556    {
    15641557      //----- store original entropy coding status -----
    1565       if( m_bUseSBACRD)
    1566       {
    15671558        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1568       }
    15691559#if H_3D_VSO
    15701560      Dist   singleDistYTmp     = 0;
     
    16411631          {
    16421632            xStoreIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly );
    1643             if( m_bUseSBACRD)
    1644             {
    16451633              m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    16461634            }
    16471635          }
    1648         }
    16491636        if(modeId == firstCheckId)
    16501637        {
     
    16671654          }
    16681655        }
    1669         if(m_bUseSBACRD)
    1670         {
    16711656          m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    16721657        }
    1673       }
    16741658
    16751659      if( !bLumaOnly )
     
    16961680      pcCU ->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiFullDepth );
    16971681      //----- store original entropy coding status -----
    1698       if( m_bUseSBACRD && bCheckSplit )
     1682      if( bCheckSplit )
    16991683      {
    17001684        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
     
    17421726  {
    17431727    //----- store full entropy coding status, load original entropy coding status -----
    1744     if( m_bUseSBACRD )
    1745     {
    17461728      if( bCheckFull )
    17471729      {
     
    17531735        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    17541736      }
    1755     }
     1737
    17561738    //----- code splitted block -----
    17571739    Double  dSplitCost      = 0.0;
     
    17981780    }
    17991781    //----- restore context states -----
    1800     if( m_bUseSBACRD )
    1801     {
    18021782      m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] );
    1803     }
     1783
    18041784    //----- determine rate and r-d cost -----
    18051785    UInt uiSplitBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false );
     
    18211801    }
    18221802    //----- set entropy coding status -----
    1823     if( m_bUseSBACRD )
    1824     {
    18251803      m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] );
    1826     }
    18271804   
    18281805    //--- set transform index and Cbf values ---
     
    27182695    {
    27192696        //use RDO to decide whether Cr/Cb takes TS
    2720         if( m_bUseSBACRD )
    2721         {
    27222697          m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
    2723         }
    27242698
    27252699        for(Int chromaId = 0; chromaId < 2; chromaId ++)
     
    27722746              {
    27732747                xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
    2774                 if( m_bUseSBACRD)
    2775                 {
    27762748                  m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    27772749                }
    27782750              }
    2779             }
    27802751            if(chromaModeId == firstCheckId)
    27812752            {
     
    27882759            xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId);
    27892760            pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth );
    2790             if(m_bUseSBACRD)
    2791             {
    27922761              m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] );
    27932762            }
    2794           }
    27952763          pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) +  actualTrDepth );
    27962764          ruiDist += singleDistC;
     
    27982766          if(chromaId == 0)
    27992767          {
    2800             if( m_bUseSBACRD )
    2801             {
    28022768              m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] );
    28032769            }
    28042770          }
    28052771        }
    2806     }
    28072772    else
    28082773    {
     
    32163181      {
    32173182#endif
    3218       // set context models
    3219       if( m_bUseSBACRD )
    3220       {
     3183        // set context models
    32213184        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    3222       }
    3223      
    3224       // determine residual for partition
     3185
     3186        // determine residual for partition
    32253187#if H_3D_VSO
    3226       Dist   uiPUDistY = 0;
     3188        Dist   uiPUDistY = 0;
    32273189#else
    3228       UInt   uiPUDistY = 0;
    3229 #endif
    3230       UInt   uiPUDistC = 0;
    3231       Double dPUCost   = 0.0;
     3190        UInt   uiPUDistY = 0;
     3191#endif
     3192        UInt   uiPUDistC = 0;
     3193        Double dPUCost   = 0.0;
    32323194#if H_3D_VSO // M36
    3233       if( m_pcRdCost->getUseRenModel() )
    3234       {
    3235         m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );
    3236       }
     3195        if( m_pcRdCost->getUseRenModel() )
     3196        {
     3197          m_pcRdCost->setRenModelData( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight );
     3198        }
    32373199#endif
    32383200#if H_3D_DIM_SDC
    3239             if( pcCU->getSDCFlag(uiPartOffset) )
    3240             {
    3241               pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth);
    3242               pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth);
    3243              
    3244               // start encoding with SDC
     3201        if( pcCU->getSDCFlag(uiPartOffset) )
     3202        {
     3203          pcCU->setTrIdxSubParts(0, uiPartOffset, uiDepth + uiInitTrDepth);
     3204          pcCU->setCbfSubParts(1, 1, 1, uiPartOffset, uiDepth + uiInitTrDepth);
     3205
     3206          // start encoding with SDC
    32453207#if QC_GENERIC_SDC_G0122
    3246               xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, ( testZeroResi != 0 ), iSDCDeltaResi );
     3208          xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, ( testZeroResi != 0 ), iSDCDeltaResi );
    32473209#else
    3248               xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0));
    3249 #endif
    3250             }
    3251             else
    3252             {
     3210          xIntraCodingSDC(pcCU, uiPartOffset, pcOrgYuv, pcPredYuv, uiPUDistY, dPUCost, (testZeroResi!=0));
     3211#endif
     3212        }
     3213        else
     3214        {
    32533215#endif
    32543216#if HHI_RQT_INTRA_SPEEDUP
    32553217#if H_3D_DIM_ENC
    3256       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) );
     3218          xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost, (testZeroResi != 0) );
    32573219#else
    3258       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );
     3220          xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, true, dPUCost );
    32593221#endif
    32603222#else
    32613223#if H_3D_DIM_ENC
    3262       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) );
     3224          xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost, (testZeroResi != 0) );
    32633225#else
    3264       xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );
     3226          xRecurIntraCodingQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcOrgYuv, pcPredYuv, pcResiYuv, uiPUDistY, uiPUDistC, dPUCost );
    32653227#endif
    32663228#endif
    32673229#if H_3D_DIM_SDC
    3268             }
    3269 #endif
    3270      
    3271       // check r-d cost
    3272       if( dPUCost < dBestPUCost )
    3273       {
     3230        }
     3231#endif
     3232
     3233        // check r-d cost
     3234        if( dPUCost < dBestPUCost )
     3235        {
    32743236#if HHI_RQT_INTRA_SPEEDUP_MOD
    3275         uiSecondBestMode  = uiBestPUMode;
    3276         dSecondBestPUCost = dBestPUCost;
    3277 #endif
    3278         uiBestPUMode  = uiOrgMode;
    3279         uiBestPUDistY = uiPUDistY;
    3280         uiBestPUDistC = uiPUDistC;
    3281         dBestPUCost   = dPUCost;
    3282        
     3237          uiSecondBestMode  = uiBestPUMode;
     3238          dSecondBestPUCost = dBestPUCost;
     3239#endif
     3240          uiBestPUMode  = uiOrgMode;
     3241          uiBestPUDistY = uiPUDistY;
     3242          uiBestPUDistC = uiPUDistC;
     3243          dBestPUCost   = dPUCost;
     3244
    32833245#if H_3D_DIM_SDC
    3284         if( pcCU->getSDCFlag(uiPartOffset) )
    3285         {
    3286           bBestUseSDC = true;
    3287          
    3288           // copy reconstruction
    3289           pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight);
    3290          
    3291           // copy DC values
    3292           apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset);
    3293           apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset);
    3294         }
    3295         else
    3296         {
    3297           bBestUseSDC = false;
    3298 #endif
    3299         xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );
    3300        
    3301         UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );
    3302         ::memcpy( m_puhQTTempTrIdx,  pcCU->getTransformIdx()       + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3303         ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA     ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3304         ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3305         ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3306         ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3307         ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    3308         ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3246          if( pcCU->getSDCFlag(uiPartOffset) )
     3247          {
     3248            bBestUseSDC = true;
     3249
     3250            // copy reconstruction
     3251            pcPredYuv->copyPartToPartYuv(pcRecoYuv, uiPartOffset, uiWidth, uiHeight);
     3252
     3253            // copy DC values
     3254            apBestDCOffsets[0] = pcCU->getSDCSegmentDCOffset(0, uiPartOffset);
     3255            apBestDCOffsets[1] = pcCU->getSDCSegmentDCOffset(1, uiPartOffset);
     3256          }
     3257          else
     3258          {
     3259            bBestUseSDC = false;
     3260#endif
     3261            xSetIntraResultQT( pcCU, uiInitTrDepth, uiPartOffset, bLumaOnly, pcRecoYuv );
     3262
     3263            UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> ( ( pcCU->getDepth(0) + uiInitTrDepth ) << 1 );
     3264            ::memcpy( m_puhQTTempTrIdx,  pcCU->getTransformIdx()       + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3265            ::memcpy( m_puhQTTempCbf[0], pcCU->getCbf( TEXT_LUMA     ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3266            ::memcpy( m_puhQTTempCbf[1], pcCU->getCbf( TEXT_CHROMA_U ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3267            ::memcpy( m_puhQTTempCbf[2], pcCU->getCbf( TEXT_CHROMA_V ) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3268            ::memcpy( m_puhQTTempTransformSkipFlag[0], pcCU->getTransformSkip(TEXT_LUMA)     + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3269            ::memcpy( m_puhQTTempTransformSkipFlag[1], pcCU->getTransformSkip(TEXT_CHROMA_U) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
     3270            ::memcpy( m_puhQTTempTransformSkipFlag[2], pcCU->getTransformSkip(TEXT_CHROMA_V) + uiPartOffset, uiQPartNum * sizeof( UChar ) );
    33093271#if H_3D_DIM_SDC
    3310         }
    3311 #endif
    3312       }
     3272          }
     3273#endif
     3274        }
    33133275#if HHI_RQT_INTRA_SPEEDUP_MOD
    3314       else if( dPUCost < dSecondBestPUCost )
    3315       {
    3316         uiSecondBestMode  = uiOrgMode;
    3317         dSecondBestPUCost = dPUCost;
    3318       }
     3276        else if( dPUCost < dSecondBestPUCost )
     3277        {
     3278          uiSecondBestMode  = uiOrgMode;
     3279          dSecondBestPUCost = dPUCost;
     3280        }
    33193281#endif
    33203282#if H_3D_DIM_ENC || H_3D_DIM_SDC
     
    33503312     
    33513313      // set context models
    3352       if( m_bUseSBACRD )
    3353       {
    33543314        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    3355       }
    33563315     
    33573316      // determine residual for partition
     
    35213480 
    35223481  //===== reset context models =====
    3523   if(m_bUseSBACRD)
    3524   {
    35253482    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    3526   }
    35273483 
    35283484  //===== set distortion (rate and r-d costs are determined later) =====
     
    35563512  {
    35573513    //----- restore context models -----
    3558     if( m_bUseSBACRD )
    3559     {
    35603514      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    3561     }
    35623515   
    35633516    //----- chroma coding -----
     
    35653518    pcCU->setChromIntraDirSubParts  ( uiModeList[uiMode], 0, uiDepth );
    35663519    xRecurIntraChromaCodingQT       ( pcCU,   0, 0, pcOrgYuv, pcPredYuv, pcResiYuv, uiDist );
    3567     if( m_bUseSBACRD && pcCU->getSlice()->getPPS()->getUseTransformSkip() )
     3520    if( pcCU->getSlice()->getPPS()->getUseTransformSkip() )
    35683521    {
    35693522      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     
    35973550 
    35983551  //----- restore context models -----
    3599   if( m_bUseSBACRD )
    3600   {
    36013552    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    36023553  }
    3603 }
    36043554
    36053555/** Function for encoding and reconstructing luma/chroma samples of a PCM mode CU.
     
    37613711  dCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion );
    37623712
    3763   if(m_bUseSBACRD)
    3764   {
    37653713    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);
    3766   }
    37673714
    37683715  pcCU->getTotalBits()       = uiBits;
     
    37893736                            pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(),
    37903737                            m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(),
    3791 #if NS_HAD
    3792                             iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    3793 #else
    37943738                            iWidth, iHeight, m_pcEncCfg->getUseHADME() );
    3795 #endif
    37963739#if H_3D_IC
    37973740  cDistParam.bUseIC = false;
     
    39423885  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
    39433886  {
    3944     {
    39453887      UInt uiCostCand = MAX_UINT;
    39463888      UInt uiBitsCand = 0;
     
    40043946      }
    40053947      else
    4006 #endif
    4007       {
     3948      {
     3949#endif
    40083950        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    40093951        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], ePartSize, uiAbsPartIdx, 0, iPUIdx );
    4010       }
    4011 
     3952
     3953#if NTT_STORE_SPDV_VSP_G0148
     3954      }
     3955#endif
    40123956#if H_3D_VSP && !NTT_STORE_SPDV_VSP_G0148
    40133957      pcCU->setVSPFlagSubParts( vspFlag[uiMergeCand], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
     
    40443988    }
    40453989  }
    4046 }
    40473990
    40483991/** convert bi-pred merge candidates to uni-pred
     
    41814124
    41824125    UInt          uiCostTempL0[MAX_NUM_REF];
    4183     for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT;
     4126    for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++)
     4127    {
     4128      uiCostTempL0[iNumRef] = MAX_UINT;
     4129    }
    41844130    UInt          uiBitsTempL0[MAX_NUM_REF];
    41854131
     
    45944540    {
    45954541      uiLastMode = 2;
    4596       {
    45974542            pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    45984543            pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    45994544            pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    46004545            pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4601       }
    4602       {
     4546     
    46034547        TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
    46044548            pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4605       }
    4606       {
     4549     
    46074550        TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
    46084551            pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4609       }
    46104552     
    46114553      pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     
    46234565          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
    46244566          pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
    4625       {
    46264567        TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
    46274568            pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4628       }
    46294569      pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    46304570     
     
    46394579          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
    46404580          pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
    4641       {
    46424581        TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
    46434582            pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    4644       }
    46454583      pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    46464584     
     
    47294667        pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    47304668#endif
    4731 
    47324669#if MTK_DDD_G0063
    47334670        if( uiMRGIndex == pcCU->getUseDDDCandIdx() )
     
    47434680        }
    47444681#endif
    4745 
    47464682#if H_3D_SPIVMP
    47474683        pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 
     
    47494685        {
    47504686          UInt uiSPAddr;
    4751 
    47524687          Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight;
    4753 
    47544688          pcCU->getSPPara(iRoiWidth, iRoiHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight);
    4755 
    47564689          for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++)
    47574690          {
     
    47614694            pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight);
    47624695          }
    4763 
    47644696          if ( pcCU->getInterDir(uiPartAddr) == 3 && pcCU->isBipredRestriction(iPartIdx) )
    47654697          {
     
    47684700            pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ));
    47694701          }
    4770 
    47714702        }
    47724703        else
     
    47834714          Int width, height;
    47844715          pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256
    4785 
    47864716          if( uiMRGInterDir & 0x01 )
    47874717          {
     
    48054735        }
    48064736        else
    4807 #endif
    4808         {
     4737#if H_3D_FIX_G0148_BRACE
     4738          {
     4739#endif
     4740#endif
    48094741          pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    4810           {
    48114742            pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    48124743            pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
     4744#if H_3D_FIX_G0148_BRACE
    48134745          }
    4814         }
    4815 
     4746#endif
    48164747        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
    48174748        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
     
    48274758        pcCU->setSPIVMPFlagSubParts(0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    48284759#endif
    4829 
    48304760#if MTK_DDD_G0063
    48314761        pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
     
    48384768        pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    48394769#endif
    4840         {
    48414770          pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    48424771          pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    48434772        }
    4844       }
    48454773#if H_3D_SPIVMP
    48464774      delete[] pcMvFieldSP;
     
    49974925 
    49984926  if (iNum == 1)
     4927  {
    49994928    return 0;
     4929  }
    50004930 
    50014931  UInt uiLength = 1;
     
    51775107                            pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(),
    51785108                            pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(),
    5179 #if NS_HAD
    5180                             iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    5181 #else
    51825109                            iSizeX, iSizeY, m_pcEncCfg->getUseHADME() );
    5183 #endif
    51845110  ruiDist = cDistParam.DistFunc( &cDistParam );
    51855111  uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] );
    51865112#else
    5187 #if WEIGHTED_CHROMA_DISTORTION
    51885113  uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD );
    5189 #else
    5190   uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );
    5191 #endif
    51925114  uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD );
    51935115#endif
     
    52885210  m_pcRdCost->setCostScale ( 1 );
    52895211 
    5290   {
    5291     xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost
    5292                           ,bBi
    5293                           );
    5294   }
     5212    xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi );
    52955213 
    52965214 
     
    56825600    {
    56835601#endif
    5684 #if WEIGHTED_CHROMA_DISTORTION
    56855602    uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    56865603    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    56875604    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    5688 #else
    5689     uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    5690     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    5691     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    5692 #endif
    5693 
    56945605#if H_3D_VSO // MIgnore
    56955606    }
    56965607#endif
    56975608
    5698     if( m_bUseSBACRD )
    56995609      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]);
    57005610   
     
    57295639    pcCU->getTotalCost() = m_pcRdCost->calcRdCost( uiBits, uiDistortion );
    57305640
    5731     if( m_bUseSBACRD )
    57325641      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]);
    57335642   
     
    57715680    uiBits = 0;
    57725681    uiDistortion = 0;
    5773     if( m_bUseSBACRD )
    5774     {
    57755682      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] );
    5776     }   
    57775683
    57785684#if H_3D_VSO // M16 // M18
     
    58365742    }
    58375743   
    5838     if( m_bUseSBACRD )
    5839     {
    58405744      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    5841     }
    58425745#if 0 // check
    58435746    {
     
    58455748      m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) );
    58465749      const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits();
    5847       if( m_bUseSBACRD )
    5848       {
    58495750        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    5850       }
    58515751      if( uiBitsForCoeff != uiBits )
    58525752        assert( 0 );
     
    59045804      dCostBest        = dCost;
    59055805      qpBest           = qp;
    5906       if( m_bUseSBACRD )
    5907       {
    59085806        m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    59095807      }
    5910     }
    59115808#if H_3D_VSO // M21
    59125809    if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     
    59185815#endif
    59195816  }
    5920  
    59215817  assert ( dCostBest != MAX_DOUBLE );
    59225818 
    59235819  if( qpMin != qpMax && qpBest != qpMax )
    59245820  {
    5925     if( m_bUseSBACRD )
    5926     {
    59275821      assert( 0 ); // check
    59285822      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    5929     }
    59305823    // copy best cbf and trIdx to pcCU
    59315824    const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1);
     
    59575850#endif
    59585851  // update with clipped distortion and cost (qp estimation loop uses unclipped values)
    5959 #if WEIGHTED_CHROMA_DISTORTION
    59605852    uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    59615853    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    59625854    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    5963 #else
    5964   uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    5965   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    5966   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    5967 #endif
    59685855#if H_3D_VSO // M23
    59695856  }
     
    59845871 
    59855872  pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) );
    5986 
    59875873#if H_3D_VSO // M24 // necessary??
    59885874  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     
    61626048    UInt uiBits = 0;
    61636049    TComYuv *pDummy = NULL;
    6164     if( m_bUseSBACRD )
    6165     {
    6166       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    6167     }
     6050    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] );
    61686051
    61696052    xAddSymbolBitsInter( pcCU, 0, 0, uiBits, pDummy, NULL, pDummy );
     
    61846067    pcCU->getTotalCost()       = rdCost;
    61856068
    6186     if( m_bUseSBACRD )
    6187     {
    6188       m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    6189     }
     6069    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] );
    61906070  }
    61916071
     
    62166096  Bool bCheckFull;
    62176097  if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) )
     6098  {
    62186099     bCheckFull = false;
     6100  }
    62196101  else
     6102  {
    62206103     bCheckFull =  ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() );
     6104  }
    62216105
    62226106  const Bool bCheckSplit  = ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     
    62476131  UInt uiBestTransformMode[3] = {0};
    62486132
    6249   if( m_bUseSBACRD )
    6250   {
    62516133    m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    6252   }
    62536134 
    62546135  if( bCheckFull )
     
    63166197
    63176198#if RDOQ_CHROMA_LAMBDA
    6318       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     6199      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    63196200#endif
    63206201
     
    63276208      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    63286209      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     6210     
     6211#if RDOQ_CHROMA_LAMBDA
     6212      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     6213#endif
     6214
    63296215      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    63306216#if ADAPTIVE_QP_SELECTION
     
    63396225    m_pcEntropyCoder->resetBits();
    63406226   
    6341     {
    63426227      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    6343     }
    63446228   
    63456229    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx,  trWidth,  trHeight,    uiDepth, TEXT_LUMA );
     
    63506234    if( bCodeChroma )
    63516235    {
    6352       {
    63536236        m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    6354       }
    63556237      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U );
    63566238      uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY;
    63576239     
    6358       {
    63596240        m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    6360       }
    63616241      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V );
    63626242      uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU );
     
    64006280
    64016281      Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
    6402       assert(scalingListType < 6);     
     6282      assert(scalingListType < SCALING_LIST_NUM);
    64036283      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
    64046284
     
    64236303      }
    64246304#else     
    6425       const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),      pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight );
     6305      const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),
     6306      pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight );
    64266307#endif
    64276308      if (pcCU->isLosslessCoded(0))
     
    65006381    {
    65016382      uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    6502 #if WEIGHTED_CHROMA_DISTORTION
    65036383                                        , TEXT_CHROMA_U
    6504 #endif
    65056384                                        ); // initialized with zero residual destortion
    65066385      if ( puiZeroDist )
     
    65166395
    65176396        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U];
    6518         assert(scalingListType < 6);
     6397        assert(scalingListType < SCALING_LIST_NUM);
    65196398        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType  );
    65206399       
    65216400        const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    65226401                                                            pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    6523 #if WEIGHTED_CHROMA_DISTORTION
    65246402                                                            , TEXT_CHROMA_U
    6525 #endif
    65266403                                                            );
    65276404
     
    65596436      {
    65606437        m_pcEntropyCoder->resetBits();
    6561         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrModeC );
     6438        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode );
    65626439        const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits();
    65636440        minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU );
     
    65756452     
    65766453      uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    6577 #if WEIGHTED_CHROMA_DISTORTION
    65786454                                        , TEXT_CHROMA_V
    6579 #endif
    65806455                                        ); // initialized with zero residual destortion
    65816456      if ( puiZeroDist )
     
    65906465
    65916466        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V];
    6592         assert(scalingListType < 6);
     6467        assert(scalingListType < SCALING_LIST_NUM);
    65936468        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType );
    65946469       
    65956470        const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    65966471                                                            pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    6597 #if WEIGHTED_CHROMA_DISTORTION
    65986472                                                            , TEXT_CHROMA_V
    6599 #endif
    66006473                                                            );
    66016474        if (pcCU->isLosslessCoded(0))
     
    66326505      {
    66336506        m_pcEntropyCoder->resetBits();
    6634         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrModeC );
     6507        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode );
    66356508        const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits();
    66366509        minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV );
     
    66816554      }
    66826555
    6683       if( m_bUseSBACRD )
    6684       {
    66856556        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    6686       }
    66876557
    66886558      pcCU->setTransformSkipSubParts ( 1, TEXT_LUMA, uiAbsPartIdx, uiDepth );
     
    67156585
    67166586        Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
    6717         assert(scalingListType < 6);     
     6587        assert(scalingListType < SCALING_LIST_NUM);
    67186588
    67196589        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType, true );
     
    67946664      }
    67956665
    6796       if( m_bUseSBACRD )
    6797       {
    67986666        m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    6799       }
    68006667
    68016668      pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC );
     
    68116678
    68126679#if RDOQ_CHROMA_LAMBDA
    6813       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     6680      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    68146681#endif
    68156682
     
    68216688      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    68226689      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     6690#if RDOQ_CHROMA_LAMBDA
     6691      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     6692#endif
    68236693      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    68246694#if ADAPTIVE_QP_SELECTION
     
    68446714
    68456715        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U];
    6846         assert(scalingListType < 6);
     6716        assert(scalingListType < SCALING_LIST_NUM);
    68476717
    68486718        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType, true  );
     
    68506720        uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    68516721                                                 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    6852 #if WEIGHTED_CHROMA_DISTORTION
    68536722                                                 , TEXT_CHROMA_U
    6854 #endif
    68556723                                                 );
    68566724
     
    68886756
    68896757        Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V];
    6890         assert(scalingListType < 6);
     6758        assert(scalingListType < SCALING_LIST_NUM);
    68916759
    68926760        m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType, true );
     
    68946762        uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    68956763                                                 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    6896 #if WEIGHTED_CHROMA_DISTORTION
    68976764                                                 , TEXT_CHROMA_V
    6898 #endif
    68996765                                                 );
    69006766
     
    69266792    }
    69276793
    6928     if( m_bUseSBACRD )
    6929     {
    69306794      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    6931     }
    6932 
    69336795    m_pcEntropyCoder->resetBits();
    69346796
    6935     {
    69366797      if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    69376798      {
    69386799        m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize );
    69396800      }
    6940     }
    6941 
    6942     {
     6801
    69436802      if( bCodeChroma )
    69446803      {
     
    69486807
    69496808      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    6950     }
    69516809
    69526810    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight,    uiDepth, TEXT_LUMA );
     
    69726830  if( bCheckSplit )
    69736831  {
    6974     if( m_bUseSBACRD && bCheckFull )
     6832    if( bCheckFull )
    69756833    {
    69766834      m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
     
    70126870    }
    70136871   
    7014     if( m_bUseSBACRD )
    7015     {
    70166872      m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] );
    7017     }
    70186873    m_pcEntropyCoder->resetBits();
    70196874   
    7020     {
    70216875      xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true,  TEXT_LUMA );
    70226876      xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA );
    70236877      xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U );
    70246878      xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V );
    7025     }
    70266879   
    70276880    uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits();
     
    70506903    }
    70516904    assert( bCheckFull );
    7052     if( m_bUseSBACRD )
    7053     {
    7054       m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
    7055     }
    7056   }
    7057 
     6905
     6906    m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] );
     6907  }
    70586908#if H_3D_VSO // M33
    70596909  if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() )
     
    70616911    UInt  uiWidth     = 1<< uiLog2TrSize;
    70626912    UInt  uiHeight    = 1<< uiLog2TrSize;
    7063 
    70646913    Pel*  piSrc;
    70656914    UInt  uiSrcStride;
    7066 
    70676915    if ( uiAbsSumY )
    70686916    {
     
    70776925      uiSrcStride = pcPred->getStride  ();
    70786926    }
    7079 
    70806927    m_pcRdCost->setRenModelData( pcCU, uiAbsPartIdx, piSrc, (Int) uiSrcStride, (Int) uiWidth, (Int) uiHeight );
    70816928  }
    70826929#endif
    7083 
    70846930  rdCost += dSingleCost;
    70856931  ruiBits += uiSingleBits;
     
    71066952  const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2;
    71076953
    7108   {
    71096954    if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    71106955    {
    71116956      m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize );
    71126957    }
    7113   }
    7114 
    7115   {
     6958
    71166959    assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
    71176960    if( bSubdivAndCbf )
     
    71356978      }
    71366979    }
    7137   }
    71386980 
    71396981  if( !bSubdiv )
     
    71597001    if( bSubdivAndCbf )
    71607002    {
    7161       {
    71627003        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    71637004      }
    7164     }
    71657005    else
    71667006    {
     
    72297069      if( bCodeChroma )
    72307070      {
    7231         {
    72327071          m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC );
    72337072        }
    72347073      }
    7235     }
    72367074    else
    72377075    {
     
    72797117UInt TEncSearch::xModeBitsIntra( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth )
    72807118{
    7281   if( m_bUseSBACRD )
    7282   {
    72837119    // Reload only contexts required for coding intra mode information
    72847120    m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
     
    72867122    m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] );
    72877123#endif
    7288   }
    72897124 
    72907125  pcCU->setLumaIntraDirSubParts ( uiMode, uiPartOffset, uiDepth + uiInitTrDepth );
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r833 r872  
    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 *
     
    114114  TEncSbac***     m_pppcRDSbacCoder;
    115115  TEncSbac*       m_pcRDGoOnSbacCoder;
    116   Bool            m_bUseSBACRD;
    117116  DistParam       m_cDistParam;
    118117 
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r773 r872  
    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 *
     
    266266 
    267267  eSliceType=B_SLICE;
    268   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     268  eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    269269 
    270270  rpcSlice->setSliceType    ( eSliceType );
     
    296296  if(eSliceType!=I_SLICE)
    297297  {
    298     if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     298    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag())))
    299299    {
    300300#if H_MV
     
    312312    dQP += pdQPs[ rpcSlice->getPOC() ];
    313313  }
    314 #if !RATE_CONTROL_LAMBDA_DOMAIN
    315   if ( m_pcCfg->getUseRateCtrl())
    316   {
    317     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
    318   }
    319 #endif
    320314  // ------------------------------------------------------------------------------------------------------------------
    321315  // Lambda computation
     
    419413#endif
    420414
    421 #if WEIGHTED_CHROMA_DISTORTION
    422415// for RDO
    423416  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    424   Double weight = 1.0;
     417  Double weight[2] = { 1.0, 1.0 };
    425418  Int qpc;
    426419  Int chromaQPOffset;
     
    428421  chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb();
    429422  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    430   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    431   m_pcRdCost->setCbDistortionWeight(weight);
     423  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     424  m_pcRdCost->setCbDistortionWeight(weight[0]);
    432425
    433426  chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr();
    434427  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    435   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    436   m_pcRdCost->setCrDistortionWeight(weight);
    437 #endif
     428  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     429  m_pcRdCost->setCrDistortionWeight(weight[1]);
     430
     431  const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])};
    438432
    439433#if RDOQ_CHROMA_LAMBDA
    440434// for RDOQ
    441   m_pcTrQuant->setLambda( dLambda, dLambda / weight );   
     435  m_pcTrQuant->setLambdas( lambdaArray );
    442436#else
    443437  m_pcTrQuant->setLambda( dLambda );
    444438#endif
    445439
    446 #if SAO_CHROMA_LAMBDA
    447440// For SAO
    448   rpcSlice   ->setLambda( dLambda, dLambda / weight ); 
    449 #else
    450   rpcSlice   ->setLambda( dLambda );
    451 #endif
     441  rpcSlice->setLambdas( lambdaArray );
    452442 
    453443#if HB_LAMBDA_FOR_LDC
     
    460450  }
    461451#else
    462   eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
     452eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    463453#endif
    464454
     
    570560}
    571561
    572 #if RATE_CONTROL_LAMBDA_DOMAIN
    573562Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
    574563{
     
    579568  slice->setSliceQpBase ( sliceQP );
    580569  m_pcRdCost ->setLambda( lambda );
    581 #if WEIGHTED_CHROMA_DISTORTION
    582570  // for RDO
    583571  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    584   Double weight;
     572  Double weight[2] = { 1.0, 1.0 };
    585573  Int qpc;
    586574  Int chromaQPOffset;
     
    588576  chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
    589577  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    590   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    591   m_pcRdCost->setCbDistortionWeight(weight);
     578  weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     579  m_pcRdCost->setCbDistortionWeight(weight[0]);
    592580
    593581  chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
    594582  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    595   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    596   m_pcRdCost->setCrDistortionWeight(weight);
    597 #endif
     583  weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     584  m_pcRdCost->setCrDistortionWeight(weight[1]);
     585
     586  const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])};
    598587
    599588#if RDOQ_CHROMA_LAMBDA
    600589  // for RDOQ
    601   m_pcTrQuant->setLambda( lambda, lambda / weight );
     590  m_pcTrQuant->setLambdas( lambdaArray );
    602591#else
    603592  m_pcTrQuant->setLambda( lambda );
    604593#endif
    605594
    606 #if SAO_CHROMA_LAMBDA
    607595  // For SAO
    608   slice   ->setLambda( lambda, lambda / weight );
    609 #else
    610   slice   ->setLambda( lambda );
    611 #endif
     596  slice->setLambdas( lambdaArray );
    612597}
    613 #else
    614 /**
    615  - lambda re-computation based on rate control QP
    616  */
    617 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)
    618 {
    619   Int qp;
    620   Double recalQP= (Double)changeQP;
    621   Double origQP = (Double)recalQP;
    622   Double lambda;
    623 
    624   // pre-compute lambda and QP values for all possible QP candidates
    625   for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )
    626   {
    627     // compute QP value
    628     recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);
    629 
    630     // compute lambda value
    631     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    632     Int    SHIFT_QP = 12;
    633     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    634 #if FULL_NBIT
    635     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    636 #else
    637     Int    bitdepth_luma_qp_scale = 0;
    638 #endif
    639     Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;
    640 #if FULL_NBIT
    641     Double qp_temp_orig = (Double) recalQP - SHIFT_QP;
    642 #endif
    643     // Case #1: I or P-slices (key-frame)
    644     Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;
    645     if ( eSliceType==I_SLICE )
    646     {
    647       dQPFactor=0.57*dLambda_scale;
    648     }
    649     lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    650 
    651     if ( depth>0 )
    652     {
    653 #if FULL_NBIT
    654       lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    655 #else
    656       lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    657 #endif
    658     }
    659 
    660     // if hadamard is used in ME process
    661     if ( !m_pcCfg->getUseHADME() )
    662     {
    663       lambda *= 0.95;
    664     }
    665 
    666     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    667 
    668     m_pdRdPicLambda[deltqQpIdx] = lambda;
    669     m_pdRdPicQp    [deltqQpIdx] = recalQP;
    670     m_piRdPicQp    [deltqQpIdx] = qp;
    671   }
    672 
    673   // obtain dQP = 0 case
    674   lambda  = m_pdRdPicLambda[0];
    675   recalQP = m_pdRdPicQp    [0];
    676   qp      = m_piRdPicQp    [0];
    677 
    678   if( pcSlice->getSliceType( ) != I_SLICE )
    679   {
    680     lambda *= m_pcCfg->getLambdaModifier( depth );
    681   }
    682 
    683   // store lambda
    684   m_pcRdCost ->setLambda( lambda );
    685 #if WEIGHTED_CHROMA_DISTORTION
    686   // for RDO
    687   // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    688   Double weight = 1.0;
    689   Int qpc;
    690   Int chromaQPOffset;
    691 
    692   chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    693   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    694   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    695   m_pcRdCost->setCbDistortionWeight(weight);
    696 
    697   chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    698   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    699   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    700   m_pcRdCost->setCrDistortionWeight(weight);
    701 #endif
    702 
    703 #if RDOQ_CHROMA_LAMBDA
    704   // for RDOQ
    705   m_pcTrQuant->setLambda( lambda, lambda / weight );   
    706 #else
    707   m_pcTrQuant->setLambda( lambda );
    708 #endif
    709 
    710 #if SAO_CHROMA_LAMBDA
    711   // For SAO
    712   pcSlice   ->setLambda( lambda, lambda / weight ); 
    713 #else
    714   pcSlice   ->setLambda( lambda );
    715 #endif
    716 }
    717 #endif
    718598// ====================================================================================================================
    719599// Public member functions
     
    755635  }
    756636
    757 #if RATE_CONTROL_LAMBDA_DOMAIN
    758637  if ( m_pcCfg->getUseRateCtrl() )
    759638  {
     
    761640    assert(0);
    762641  }
    763 #endif
    764642 
    765643  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
     
    793671#endif
    794672    m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    795 #if WEIGHTED_CHROMA_DISTORTION
    796673    // for RDO
    797674    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    798675    Int iQP = m_piRdPicQp    [uiQpIdx];
    799     Double weight = 1.0;
     676    Double weight[2] = { 1.0, 1.0 };
    800677    Int qpc;
    801678    Int chromaQPOffset;
     
    803680    chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    804681    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    805     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    806     m_pcRdCost->setCbDistortionWeight(weight);
     682    weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     683    m_pcRdCost->setCbDistortionWeight(weight[0]);
    807684
    808685    chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    809686    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    810     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    811     m_pcRdCost->setCrDistortionWeight(weight);
    812 #endif
    813 
     687    weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     688    m_pcRdCost->setCrDistortionWeight(weight[1]);
     689
     690    const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])};
    814691#if RDOQ_CHROMA_LAMBDA
    815692    // for RDOQ
    816     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     693    m_pcTrQuant->setLambdas( lambdaArray );
    817694#else
    818695    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    819696#endif
    820 #if SAO_CHROMA_LAMBDA
    821697    // For SAO
    822     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
    823 #else
    824     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    825 #endif
     698    pcSlice->setLambdas( lambdaArray );
    826699   
    827700    // try compress
     
    857730#endif
    858731  m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    859 #if WEIGHTED_CHROMA_DISTORTION
    860732  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    861733  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    862   Double weight = 1.0;
     734  Double weight[2] = { 1.0, 1.0 };
    863735  Int qpc;
    864736  Int chromaQPOffset;
     
    866738  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    867739  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    868   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    869   m_pcRdCost->setCbDistortionWeight(weight);
     740  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     741  m_pcRdCost->setCbDistortionWeight(weight[0]);
    870742
    871743  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    872744  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    873   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    874   m_pcRdCost->setCrDistortionWeight(weight);
    875 #endif
    876 
     745  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     746  m_pcRdCost->setCrDistortionWeight(weight[1]);
     747
     748  const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])};
    877749#if RDOQ_CHROMA_LAMBDA
    878750  // for RDOQ
    879   m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     751  m_pcTrQuant->setLambdas( lambdaArray );
    880752#else
    881753  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    882754#endif
    883 #if SAO_CHROMA_LAMBDA
    884755  // For SAO
    885   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
    886 #else
    887   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    888 #endif
     756  pcSlice->setLambdas( lambdaArray );
    889757}
    890758
    891759/** \param rpcPic   picture class
    892760 */
    893 #if RATE_CONTROL_INTRA
    894761Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
    895762{
     
    925792  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
    926793}
    927 #endif
    928794
    929795Void TEncSlice::compressSlice( TComPic*& rpcPic )
     
    943809 
    944810  // set entropy coder
    945   if( m_pcCfg->getUseSBACRD() )
    946   {
    947811    m_pcSbacCoder->init( m_pcBinCABAC );
    948812    m_pcEntropyCoder->setEntropyCoder   ( m_pcSbacCoder, pcSlice );
     
    952816    pppcRDSbacCoder->setBinCountingEnableFlag( false );
    953817    pppcRDSbacCoder->setBinsCoded( 0 );
    954   }
    955   else
    956   {
    957     m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    958     m_pcEntropyCoder->resetEntropy      ();
    959     m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
    960   }
    961818 
    962819  //------------------------------------------------------------------------------
     
    1016873  }
    1017874#endif
    1018   if( m_pcCfg->getUseSBACRD() )
    1019   {
    1020875    iNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    1021876    uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1;
     
    1037892      ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);
    1038893    }
    1039   }
    1040   //if( m_pcCfg->getUseSBACRD() )
    1041   {
    1042894    delete[] m_pcBufferLowLatSbacCoders;
    1043895    delete[] m_pcBufferLowLatBinCoderCABACs;
     
    1050902    for (UInt ui = 0; ui < uiTilesAcross; ui++)
    1051903      m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]);  //init. state
    1052   }
     904
    1053905  UInt uiWidthInLCUs  = rpcPic->getPicSym()->getFrameWidthInCU();
    1054906  //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU();
     
    1121973    }
    1122974#endif
    1123 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1124     if(m_pcCfg->getUseRateCtrl())
    1125     {
    1126 #if KWU_RC_MADPRED_E0227
    1127       if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
    1128       {
    1129         Double zn, zf, focallength, position, camshift;
    1130         Double basepos;
    1131         Bool bInterpolated;
    1132         Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
    1133 
    1134         pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
    1135         pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);
    1136         pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);
    1137 
    1138         m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));
    1139       }
    1140 #endif
    1141       if(m_pcRateCtrl->calculateUnitQP())
    1142       {
    1143         xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );
    1144       }
    1145     }
    1146 #endif
    1147975    // inherit from TR if necessary, select substream to use.
    1148     if( m_pcCfg->getUseSBACRD() )
    1149     {
    1150976      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    1151977      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     
    11921018      }
    11931019      m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code
    1194     }
    11951020
    11961021    // reset the entropy coder
     
    12101035      m_pcEntropyCoder->setEntropyCoder     ( m_pcSbacCoder, pcSlice );
    12111036    }
    1212     // if RD based on SBAC is used
    1213     if( m_pcCfg->getUseSBACRD() )
    1214     {
     1037
    12151038      // set go-on entropy coder
    12161039      m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice );
     
    12191042      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    12201043
    1221 #if RATE_CONTROL_LAMBDA_DOMAIN
    12221044      Double oldLambda = m_pcRdCost->getLambda();
    12231045      if ( m_pcCfg->getUseRateCtrl() )
     
    12271049        Double bpp       = -1.0;
    12281050
    1229 #if M0036_RC_IMPROVEMENT
    12301051        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
    1231 #else
    1232         if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
    1233 #endif
    12341052        {
    12351053          estQP = pcSlice->getSliceQp();
     
    12551073          {
    12561074#endif
    1257 #if RATE_CONTROL_INTRA
    12581075          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
    12591076          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
     
    12661083            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    12671084          }
    1268 #else
    1269           bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
    1270           estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    1271           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    1272 #endif
    1273 #if KWU_RC_MADPRED_E0227
    1274           }
    1275 #endif
    12761085#if KWU_RC_MADPRED_E0227
    12771086          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     
    12811090
    12821091          m_pcRdCost->setLambda(estLambda);
    1283 #if M0036_RC_IMPROVEMENT
    12841092#if RDOQ_CHROMA_LAMBDA
    12851093          // set lambda for RDOQ
    12861094          Double weight=m_pcRdCost->getChromaWeight();
    1287           m_pcTrQuant->setLambda( estLambda, estLambda / weight );
     1095        const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) };
     1096        m_pcTrQuant->setLambdas( lambdaArray );
    12881097#else
    12891098          m_pcTrQuant->setLambda( estLambda );
    1290 #endif
    12911099#endif
    12921100        }
     
    12951103        pcCU->getSlice()->setSliceQpBase( estQP );
    12961104      }
    1297 #endif
    12981105
    12991106      // run CU encoder
    13001107      m_pcCuEncoder->compressCU( pcCU );
    13011108
    1302 #if !TICKET_1090_FIX
    1303 #if RATE_CONTROL_LAMBDA_DOMAIN
    1304       if ( m_pcCfg->getUseRateCtrl() )
    1305       {
    1306 #if !M0036_RC_IMPROVEMENT
    1307         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1308         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1309         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1310         Double MAD = (Double)SAD / (Double)(height * width);
    1311         MAD = MAD * MAD;
    1312         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1313 #endif
    1314 
    1315         Int actualQP        = g_RCInvalidQPValue;
    1316         Double actualLambda = m_pcRdCost->getLambda();
    1317         Int actualBits      = pcCU->getTotalBits();
    1318         Int numberOfEffectivePixels    = 0;
    1319         for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
    1320         {
    1321           if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
    1322           {
    1323             numberOfEffectivePixels = numberOfEffectivePixels + 16;
    1324             break;
    1325           }
    1326         }
    1327 
    1328         if ( numberOfEffectivePixels == 0 )
    1329         {
    1330           actualQP = g_RCInvalidQPValue;
    1331         }
    1332         else
    1333         {
    1334           actualQP = pcCU->getQP( 0 );
    1335         }
    1336         m_pcRdCost->setLambda(oldLambda);
    1337 #if RATE_CONTROL_INTRA
    1338         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    1339           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1340 #else
    1341         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1342 #endif
    1343       }
    1344 #endif
    1345 #endif
    1346      
    13471109      // restore entropy coder to an initial stage
    13481110      m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice );
     
    13661128        break;
    13671129      }
    1368       if( m_pcCfg->getUseSBACRD() )
    1369       {
    1370          ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    13711130       
     1131    ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );
    13721132         //Store probabilties of second LCU in line into buffer
    13731133         if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro())
     
    13751135          m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]);
    13761136        }
    1377       }
    1378 
    1379 #if TICKET_1090_FIX
    1380 #if RATE_CONTROL_LAMBDA_DOMAIN
     1137
    13811138      if ( m_pcCfg->getUseRateCtrl() )
    13821139      {
    1383 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
     1140#if KWU_RC_MADPRED_E0227
    13841141        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    13851142        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     
    14131170        m_pcRdCost->setLambda(oldLambda);
    14141171
    1415 #if RATE_CONTROL_INTRA
    14161172        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    14171173          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1418 #else
    1419         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1420 #endif
    1421       }
    1422 #endif
    1423 #endif
    1424     }
    1425     // other case: encodeCU is not called
    1426     else
    1427     {
    1428       m_pcCuEncoder->compressCU( pcCU );
    1429       m_pcCuEncoder->encodeCU( pcCU );
    1430       if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)
    1431       {
    1432         pcSlice->setNextSlice( true );
    1433         break;
    1434       }
    1435       if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())
    1436       {
    1437         pcSlice->setNextSliceSegment( true );
    1438         break;
    1439       }
    14401174    }
    14411175   
     
    14431177    m_dPicRdCost     += pcCU->getTotalCost();
    14441178    m_uiPicDist      += pcCU->getTotalDistortion();
    1445 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1446     if(m_pcCfg->getUseRateCtrl())
    1447     {
    1448       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
    1449       m_pcRateCtrl->updataRCUnitStatus();
    1450     }
    1451 #endif
    14521179  }
    14531180  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
     
    14551182    pcSlice->setNextSlice( true );
    14561183  }
     1184  if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES)
     1185  {
     1186    if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr())
     1187    {
     1188       pcSlice->setNextSlice( true );
     1189    }
     1190    else
     1191    {
     1192       pcSlice->setNextSliceSegment( true );
     1193    }
     1194  }
    14571195  if( depSliceSegmentsEnabled )
    14581196  {
     
    14641202  }
    14651203  xRestoreWPparam( pcSlice );
    1466 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1467   if(m_pcCfg->getUseRateCtrl())
    1468   {
    1469     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
    1470   }
    1471 #endif
    14721204}
    14731205
     
    15821314       uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) )
    15831315  {
    1584     if( m_pcCfg->getUseSBACRD() )
    1585     {
    15861316      uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in?
    15871317      uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
     
    16321362      }
    16331363      m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]);  //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder)
    1634     }
     1364
    16351365    // reset the entropy coder
    16361366    if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() &&                                   // must be first CU of tile
     
    16761406#endif
    16771407    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );   
    1678     if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    1679     {
    1680       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1681       Int iNumCuInWidth     = saoParam->numCuInWidth;
    1682       Int iCUAddrInSlice    = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU());
    1683       Int iCUAddrUpInSlice  = iCUAddrInSlice - iNumCuInWidth;
    1684       Int rx = uiCUAddr % iNumCuInWidth;
    1685       Int ry = uiCUAddr / iNumCuInWidth;
    1686       Int allowMergeLeft = 1;
    1687       Int allowMergeUp   = 1;
    1688       if (rx!=0)
    1689       {
    1690         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1691         {
    1692           allowMergeLeft = 0;
    1693         }
    1694       }
    1695       if (ry!=0)
    1696       {
    1697         if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))
    1698         {
    1699           allowMergeUp = 0;
    1700         }
    1701       }
    1702       Int addr = pcCU->getAddr();
    1703       allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0);
    1704       allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0);
    1705       if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] )
    1706       {
    1707         Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag;
    1708         Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag;
    1709         if (allowMergeLeft)
    1710         {
    1711           m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft);
    1712         }
    1713         else
    1714         {
    1715           mergeLeft = 0;
    1716         }
    1717         if(mergeLeft == 0)
    1718         {
    1719           if (allowMergeUp)
    1720           {
    1721             m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp);
    1722           }
    1723           else
    1724           {
    1725             mergeUp = 0;
    1726           }
    1727           if(mergeUp == 0)
    1728           {
    1729             for (Int compIdx=0;compIdx<3;compIdx++)
    1730             {
    1731             if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1]))
    1732               {
    1733                 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx);
    1734               }
    1735             }
    1736           }
    1737         }
    1738       }
    1739     }
    1740     else if (pcSlice->getSPS()->getUseSAO())
    1741     {
    1742       Int addr = pcCU->getAddr();
    1743       SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1744       for (Int cIdx=0; cIdx<3; cIdx++)
    1745       {
    1746         SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]);
    1747         if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma()))
    1748         {
    1749           saoLcuParam->mergeUpFlag   = 0;
    1750           saoLcuParam->mergeLeftFlag = 0;
    1751           saoLcuParam->subTypeIdx    = 0;
    1752           saoLcuParam->typeIdx       = -1;
    1753           saoLcuParam->offset[0]     = 0;
    1754           saoLcuParam->offset[1]     = 0;
    1755           saoLcuParam->offset[2]     = 0;
    1756           saoLcuParam->offset[3]     = 0;
    1757         }
     1408    if ( pcSlice->getSPS()->getUseSAO() )
     1409    {
     1410      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     1411      {
     1412        SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr];
     1413        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     1414        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     1415        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     1416
     1417        Bool leftMergeAvail = false;
     1418        Bool aboveMergeAvail= false;
     1419        //merge left condition
     1420        Int rx = (uiCUAddr % uiWidthInLCUs);
     1421        if(rx > 0)
     1422        {
     1423          leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1);
     1424        }
     1425
     1426        //merge up condition
     1427        Int ry = (uiCUAddr / uiWidthInLCUs);
     1428        if(ry > 0)
     1429      {
     1430          aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs);
     1431        }
     1432
     1433        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail);
    17581434      }
    17591435    }
     
    17731449    g_bJustDoIt = g_bEncDecTraceDisable;
    17741450#endif   
    1775     if( m_pcCfg->getUseSBACRD() )
    1776     {
    17771451       pcSbacCoders[uiSubStrm].load(m_pcSbacCoder);   //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder
    17781452       
     
    17831457        m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] );
    17841458      }
    1785     }
    17861459#if H_3D_QTLPC
    17871460    rpcPic->setReduceBitsFlag(false);
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r833 r872  
    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 *
     
    107107  UInt                    m_uiSliceIdx;
    108108  std::vector<TEncSbac*> CTXMem;
    109 
    110109#if MTK_DDD_G0063
    111110  Int          m_iDDDScale;
     
    129128                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField  );
    130129#endif
    131 #if RATE_CONTROL_LAMBDA_DOMAIN
    132130  Void    resetQP             ( TComPic* pic, Int sliceQP, Double lambda );
    133 #else
    134   Void    xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);
    135 #endif
    136131  // compress and encode slice
    137132  Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
    138133  Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
    139 #if RATE_CONTROL_INTRA
    140134  Void    calCostSliceI       ( TComPic*& rpcPic );
    141 #endif
    142135  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
    143136 
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r773 r872  
    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 *
     
    106106  if (m_bUseSAO)
    107107  {
    108     m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
    109     m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
    110     m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic());
    111     m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
    112     m_cEncSAO.createEncBuffer();
     108    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     109#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     110    m_cEncSAO.createEncData(getSaoLcuBoundary());
     111#else
     112    m_cEncSAO.createEncData();
     113#endif
    113114  }
    114115#if ADAPTIVE_QP_SELECTION
     
    120121  m_cLoopFilter.        create( g_uiMaxCUDepth );
    121122
    122 #if RATE_CONTROL_LAMBDA_DOMAIN
    123123  if ( m_RCEnableRateControl )
    124124  {
     
    131131#endif
    132132  }
    133 #else
    134 #if KWU_FIX_URQ
    135   if(m_enableRateCtrl)
    136 #endif
    137     m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
    138 #endif
    139   // if SBAC-based RD optimization is used
    140   if( m_bUseSBACRD )
    141   {
    142133    m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
    143134#if FAST_BIT_EST
     
    168159    }
    169160  }
    170 }
    171161
    172162/**
     
    195185    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
    196186  }
    197   if( m_bUseSBACRD )
    198   {
     187
    199188    m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
    200189    m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
     
    218207    }
    219208  }
    220 }
    221209
    222210Void TEncTop::destroy ()
     
    228216  if (m_cSPS.getUseSAO())
    229217  {
     218    m_cEncSAO.destroyEncData();
    230219    m_cEncSAO.destroy();
    231     m_cEncSAO.destroyEncBuffer();
    232220  }
    233221  m_cLoopFilter.        destroy();
    234222  m_cRateCtrl.          destroy();
    235   // SBAC RD
    236   if( m_bUseSBACRD )
    237   {
     223
    238224    Int iDepth;
    239225    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
     
    276262    delete[] m_ppppcRDSbacCoders;
    277263    delete[] m_ppppcBinCodersCABAC;
    278   }
    279264  delete[] m_pcSbacCoders;
    280265  delete[] m_pcBinCoderCABACs;
     
    439424#endif
    440425 
    441 #if RATE_CONTROL_LAMBDA_DOMAIN
    442426  if ( m_RCEnableRateControl )
    443427  {
    444428    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
    445429  }
    446 #endif
    447 
    448430#if H_MV
    449431  }
     
    457439#endif
    458440
    459 #if RATE_CONTROL_LAMBDA_DOMAIN
    460441  if ( m_RCEnableRateControl )
    461442  {
    462443    m_cRateCtrl.destroyRCGOP();
    463444  }
    464 #endif
    465445 
    466446  iNumEncoded         = m_iNumPicRcvd;
     
    510490    TComPic *pcTopField;
    511491    xGetNewPicBuffer( pcTopField );
    512     pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
    513492    pcTopField->setReconMark (false);
    514493   
     
    532511    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
    533512   
    534     // compute image characteristics
    535     if ( getUseAdaptiveQP() )
    536     {
    537       m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
    538     }
    539    
    540513    /* -- Defield -- */
    541514   
     
    546519    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
    547520   
     521    // compute image characteristics
     522    if ( getUseAdaptiveQP() )
     523    {
     524      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     525    }   
    548526  }
    549527 
     
    562540    TComPic* pcBottomField;
    563541    xGetNewPicBuffer( pcBottomField );
    564     pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
    565542    pcBottomField->setReconMark (false);
    566543   
    567     TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     544    TComPicYuv* rpcPicYuvRec;
    568545    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
    569546    {
     
    572549    else
    573550    {
     551      rpcPicYuvRec = new TComPicYuv;
    574552      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    575553    }
     
    595573    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
    596574   
    597     // Compute image characteristics
    598     if ( getUseAdaptiveQP() )
    599     {
    600       m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
    601     }
    602    
    603575    /* -- Defield -- */
    604576   
     
    609581    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
    610582   
     583    // Compute image characteristics
     584    if ( getUseAdaptiveQP() )
     585    {
     586      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     587    }   
    611588  }
    612589 
     
    625602}
    626603#endif
    627 
    628 
    629 
    630604// ====================================================================================================================
    631605// Protected member functions
     
    672646                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
    673647    }
    674     if (getUseSAO())
    675     {
    676       rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
    677     }
    678648    m_cListPic.pushBack( rpcPic );
    679649  }
     
    697667  m_cSPS.setSPSId( getLayerIdInVps() );
    698668  m_cSPS.setLayerId( getLayerId() );
     669#endif
     670#if H_MV_HLS_7_VPS_P0048_14
     671 // Code below needs to be moved to VPS
    699672#endif
    700673  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
     
    760733 
    761734  m_cSPS.setTMVPFlagsPresent(false);
    762   m_cSPS.setUseLossless   ( m_useLossless  );
    763735
    764736  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
     
    794766  m_cSPS.setMaxTLayers( m_maxTempLayer );
    795767  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
    796   for ( i = 0; i < m_cSPS.getMaxTLayers(); i++ )
     768  for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
    797769  {
    798770    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
     
    859831  m_cPPS.setPPSId( getLayerIdInVps() );
    860832  m_cPPS.setSPSId( getLayerIdInVps() );
     833
     834#if H_MV_HLS_7_GEN_P0166_PPS_EXTENSION
     835#if H_MV 
     836  m_cPPS.setPpsExtensionTypeFlag          ( PPS_EX_T_MV ,true );
     837#if H_3D
     838  m_cPPS.setPpsExtensionTypeFlag          ( PPS_EX_T_3D ,true );
     839#endif
     840#endif
     841#endif
    861842#endif
    862843
     
    864845  m_cPPS.setDLT( getDLT() );
    865846#endif
    866 
    867847  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
    868848  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
    869849
    870   Int lowestQP = - m_cSPS.getQpBDOffsetY();
    871 
    872   if(getUseLossless())
    873   {
    874     if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )
    875     {
    876       bUseDQP = false;
    877     }
    878     else
    879     {
    880       bUseDQP = true;
    881     }
    882   }
    883   else
    884   {
    885     if(bUseDQP == false)
    886     {
    887850      if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
    888851      {
    889852        bUseDQP = true;
    890853      }
    891     }
    892   }
    893854
    894855  if(bUseDQP)
     
    905866  }
    906867
    907 #if RATE_CONTROL_LAMBDA_DOMAIN
    908868  if ( m_RCEnableRateControl )
    909869  {
     
    912872    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
    913873  }
    914 #endif
    915 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
    916   if ( m_enableRateCtrl )
    917   {
    918     m_cPPS.setUseDQP(true);
    919     m_cPPS.setMaxCuDQPDepth( 0 );
    920     m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
    921   }
    922 #endif
    923874
    924875  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
     
    991942    }
    992943  }
    993 #if H_3D
    994   if( m_cVPS->hasCamParInSliceHeader( getViewIndex() ) )
    995   {
    996     m_cPPS.setSliceHeaderExtensionPresentFlag( true );
    997   }
    998 #endif
    999944}
    1000945
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r655 r872  
    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 *
     
    8282  // encoder search
    8383  TEncSearch              m_cSearch;                      ///< encoder search class
    84   TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
     84  //TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
    8585  TEncCavlc*              m_pcCavlcCoder;                       ///< CAVLC encoder 
    8686  // coding tool
  • trunk/source/Lib/TLibEncoder/WeightPredAnalysis.cpp

    r608 r872  
    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

    r608 r872  
    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/TLibVideoIO/TVideoIOYuv.cpp

    r655 r872  
    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/TLibVideoIO/TVideoIOYuv.h

    r655 r872  
    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/libmd5/MD5.h

    r608 r872  
    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/libmd5/libmd5.h

    r608 r872  
    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.