- Timestamp:
- 2 Jan 2014, 07:21:30 (11 years ago)
- Location:
- branches/SHM-4.1-dev/source
- Files:
-
- 57 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-4.1-dev/source/App/TAppDecoder/TAppDecTop.cpp
r531 r532 145 145 // main decoder loop 146 146 Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen) 147 Bool loopFiltered[MAX_LAYERS]; 148 memset( loopFiltered, false, sizeof( loopFiltered ) ); 149 147 150 for(UInt layer=0; layer<=m_tgtLayerId; layer++) 148 151 { … … 223 226 } 224 227 } 225 if (bNewPicture || !bitstreamFile) 228 229 if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) 226 230 { 227 231 #if O0194_DIFFERENT_BITDEPTH_EL_BL … … 230 234 g_bitDepthC = g_bitDepthCLayer[curLayerId]; 231 235 #endif 232 m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic); 236 if (!loopFiltered[curLayerId] || bitstreamFile) 237 { 238 m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic); 239 } 240 loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS); 233 241 #if EARLY_REF_PIC_MARKING 234 242 m_acTDecTop[curLayerId].earlyPicMarking(m_iMaxTemporalLayer, m_targetDecLayerIdSet); … … 256 264 xFlushOutput( pcListPic, curLayerId ); 257 265 } 266 if (nalu.m_nalUnitType == NAL_UNIT_EOS) 267 { 268 xFlushOutput( pcListPic, curLayerId ); 269 } 258 270 // write reconstruction to file 259 271 if(bNewPicture) … … 316 328 // main decoder loop 317 329 Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen) 330 Bool loopFiltered = false; 318 331 319 332 #if SYNTAX_OUTPUT … … 384 397 } 385 398 } 386 if (bNewPicture || !bitstreamFile) 387 { 388 m_cTDecTop.executeLoopFilters(poc, pcListPic); 399 if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) 400 { 401 if (!loopFiltered || bitstreamFile) 402 { 403 m_cTDecTop.executeLoopFilters(poc, pcListPic); 404 } 405 loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); 389 406 } 390 407 … … 408 425 xFlushOutput( pcListPic ); 409 426 } 427 if (nalu.m_nalUnitType == NAL_UNIT_EOS) 428 { 429 xFlushOutput( pcListPic ); 430 } 410 431 // write reconstruction to file 411 432 if(bNewPicture) … … 506 527 507 528 /** \param pcListPic list of pictures to be written to file 508 \todo DYN_REF_FREE should be revised509 */529 \todo DYN_REF_FREE should be revised 530 */ 510 531 #if SVC_EXTENSION 511 532 Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ) -
branches/SHM-4.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp
r531 r532 791 791 ("MaxNumOffsetsPerPic", m_maxNumOffsetsPerPic, 2048, "Max number of SAO offset per picture (Default: 2048)") 792 792 ("SAOLcuBoundary", m_saoLcuBoundary, false, "0: right/bottom LCU boundary areas skipped from SAO parameter estimation, 1: non-deblocked pixels are used for those areas") 793 #if !HM_CLEANUP_SAO 793 794 ("SAOLcuBasedOptimization", m_saoLcuBasedOptimization, true, "0: SAO picture-based optimization, 1: SAO LCU-based optimization ") 795 #endif 794 796 ("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") 795 797 ("SliceArgument", m_sliceArgument, 0, "Depending on SliceMode being:" … … 845 847 ("FIS", m_useFastIntraScalable, false, "Fast Intra Decision for Scalable HEVC") 846 848 #endif 847 #if RATE_CONTROL_LAMBDA_DOMAIN848 849 #if RC_SHVC_HARMONIZATION 849 850 ("RateControl%d", cfg_RCEnableRateControl, false, MAX_LAYERS, "Rate control: enable rate control for layer %d") … … 857 858 ( "RateControl", m_RCEnableRateControl, false, "Rate control: enable rate control" ) 858 859 ( "TargetBitrate", m_RCTargetBitrate, 0, "Rate control: target bitrate" ) 859 #if M0036_RC_IMPROVEMENT860 860 ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, 0, "Rate control: 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation" ) 861 #else862 ( "KeepHierarchicalBit", m_RCKeepHierarchicalBit, false, "Rate control: keep hierarchical bit allocation in rate control algorithm" )863 #endif864 861 ( "LCULevelRateControl", m_RCLCULevelRC, true, "Rate control: true: LCU level RC; false: picture level RC" ) 865 862 ( "RCLCUSeparateModel", m_RCUseLCUSeparateModel, true, "Rate control: use LCU level separate R-lambda model" ) 866 863 ( "InitialQP", m_RCInitialQP, 0, "Rate control: initial QP" ) 867 864 ( "RCForceIntraQP", m_RCForceIntraQP, false, "Rate control: force intra QP to be equal to initial QP" ) 868 #endif869 #else870 ("RateCtrl,-rc", m_enableRateCtrl, false, "Rate control on/off")871 ("TargetBitrate,-tbr", m_targetBitrate, 0, "Input target bitrate")872 ("NumLCUInUnit,-nu", m_numLCUInUnit, 0, "Number of LCUs in an Unit")873 865 #endif 874 866 … … 2200 2192 } 2201 2193 2202 #if RATE_CONTROL_LAMBDA_DOMAIN2203 2194 #if RC_SHVC_HARMONIZATION 2204 2195 for ( Int layer=0; layer<m_numLayers; layer++ ) … … 2229 2220 } 2230 2221 xConfirmPara( m_uiDeltaQpRD > 0, "Rate control cannot be used together with slice level multiple-QP optimization!\n" ); 2231 }2232 #endif2233 #else2234 if(m_enableRateCtrl)2235 {2236 Int numLCUInWidth = (m_iSourceWidth / m_uiMaxCUWidth) + (( m_iSourceWidth % m_uiMaxCUWidth ) ? 1 : 0);2237 Int numLCUInHeight = (m_iSourceHeight / m_uiMaxCUHeight)+ (( m_iSourceHeight % m_uiMaxCUHeight) ? 1 : 0);2238 Int numLCUInPic = numLCUInWidth * numLCUInHeight;2239 2240 xConfirmPara( (numLCUInPic % m_numLCUInUnit) != 0, "total number of LCUs in a frame should be completely divided by NumLCUInUnit" );2241 2242 m_iMaxDeltaQP = MAX_DELTA_QP;2243 m_iMaxCuDQPDepth = MAX_CUDQP_DEPTH;2244 2222 } 2245 2223 #endif … … 2521 2499 printf("Cross-layer sample alignment : %d\n", m_phaseAlignFlag); 2522 2500 #endif 2523 #if RATE_CONTROL_LAMBDA_DOMAIN2524 2501 #if !RC_SHVC_HARMONIZATION 2525 2502 printf("RateControl : %d\n", m_RCEnableRateControl ); … … 2534 2511 } 2535 2512 #endif 2536 #else 2537 printf("RateControl : %d\n", m_enableRateCtrl); 2538 if(m_enableRateCtrl) 2539 { 2540 printf("TargetBitrate : %d\n", m_targetBitrate); 2541 printf("NumLCUInUnit : %d\n", m_numLCUInUnit); 2542 } 2543 #endif 2513 2544 2514 printf("Max Num Merge Candidates : %d\n", m_maxNumMergeCand); 2545 2515 printf("\n"); … … 2582 2552 printf("PCM:%d ", (m_usePCM && (1<<m_uiPCMLog2MinSize) <= m_uiMaxCUWidth)? 1 : 0); 2583 2553 #endif 2554 #if !HM_CLEANUP_SAO 2584 2555 printf("SAOLcuBasedOptimization:%d ", (m_saoLcuBasedOptimization)?(1):(0)); 2585 2556 #endif 2586 2557 printf("LosslessCuEnabled:%d ", (m_useLossless)? 1:0 ); 2587 2558 printf("WPP:%d ", (Int)m_useWeightedPred); -
branches/SHM-4.1-dev/source/App/TAppEncoder/TAppEncCfg.h
r531 r532 187 187 Int m_maxNumOffsetsPerPic; ///< SAO maximun number of offset per picture 188 188 Bool m_saoLcuBoundary; ///< SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas 189 #if !HM_CLEANUP_SAO 189 190 Bool m_saoLcuBasedOptimization; ///< SAO LCU-based optimization 191 #endif 190 192 // coding tools (loop filter) 191 193 Bool m_bLoopFilterDisable; ///< flag for using deblocking filter … … 295 297 Int m_TMVPModeId; 296 298 Int m_signHideFlag; 297 #if RATE_CONTROL_LAMBDA_DOMAIN298 299 #if !RC_SHVC_HARMONIZATION 299 300 Bool m_RCEnableRateControl; ///< enable rate control or not 300 301 Int m_RCTargetBitrate; ///< target bitrate when rate control is enabled 301 #if M0036_RC_IMPROVEMENT302 302 Int m_RCKeepHierarchicalBit; ///< 0: equal bit allocation; 1: fixed ratio bit allocation; 2: adaptive ratio bit allocation 303 #else304 Bool m_RCKeepHierarchicalBit; ///< whether keeping hierarchical bit allocation structure or not305 #endif306 303 Bool m_RCLCULevelRC; ///< true: LCU level rate control; false: picture level rate control 307 304 Bool m_RCUseLCUSeparateModel; ///< use separate R-lambda model at LCU level 308 305 Int m_RCInitialQP; ///< inital QP for rate control 309 306 Bool m_RCForceIntraQP; ///< force all intra picture to use initial QP or not 310 #endif311 #else312 Bool m_enableRateCtrl; ///< Flag for using rate control algorithm313 Int m_targetBitrate; ///< target bitrate314 Int m_numLCUInUnit; ///< Total number of LCUs in a frame should be completely divided by the NumLCUInUnit315 307 #endif 316 308 Int m_useScalingListId; ///< using quantization matrix -
branches/SHM-4.1-dev/source/App/TAppEncoder/TAppEncTop.cpp
r531 r532 470 470 471 471 m_acTEncTop[layer].setSaoLcuBoundary (m_saoLcuBoundary); 472 #if !HM_CLEANUP_SAO 472 473 m_acTEncTop[layer].setSaoLcuBasedOptimization (m_saoLcuBasedOptimization); 474 #endif 473 475 m_acTEncTop[layer].setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); 474 476 m_acTEncTop[layer].setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); … … 546 548 m_acTEncTop[layer].setScalingListFile ( m_scalingListFile ); 547 549 m_acTEncTop[layer].setSignHideFlag(m_signHideFlag); 548 #if RATE_CONTROL_LAMBDA_DOMAIN549 550 #if RC_SHVC_HARMONIZATION 550 551 m_acTEncTop[layer].setUseRateCtrl (m_acLayerCfg[layer].getRCEnableRateControl()); … … 563 564 m_acTEncTop[layer].setInitialQP ( m_RCInitialQP ); 564 565 m_acTEncTop[layer].setForceIntraQP ( m_RCForceIntraQP ); 565 #endif566 #else567 m_acTEncTop[layer].setUseRateCtrl ( m_enableRateCtrl);568 m_acTEncTop[layer].setTargetBitrate ( m_targetBitrate);569 m_acTEncTop[layer].setNumLCUInUnit ( m_numLCUInUnit);570 566 #endif 571 567 m_acTEncTop[layer].setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); … … 788 784 789 785 m_cTEncTop.setSaoLcuBoundary (m_saoLcuBoundary); 786 #if !HM_CLEANUP_SAO 790 787 m_cTEncTop.setSaoLcuBasedOptimization (m_saoLcuBasedOptimization); 788 #endif 791 789 m_cTEncTop.setPCMInputBitDepthFlag ( m_bPCMInputBitDepthFlag); 792 790 m_cTEncTop.setPCMFilterDisableFlag ( m_bPCMFilterDisableFlag); … … 856 854 m_cTEncTop.setScalingListFile ( m_scalingListFile ); 857 855 m_cTEncTop.setSignHideFlag(m_signHideFlag); 858 #if RATE_CONTROL_LAMBDA_DOMAIN859 856 m_cTEncTop.setUseRateCtrl ( m_RCEnableRateControl ); 860 857 m_cTEncTop.setTargetBitrate ( m_RCTargetBitrate ); … … 864 861 m_cTEncTop.setInitialQP ( m_RCInitialQP ); 865 862 m_cTEncTop.setForceIntraQP ( m_RCForceIntraQP ); 866 #else867 m_cTEncTop.setUseRateCtrl ( m_enableRateCtrl);868 m_cTEncTop.setTargetBitrate ( m_targetBitrate);869 m_cTEncTop.setNumLCUInUnit ( m_numLCUInUnit);870 #endif871 863 m_cTEncTop.setTransquantBypassEnableFlag(m_TransquantBypassEnableFlag); 872 864 m_cTEncTop.setCUTransquantBypassFlagValue(m_CUTransquantBypassFlagValue); … … 2131 2123 case NAL_UNIT_CODED_SLICE_TRAIL_R: 2132 2124 case NAL_UNIT_CODED_SLICE_TRAIL_N: 2133 case NAL_UNIT_CODED_SLICE_T LA_R:2125 case NAL_UNIT_CODED_SLICE_TSA_R: 2134 2126 case NAL_UNIT_CODED_SLICE_TSA_N: 2135 2127 case NAL_UNIT_CODED_SLICE_STSA_R: -
branches/SHM-4.1-dev/source/Lib/TAppCommon/program_options_lite.cpp
r313 r532 38 38 #include <list> 39 39 #include <map> 40 #include <algorithm> 40 41 #include "program_options_lite.h" 41 42 -
branches/SHM-4.1-dev/source/Lib/TLibCommon/CommonDef.h
r521 r532 40 40 41 41 #include <algorithm> 42 #include <vector>43 42 #if _MSC_VER > 1000 44 43 // disable "signed and unsigned mismatch" … … 57 56 58 57 #if SVC_EXTENSION 59 #define NV_VERSION "4.0" ///< Current software version 58 #include <vector> 59 #define NV_VERSION "4.1" ///< Current software version 60 60 #else 61 #define NV_VERSION "12. 0" ///< Current software version61 #define NV_VERSION "12.1" ///< Current software version 62 62 #endif 63 63 … … 209 209 210 210 NAL_UNIT_CODED_SLICE_TSA_N, // 2 211 NAL_UNIT_CODED_SLICE_T LA_R, // 3211 NAL_UNIT_CODED_SLICE_TSA_R, // 3 212 212 213 213 NAL_UNIT_CODED_SLICE_STSA_N, // 4 -
branches/SHM-4.1-dev/source/Lib/TLibCommon/NAL.h
r313 r532 76 76 return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R 77 77 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N 78 || m_nalUnitType == NAL_UNIT_CODED_SLICE_T LA_R78 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R 79 79 || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N 80 80 || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComDataCU.cpp
r507 r532 309 309 } 310 310 } 311 311 #if !HM_CLEANUP_SAO 312 312 const NDBFBlockInfo& NDBFBlockInfo::operator= (const NDBFBlockInfo& src) 313 313 { … … 328 328 } 329 329 330 330 #endif 331 331 // ==================================================================================================================== 332 332 // Public member functions … … 3638 3638 return getPic()->getPicSym()->getInverseCUOrderMap(m_uiCUAddr)*(1<<(m_pcSlice->getSPS()->getMaxCUDepth()<<1))+m_uiAbsIdxInLCU; 3639 3639 } 3640 3640 #if !HM_CLEANUP_SAO 3641 3641 /** Set neighboring blocks availabilities for non-deblocked filtering 3642 3642 * \param numLCUInPicWidth number of LCUs in picture width … … 4008 4008 } 4009 4009 4010 #endif 4011 4010 4012 #if SVC_EXTENSION 4011 4013 TComDataCU* TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase, Int iMotionMapping ) -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComDataCU.h
r494 r532 55 55 //! \{ 56 56 57 #if !HM_CLEANUP_SAO 57 58 // ==================================================================================================================== 58 59 // Non-deblocking in-loop filter processing block data structure … … 92 93 const NDBFBlockInfo& operator= (const NDBFBlockInfo& src); //!< "=" operator 93 94 }; 95 #endif 94 96 95 97 … … 159 161 Pel* m_pcIPCMSampleCr; ///< PCM sample buffer (Cr) 160 162 163 #if !HM_CLEANUP_SAO 161 164 Int* m_piSliceSUMap; ///< pointer of slice ID map 162 165 std::vector<NDBFBlockInfo> m_vNDFBlock; 163 166 #endif 164 167 // ------------------------------------------------------------------------------------------------------------------- 165 168 // neighbour access variables … … 389 392 Void setIPCMFlagSubParts (Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth); 390 393 394 #if !HM_CLEANUP_SAO 391 395 /// get slice ID for SU 392 396 Int getSUSliceID (UInt uiIdx) {return m_piSliceSUMap[uiIdx]; } … … 403 407 ,Bool bTopTileBoundary, Bool bDownTileBoundary, Bool bLeftTileBoundary, Bool bRightTileBoundary 404 408 ,Bool bIndependentTileBoundaryEnabled ); 409 #endif 405 410 // ------------------------------------------------------------------------------------------------------------------- 406 411 // member functions for accessing partition information -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComPic.cpp
r494 r532 59 59 , m_bNeededForOutput (false) 60 60 , m_uiCurrSliceIdx (0) 61 #if !HM_CLEANUP_SAO 61 62 , m_pSliceSUMap (NULL) 62 63 , m_pbValidSlice (NULL) … … 65 66 , m_bIndependentTileBoundaryForNDBFilter (false) 66 67 , m_pNDBFilterYuvTmp (NULL) 68 #endif 67 69 , m_bCheckLTMSB (false) 68 70 { … … 212 214 } 213 215 } 214 216 #if HM_CLEANUP_SAO 217 Bool TComPic::getSAOMergeAvailability(Int currAddr, Int mergeAddr) 218 { 219 Bool mergeCtbInSliceSeg = (mergeAddr >= getPicSym()->getCUOrderMap(getCU(currAddr)->getSlice()->getSliceCurStartCUAddr()/getNumPartInCU())); 220 Bool mergeCtbInTile = (getPicSym()->getTileIdxMap(mergeAddr) == getPicSym()->getTileIdxMap(currAddr)); 221 return (mergeCtbInSliceSeg && mergeCtbInTile); 222 } 223 #else 215 224 /** Create non-deblocked filter information 216 225 * \param pSliceStartAddress array for storing slice start addresses … … 548 557 549 558 } 559 #endif 550 560 551 561 #if SVC_EXTENSION -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComPic.h
r494 r532 75 75 Bool m_bNeededForOutput; 76 76 UInt m_uiCurrSliceIdx; // Index of current slice 77 #if !HM_CLEANUP_SAO 77 78 Int* m_pSliceSUMap; 78 79 Bool* m_pbValidSlice; … … 81 82 Bool m_bIndependentTileBoundaryForNDBFilter; 82 83 TComPicYuv* m_pNDBFilterYuvTmp; //!< temporary picture buffer when non-cross slice/tile boundary in-loop filtering is enabled 84 #endif 83 85 Bool m_bCheckLTMSB; 84 86 … … 199 201 Window& getDefDisplayWindow() { return m_defaultDisplayWindow; } 200 202 203 #if HM_CLEANUP_SAO 204 Bool getSAOMergeAvailability(Int currAddr, Int mergeAddr); 205 #else 201 206 Void createNonDBFilterInfo (std::vector<Int> sliceStartAddress, Int sliceGranularityDepth 202 207 ,std::vector<Bool>* LFCrossSliceBoundary … … 211 216 TComPicYuv* getYuvPicBufferForIndependentBoundaryProcessing() {return m_pNDBFilterYuvTmp;} 212 217 std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter (Int sliceID) { return m_vSliceCUDataLink[sliceID];} 218 #endif 213 219 214 220 /* field coding parameters*/ -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComPicSym.cpp
r442 r532 67 67 ,m_puiTileIdxMap(NULL) 68 68 ,m_puiInverseCUOrderMap(NULL) 69 #if HM_CLEANUP_SAO 70 ,m_saoBlkParams(NULL) 71 #endif 69 72 {}; 70 73 … … 127 130 m_puiInverseCUOrderMap[i] = i; 128 131 } 132 133 #if HM_CLEANUP_SAO 134 m_saoBlkParams = new SAOBlkParam[m_uiNumCUsInFrame]; 135 #else 129 136 m_saoParam = NULL; 137 #endif 130 138 } 131 139 … … 183 191 m_puiInverseCUOrderMap = NULL; 184 192 193 #if HM_CLEANUP_SAO 194 if(m_saoBlkParams) 195 { 196 delete[] m_saoBlkParams; m_saoBlkParams = NULL; 197 } 198 #else 185 199 if (m_saoParam) 186 200 { … … 189 203 m_saoParam = NULL; 190 204 } 205 #endif 191 206 } 192 207 … … 332 347 } 333 348 349 350 #if HM_CLEANUP_SAO 351 Void TComPicSym::deriveLoopFilterBoundaryAvailibility(Int ctu, 352 Bool& isLeftAvail, 353 Bool& isRightAvail, 354 Bool& isAboveAvail, 355 Bool& isBelowAvail, 356 Bool& isAboveLeftAvail, 357 Bool& isAboveRightAvail, 358 Bool& isBelowLeftAvail, 359 Bool& isBelowRightAvail 360 ) 361 { 362 363 isLeftAvail = (ctu % m_uiWidthInCU != 0); 364 isRightAvail = (ctu % m_uiWidthInCU != m_uiWidthInCU-1); 365 isAboveAvail = (ctu >= m_uiWidthInCU ); 366 isBelowAvail = (ctu < m_uiNumCUsInFrame - m_uiWidthInCU); 367 isAboveLeftAvail = (isAboveAvail && isLeftAvail); 368 isAboveRightAvail= (isAboveAvail && isRightAvail); 369 isBelowLeftAvail = (isBelowAvail && isLeftAvail); 370 isBelowRightAvail= (isBelowAvail && isRightAvail); 371 372 Bool isLoopFiltAcrossTilePPS = getCU(ctu)->getSlice()->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); 373 374 { 375 TComDataCU* ctuCurr = getCU(ctu); 376 TComDataCU* ctuLeft = isLeftAvail ?getCU(ctu-1):NULL; 377 TComDataCU* ctuRight = isRightAvail?getCU(ctu+1):NULL; 378 TComDataCU* ctuAbove = isAboveAvail?getCU(ctu-m_uiWidthInCU):NULL; 379 TComDataCU* ctuBelow = isBelowAvail?getCU(ctu+m_uiWidthInCU):NULL; 380 TComDataCU* ctuAboveLeft = isAboveLeftAvail ? getCU(ctu-m_uiWidthInCU-1):NULL; 381 TComDataCU* ctuAboveRigtht= isAboveRightAvail? getCU(ctu-m_uiWidthInCU+1):NULL; 382 TComDataCU* ctuBelowLeft = isBelowLeftAvail ? getCU(ctu+m_uiWidthInCU-1):NULL; 383 TComDataCU* ctuBelowRight = isBelowRightAvail? getCU(ctu+m_uiWidthInCU+1):NULL; 384 385 { 386 //left 387 if(ctuLeft != NULL) 388 { 389 isLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 390 } 391 //above 392 if(ctuAbove != NULL) 393 { 394 isAboveAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAbove->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 395 } 396 //right 397 if(ctuRight != NULL) 398 { 399 isRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuRight->getSlice()->getSliceCurStartCUAddr())?ctuRight->getSlice()->getLFCrossSliceBoundaryFlag():true; 400 } 401 //below 402 if(ctuBelow != NULL) 403 { 404 isBelowAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelow->getSlice()->getSliceCurStartCUAddr())?ctuBelow->getSlice()->getLFCrossSliceBoundaryFlag():true; 405 } 406 //above-left 407 if(ctuAboveLeft != NULL) 408 { 409 isAboveLeftAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuAboveLeft->getSlice()->getSliceCurStartCUAddr())?ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag():true; 410 } 411 //below-right 412 if(ctuBelowRight != NULL) 413 { 414 isBelowRightAvail = (ctuCurr->getSlice()->getSliceCurStartCUAddr() != ctuBelowRight->getSlice()->getSliceCurStartCUAddr())?ctuBelowRight->getSlice()->getLFCrossSliceBoundaryFlag():true; 415 } 416 417 418 //above-right 419 if(ctuAboveRigtht != NULL) 420 { 421 Int curSliceStartTS = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions); 422 Int aboveRigthtSliceStartTS = getCUOrderMap(ctuAboveRigtht->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions); 423 424 isAboveRightAvail = (curSliceStartTS == aboveRigthtSliceStartTS)?(true): 425 ( 426 (curSliceStartTS > aboveRigthtSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag()) 427 :(ctuAboveRigtht->getSlice()->getLFCrossSliceBoundaryFlag()) 428 ); 429 } 430 //below-left 431 if(ctuBelowLeft != NULL) 432 { 433 Int curSliceStartTS = getCUOrderMap(ctuCurr->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions); 434 Int belowLeftSliceStartTS = getCUOrderMap(ctuBelowLeft->getSlice()->getSliceCurStartCUAddr()/m_uiNumPartitions); 435 436 isBelowLeftAvail = (curSliceStartTS == belowLeftSliceStartTS)?(true): 437 ( 438 (curSliceStartTS > belowLeftSliceStartTS)?(ctuCurr->getSlice()->getLFCrossSliceBoundaryFlag()) 439 :(ctuBelowLeft->getSlice()->getLFCrossSliceBoundaryFlag()) 440 ); 441 } 442 } 443 444 if(!isLoopFiltAcrossTilePPS) 445 { 446 isLeftAvail = (!isLeftAvail ) ?false:(getTileIdxMap( ctuLeft->getAddr() ) == getTileIdxMap( ctu )); 447 isAboveAvail = (!isAboveAvail ) ?false:(getTileIdxMap( ctuAbove->getAddr() ) == getTileIdxMap( ctu )); 448 isRightAvail = (!isRightAvail ) ?false:(getTileIdxMap( ctuRight->getAddr() ) == getTileIdxMap( ctu )); 449 isBelowAvail = (!isBelowAvail ) ?false:(getTileIdxMap( ctuBelow->getAddr() ) == getTileIdxMap( ctu )); 450 isAboveLeftAvail = (!isAboveLeftAvail ) ?false:(getTileIdxMap( ctuAboveLeft->getAddr() ) == getTileIdxMap( ctu )); 451 isAboveRightAvail= (!isAboveRightAvail) ?false:(getTileIdxMap( ctuAboveRigtht->getAddr() ) == getTileIdxMap( ctu )); 452 isBelowLeftAvail = (!isBelowLeftAvail ) ?false:(getTileIdxMap( ctuBelowLeft->getAddr() ) == getTileIdxMap( ctu )); 453 isBelowRightAvail= (!isBelowRightAvail) ?false:(getTileIdxMap( ctuBelowRight->getAddr() ) == getTileIdxMap( ctu )); 454 } 455 } 456 457 } 458 #else 334 459 Void TComPicSym::allocSaoParam(TComSampleAdaptiveOffset *sao) 335 460 { … … 337 462 sao->allocSaoParam(m_saoParam); 338 463 } 464 #endif 339 465 340 466 TComTile::TComTile() -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComPicSym.h
r494 r532 112 112 UInt* m_puiInverseCUOrderMap; 113 113 114 #if HM_CLEANUP_SAO 115 SAOBlkParam *m_saoBlkParams; 116 #else 114 117 SAOParam *m_saoParam; 118 #endif 119 115 120 public: 116 121 Void create ( Int iPicWidth, Int iPicHeight, UInt uiMaxWidth, UInt uiMaxHeight, UInt uiMaxDepth ); … … 171 176 Void xInitTiles(); 172 177 UInt xCalculateNxtCUAddr( UInt uiCurrCUAddr ); 178 #if HM_CLEANUP_SAO 179 SAOBlkParam* getSAOBlkParam() { return m_saoBlkParams;} 180 Void deriveLoopFilterBoundaryAvailibility(Int ctu, Bool& isLeftAvail,Bool& isRightAvail,Bool& isAboveAvail,Bool& isBelowAvail,Bool& isAboveLeftAvail,Bool& isAboveRightAvail,Bool& isBelowLeftAvail,Bool& isBelowRightAvail); 181 #else 173 182 Void allocSaoParam(TComSampleAdaptiveOffset *sao); 174 183 SAOParam *getSaoParam() { return m_saoParam; } 184 #endif 185 186 175 187 };// END CLASS DEFINITION TComPicSym 176 188 -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComRdCost.cpp
r494 r532 330 330 331 331 // Setting the Distortion Parameter for Inter (subpel ME with step) 332 #if NS_HAD333 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME, Bool bUseNSHAD )334 #else335 332 Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME ) 336 #endif337 333 { 338 334 #if O0194_WEIGHTED_PREDICTION_CGS … … 353 349 rcDistParam.iCols = pcPatternKey->getROIYWidth(); 354 350 rcDistParam.iRows = pcPatternKey->getROIYHeight(); 355 #if NS_HAD356 rcDistParam.bUseNSHAD = bUseNSHAD;357 #endif358 351 359 352 // set distortion function … … 386 379 387 380 Void 388 #if NS_HAD389 TComRdCost::setDistParam( DistParam& rcDP, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard, Bool bUseNSHAD )390 #else391 381 TComRdCost::setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard ) 392 #endif393 382 { 394 383 rcDP.pOrg = p1; … … 402 391 rcDP.bitDepth = bitDepth; 403 392 rcDP.DistFunc = m_afpDistortFunc[ ( bHadamard ? DF_HADS : DF_SADS ) + g_aucConvertToBit[ iWidth ] + 1 ]; 404 #if NS_HAD405 rcDP.bUseNSHAD = bUseNSHAD;406 #endif407 393 } 408 394 … … 453 439 } 454 440 455 #if WEIGHTED_CHROMA_DISTORTION456 441 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText, DFunc eDFunc) 457 #else458 UInt TComRdCost::getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc )459 #endif460 442 { 461 443 DistParam cDtParam; … … 471 453 cDtParam.bitDepth = bitDepth; 472 454 473 #if WEIGHTED_CHROMA_DISTORTION474 455 if (eText == TEXT_CHROMA_U) 475 456 { … … 484 465 return cDtParam.DistFunc( &cDtParam ); 485 466 } 486 #else 487 return cDtParam.DistFunc( &cDtParam ); 488 #endif 489 } 490 491 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT 492 UInt TComRdCost::getSADPart ( Int bitDepth, Pel* pelCur, Int curStride, Pel* pelOrg, Int orgStride, UInt width, UInt height ) 493 { 494 UInt SAD = 0; 495 Int shift = DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 496 for ( Int i=0; i<height; i++ ) 497 { 498 for( Int j=0; j<width; j++ ) 499 { 500 SAD += abs((pelCur[j] - pelOrg[j])) >> shift; 501 } 502 pelCur = pelCur + curStride; 503 pelOrg = pelOrg + orgStride; 504 } 505 return SAD; 506 } 507 #endif 467 } 508 468 509 469 // ==================================================================================================================== … … 1579 1539 } 1580 1540 1581 #if NS_HAD1582 UInt TComRdCost::xCalcHADs16x4( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )1583 {1584 Int k, i, j, jj, sad=0;1585 Int diff[64], m1[4][16], m2[4][16];1586 assert( iStep == 1 );1587 for( k = 0; k < 64; k += 16 )1588 {1589 diff[k+0] = piOrg[0] - piCur[0];1590 diff[k+1] = piOrg[1] - piCur[1];1591 diff[k+2] = piOrg[2] - piCur[2];1592 diff[k+3] = piOrg[3] - piCur[3];1593 diff[k+4] = piOrg[4] - piCur[4];1594 diff[k+5] = piOrg[5] - piCur[5];1595 diff[k+6] = piOrg[6] - piCur[6];1596 diff[k+7] = piOrg[7] - piCur[7];1597 1598 diff[k+8] = piOrg[8] - piCur[8] ;1599 diff[k+9] = piOrg[9] - piCur[9] ;1600 diff[k+10] = piOrg[10] - piCur[10];1601 diff[k+11] = piOrg[11] - piCur[11];1602 diff[k+12] = piOrg[12] - piCur[12];1603 diff[k+13] = piOrg[13] - piCur[13];1604 diff[k+14] = piOrg[14] - piCur[14];1605 diff[k+15] = piOrg[15] - piCur[15];1606 1607 piCur += iStrideCur;1608 piOrg += iStrideOrg;1609 }1610 1611 //horizontal1612 for (j=0; j < 4; j++)1613 {1614 jj = j << 4;1615 1616 m2[j][0] = diff[jj ] + diff[jj+8];1617 m2[j][1] = diff[jj+1] + diff[jj+9];1618 m2[j][2] = diff[jj+2] + diff[jj+10];1619 m2[j][3] = diff[jj+3] + diff[jj+11];1620 m2[j][4] = diff[jj+4] + diff[jj+12];1621 m2[j][5] = diff[jj+5] + diff[jj+13];1622 m2[j][6] = diff[jj+6] + diff[jj+14];1623 m2[j][7] = diff[jj+7] + diff[jj+15];1624 m2[j][8] = diff[jj ] - diff[jj+8];1625 m2[j][9] = diff[jj+1] - diff[jj+9];1626 m2[j][10] = diff[jj+2] - diff[jj+10];1627 m2[j][11] = diff[jj+3] - diff[jj+11];1628 m2[j][12] = diff[jj+4] - diff[jj+12];1629 m2[j][13] = diff[jj+5] - diff[jj+13];1630 m2[j][14] = diff[jj+6] - diff[jj+14];1631 m2[j][15] = diff[jj+7] - diff[jj+15];1632 1633 m1[j][0] = m2[j][0] + m2[j][4];1634 m1[j][1] = m2[j][1] + m2[j][5];1635 m1[j][2] = m2[j][2] + m2[j][6];1636 m1[j][3] = m2[j][3] + m2[j][7];1637 m1[j][4] = m2[j][0] - m2[j][4];1638 m1[j][5] = m2[j][1] - m2[j][5];1639 m1[j][6] = m2[j][2] - m2[j][6];1640 m1[j][7] = m2[j][3] - m2[j][7];1641 m1[j][8] = m2[j][8] + m2[j][12];1642 m1[j][9] = m2[j][9] + m2[j][13];1643 m1[j][10] = m2[j][10] + m2[j][14];1644 m1[j][11] = m2[j][11] + m2[j][15];1645 m1[j][12] = m2[j][8] - m2[j][12];1646 m1[j][13] = m2[j][9] - m2[j][13];1647 m1[j][14] = m2[j][10] - m2[j][14];1648 m1[j][15] = m2[j][11] - m2[j][15];1649 1650 m2[j][0] = m1[j][0] + m1[j][2];1651 m2[j][1] = m1[j][1] + m1[j][3];1652 m2[j][2] = m1[j][0] - m1[j][2];1653 m2[j][3] = m1[j][1] - m1[j][3];1654 m2[j][4] = m1[j][4] + m1[j][6];1655 m2[j][5] = m1[j][5] + m1[j][7];1656 m2[j][6] = m1[j][4] - m1[j][6];1657 m2[j][7] = m1[j][5] - m1[j][7];1658 m2[j][8] = m1[j][8] + m1[j][10];1659 m2[j][9] = m1[j][9] + m1[j][11];1660 m2[j][10] = m1[j][8] - m1[j][10];1661 m2[j][11] = m1[j][9] - m1[j][11];1662 m2[j][12] = m1[j][12] + m1[j][14];1663 m2[j][13] = m1[j][13] + m1[j][15];1664 m2[j][14] = m1[j][12] - m1[j][14];1665 m2[j][15] = m1[j][13] - m1[j][15];1666 1667 m1[j][0] = m2[j][0] + m2[j][1];1668 m1[j][1] = m2[j][0] - m2[j][1];1669 m1[j][2] = m2[j][2] + m2[j][3];1670 m1[j][3] = m2[j][2] - m2[j][3];1671 m1[j][4] = m2[j][4] + m2[j][5];1672 m1[j][5] = m2[j][4] - m2[j][5];1673 m1[j][6] = m2[j][6] + m2[j][7];1674 m1[j][7] = m2[j][6] - m2[j][7];1675 m1[j][8] = m2[j][8] + m2[j][9];1676 m1[j][9] = m2[j][8] - m2[j][9];1677 m1[j][10] = m2[j][10] + m2[j][11];1678 m1[j][11] = m2[j][10] - m2[j][11];1679 m1[j][12] = m2[j][12] + m2[j][13];1680 m1[j][13] = m2[j][12] - m2[j][13];1681 m1[j][14] = m2[j][14] + m2[j][15];1682 m1[j][15] = m2[j][14] - m2[j][15];1683 }1684 1685 //vertical1686 for (i=0; i < 16; i++)1687 {1688 m2[0][i] = m1[0][i] + m1[2][i];1689 m2[1][i] = m1[1][i] + m1[3][i];1690 m2[2][i] = m1[0][i] - m1[2][i];1691 m2[3][i] = m1[1][i] - m1[3][i];1692 1693 m1[0][i] = m2[0][i] + m2[1][i];1694 m1[1][i] = m2[0][i] - m2[1][i];1695 m1[2][i] = m2[2][i] + m2[3][i];1696 m1[3][i] = m2[2][i] - m2[3][i];1697 }1698 1699 for (i = 0; i < 4; i++)1700 {1701 for (j = 0; j < 16; j++)1702 {1703 sad += abs(m1[i][j]);1704 }1705 }1706 1707 sad=((sad+2)>>2);1708 1709 return sad;1710 }1711 1712 UInt TComRdCost::xCalcHADs4x16( Pel *piOrg, Pel *piCur, Int iStrideOrg, Int iStrideCur, Int iStep )1713 {1714 Int k, i, j, jj, sad=0;1715 Int diff[64], m1[16][4], m2[16][4], m3[16][4];1716 assert( iStep == 1 );1717 for( k = 0; k < 64; k += 4 )1718 {1719 diff[k+0] = piOrg[0] - piCur[0];1720 diff[k+1] = piOrg[1] - piCur[1];1721 diff[k+2] = piOrg[2] - piCur[2];1722 diff[k+3] = piOrg[3] - piCur[3];1723 1724 piCur += iStrideCur;1725 piOrg += iStrideOrg;1726 }1727 1728 //horizontal1729 for (j=0; j < 16; j++)1730 {1731 jj = j << 2;1732 m2[j][0] = diff[jj ] + diff[jj+2];1733 m2[j][1] = diff[jj+1] + diff[jj+3];1734 m2[j][2] = diff[jj ] - diff[jj+2];1735 m2[j][3] = diff[jj+1] - diff[jj+3];1736 1737 m1[j][0] = m2[j][0] + m2[j][1];1738 m1[j][1] = m2[j][0] - m2[j][1];1739 m1[j][2] = m2[j][2] + m2[j][3];1740 m1[j][3] = m2[j][2] - m2[j][3];1741 }1742 1743 //vertical1744 for (i=0; i < 4; i++)1745 {1746 m2[0][i] = m1[0][i] + m1[8][i];1747 m2[1][i] = m1[1][i] + m1[9][i];1748 m2[2][i] = m1[2][i] + m1[10][i];1749 m2[3][i] = m1[3][i] + m1[11][i];1750 m2[4][i] = m1[4][i] + m1[12][i];1751 m2[5][i] = m1[5][i] + m1[13][i];1752 m2[6][i] = m1[6][i] + m1[14][i];1753 m2[7][i] = m1[7][i] + m1[15][i];1754 m2[8][i] = m1[0][i] - m1[8][i];1755 m2[9][i] = m1[1][i] - m1[9][i];1756 m2[10][i] = m1[2][i] - m1[10][i];1757 m2[11][i] = m1[3][i] - m1[11][i];1758 m2[12][i] = m1[4][i] - m1[12][i];1759 m2[13][i] = m1[5][i] - m1[13][i];1760 m2[14][i] = m1[6][i] - m1[14][i];1761 m2[15][i] = m1[7][i] - m1[15][i];1762 1763 m3[0][i] = m2[0][i] + m2[4][i];1764 m3[1][i] = m2[1][i] + m2[5][i];1765 m3[2][i] = m2[2][i] + m2[6][i];1766 m3[3][i] = m2[3][i] + m2[7][i];1767 m3[4][i] = m2[0][i] - m2[4][i];1768 m3[5][i] = m2[1][i] - m2[5][i];1769 m3[6][i] = m2[2][i] - m2[6][i];1770 m3[7][i] = m2[3][i] - m2[7][i];1771 m3[8][i] = m2[8][i] + m2[12][i];1772 m3[9][i] = m2[9][i] + m2[13][i];1773 m3[10][i] = m2[10][i] + m2[14][i];1774 m3[11][i] = m2[11][i] + m2[15][i];1775 m3[12][i] = m2[8][i] - m2[12][i];1776 m3[13][i] = m2[9][i] - m2[13][i];1777 m3[14][i] = m2[10][i] - m2[14][i];1778 m3[15][i] = m2[11][i] - m2[15][i];1779 1780 m1[0][i] = m3[0][i] + m3[2][i];1781 m1[1][i] = m3[1][i] + m3[3][i];1782 m1[2][i] = m3[0][i] - m3[2][i];1783 m1[3][i] = m3[1][i] - m3[3][i];1784 m1[4][i] = m3[4][i] + m3[6][i];1785 m1[5][i] = m3[5][i] + m3[7][i];1786 m1[6][i] = m3[4][i] - m3[6][i];1787 m1[7][i] = m3[5][i] - m3[7][i];1788 m1[8][i] = m3[8][i] + m3[10][i];1789 m1[9][i] = m3[9][i] + m3[11][i];1790 m1[10][i] = m3[8][i] - m3[10][i];1791 m1[11][i] = m3[9][i] - m3[11][i];1792 m1[12][i] = m3[12][i] + m3[14][i];1793 m1[13][i] = m3[13][i] + m3[15][i];1794 m1[14][i] = m3[12][i] - m3[14][i];1795 m1[15][i] = m3[13][i] - m3[15][i];1796 1797 m2[0][i] = m1[0][i] + m1[1][i];1798 m2[1][i] = m1[0][i] - m1[1][i];1799 m2[2][i] = m1[2][i] + m1[3][i];1800 m2[3][i] = m1[2][i] - m1[3][i];1801 m2[4][i] = m1[4][i] + m1[5][i];1802 m2[5][i] = m1[4][i] - m1[5][i];1803 m2[6][i] = m1[6][i] + m1[7][i];1804 m2[7][i] = m1[6][i] - m1[7][i];1805 m2[8][i] = m1[8][i] + m1[9][i];1806 m2[9][i] = m1[8][i] - m1[9][i];1807 m2[10][i] = m1[10][i] + m1[11][i];1808 m2[11][i] = m1[10][i] - m1[11][i];1809 m2[12][i] = m1[12][i] + m1[13][i];1810 m2[13][i] = m1[12][i] - m1[13][i];1811 m2[14][i] = m1[14][i] + m1[15][i];1812 m2[15][i] = m1[14][i] - m1[15][i];1813 }1814 1815 for (i = 0; i < 16; i++)1816 {1817 for (j = 0; j < 4; j++)1818 {1819 sad += abs(m2[i][j]);1820 }1821 }1822 1823 sad=((sad+2)>>2);1824 1825 return sad;1826 }1827 #endif1828 1829 1541 UInt TComRdCost::xGetHADs4( DistParam* pcDtParam ) 1830 1542 { … … 1909 1621 UInt uiSum = 0; 1910 1622 1911 #if NS_HAD1912 if( ( ( iRows % 8 == 0) && (iCols % 8 == 0) && ( iRows == iCols ) ) || ( ( iRows % 8 == 0 ) && (iCols % 8 == 0) && !pcDtParam->bUseNSHAD ) )1913 #else1914 1623 if( ( iRows % 8 == 0) && (iCols % 8 == 0) ) 1915 #endif1916 1624 { 1917 1625 Int iOffsetOrg = iStrideOrg<<3; … … 1927 1635 } 1928 1636 } 1929 #if NS_HAD1930 else if ( ( iCols > 8 ) && ( iCols > iRows ) && pcDtParam->bUseNSHAD )1931 {1932 Int iOffsetOrg = iStrideOrg<<2;1933 Int iOffsetCur = iStrideCur<<2;1934 for ( y=0; y<iRows; y+= 4 )1935 {1936 for ( x=0; x<iCols; x+= 16 )1937 {1938 uiSum += xCalcHADs16x4( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );1939 }1940 piOrg += iOffsetOrg;1941 piCur += iOffsetCur;1942 }1943 }1944 else if ( ( iRows > 8 ) && ( iCols < iRows ) && pcDtParam->bUseNSHAD )1945 {1946 Int iOffsetOrg = iStrideOrg<<4;1947 Int iOffsetCur = iStrideCur<<4;1948 for ( y=0; y<iRows; y+= 16 )1949 {1950 for ( x=0; x<iCols; x+= 4 )1951 {1952 uiSum += xCalcHADs4x16( &piOrg[x], &piCur[x*iStep], iStrideOrg, iStrideCur, iStep );1953 }1954 piOrg += iOffsetOrg;1955 piCur += iOffsetCur;1956 }1957 }1958 #endif1959 1637 else if( ( iRows % 4 == 0) && (iCols % 4 == 0) ) 1960 1638 { -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComRdCost.h
r442 r532 84 84 UInt uiComp; // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V) 85 85 86 #if NS_HAD87 Bool bUseNSHAD;88 #endif89 90 86 // (vertical) subsampling shift (for reducing complexity) 91 87 // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. … … 104 100 iSubShift = 0; 105 101 bitDepth = 0; 106 #if NS_HAD107 bUseNSHAD = false;108 #endif109 102 } 110 103 }; … … 123 116 #endif 124 117 125 #if WEIGHTED_CHROMA_DISTORTION126 118 Double m_cbDistortionWeight; 127 119 Double m_crDistortionWeight; 128 #endif129 120 Double m_dLambda; 130 121 Double m_sqrtLambda; … … 155 146 Double calcRdCost64( UInt64 uiBits, UInt64 uiDistortion, Bool bFlag = false, DFunc eDFunc = DF_DEFAULT ); 156 147 157 #if WEIGHTED_CHROMA_DISTORTION158 148 Void setCbDistortionWeight ( Double cbDistortionWeight) { m_cbDistortionWeight = cbDistortionWeight; }; 159 149 Void setCrDistortionWeight ( Double crDistortionWeight) { m_crDistortionWeight = crDistortionWeight; }; 160 #endif161 150 Void setLambda ( Double dLambda ); 162 151 Void setFrameLambda ( Double dLambda ) { m_dFrameLambda = dLambda; } … … 164 153 Double getSqrtLambda () { return m_sqrtLambda; } 165 154 166 #if RATE_CONTROL_LAMBDA_DOMAIN167 155 Double getLambda() { return m_dLambda; } 168 #if M0036_RC_IMPROVEMENT169 156 Double getChromaWeight () {return((m_cbDistortionWeight+m_crDistortionWeight)/2.0);} 170 #endif171 #endif172 157 173 158 // Distortion Functions … … 176 161 Void setDistParam( UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc, DistParam& rcDistParam ); 177 162 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam ); 178 #if NS_HAD179 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false, Bool bUseNSHAD=false );180 Void setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false, Bool bUseNSHAD=false );181 #else182 163 Void setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, Int iStep, DistParam& rcDistParam, Bool bHADME=false ); 183 164 Void setDistParam( DistParam& rcDP, Int bitDepth, Pel* p1, Int iStride1, Pel* p2, Int iStride2, Int iWidth, Int iHeight, Bool bHadamard = false ); 184 #endif185 165 186 166 UInt calcHAD(Int bitDepth, Pel* pi0, Int iStride0, Pel* pi1, Int iStride1, Int iWidth, Int iHeight ); … … 253 233 static UInt xCalcHADs4x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); 254 234 static UInt xCalcHADs8x8 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep ); 255 #if NS_HAD256 static UInt xCalcHADs16x4 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );257 static UInt xCalcHADs4x16 ( Pel *piOrg, Pel *piCurr, Int iStrideOrg, Int iStrideCur, Int iStep );258 #endif259 235 260 236 public: 261 #if WEIGHTED_CHROMA_DISTORTION262 237 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, TextType eText = TEXT_LUMA, DFunc eDFunc = DF_SSE ); 263 #else 264 UInt getDistPart(Int bitDepth, Pel* piCur, Int iCurStride, Pel* piOrg, Int iOrgStride, UInt uiBlkWidth, UInt uiBlkHeight, DFunc eDFunc = DF_SSE ); 265 #endif 266 267 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT 268 UInt getSADPart ( Int bitDepth, Pel* pelCur, Int curStride, Pel* pelOrg, Int orgStride, UInt width, UInt height ); 269 #endif 238 270 239 };// END CLASS DEFINITION TComRdCost 271 240 -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComRom.cpp
r529 r532 363 363 const UInt g_uiGroupIdx[ 32 ] = {0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9}; 364 364 365 // Rice parameters for absolute transform levels366 const UInt g_auiGoRiceRange[5] =367 {368 7, 14, 26, 46, 78369 };370 371 const UInt g_auiGoRicePrefixLen[5] =372 {373 8, 7, 6, 5, 4374 };375 376 365 Void initSigLastScan(UInt* pBuffD, UInt* pBuffH, UInt* pBuffV, Int iWidth, Int iHeight) 377 366 { -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComRom.h
r529 r532 131 131 extern const UInt g_uiMinInGroup[ 10 ]; 132 132 133 extern const UInt g_auiGoRiceRange[5]; //!< maximum value coded with Rice codes134 extern const UInt g_auiGoRicePrefixLen[5]; //!< prefix length for each maximum value135 136 133 extern const UInt g_sigLastScan8x8[ 3 ][ 4 ]; //!< coefficient group scan order for 8x8 TUs 137 134 extern UInt g_sigLastScanCG32x32[ 64 ]; -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp
r442 r532 44 44 //! \ingroup TLibCommon 45 45 //! \{ 46 #if HM_CLEANUP_SAO 47 UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 48 49 SAOOffset::SAOOffset() 50 { 51 reset(); 52 } 53 54 SAOOffset::~SAOOffset() 55 { 56 57 } 58 59 Void SAOOffset::reset() 60 { 61 modeIdc = SAO_MODE_OFF; 62 typeIdc = -1; 63 typeAuxInfo = -1; 64 ::memset(offset, 0, sizeof(Int)* MAX_NUM_SAO_CLASSES); 65 } 66 67 const SAOOffset& SAOOffset::operator= (const SAOOffset& src) 68 { 69 modeIdc = src.modeIdc; 70 typeIdc = src.typeIdc; 71 typeAuxInfo = src.typeAuxInfo; 72 ::memcpy(offset, src.offset, sizeof(Int)* MAX_NUM_SAO_CLASSES); 73 74 return *this; 75 } 76 77 78 SAOBlkParam::SAOBlkParam() 79 { 80 reset(); 81 } 82 83 SAOBlkParam::~SAOBlkParam() 84 { 85 86 } 87 88 Void SAOBlkParam::reset() 89 { 90 for(Int compIdx=0; compIdx< 3; compIdx++) 91 { 92 offsetParam[compIdx].reset(); 93 } 94 } 95 96 const SAOBlkParam& SAOBlkParam::operator= (const SAOBlkParam& src) 97 { 98 for(Int compIdx=0; compIdx< 3; compIdx++) 99 { 100 offsetParam[compIdx] = src.offsetParam[compIdx]; 101 } 102 return *this; 103 104 } 105 106 TComSampleAdaptiveOffset::TComSampleAdaptiveOffset() 107 { 108 m_tempPicYuv = NULL; 109 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 110 { 111 m_offsetClipTable[compIdx] = NULL; 112 } 113 m_signTable = NULL; 114 115 116 m_lineBufWidth = 0; 117 m_signLineBuf1 = NULL; 118 m_signLineBuf2 = NULL; 119 } 120 121 122 TComSampleAdaptiveOffset::~TComSampleAdaptiveOffset() 123 { 124 destroy(); 125 126 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 127 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 128 } 129 130 #if AUXILIARY_PICTURES 131 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, ChromaFormat chromaFormatIDC, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ) 132 #else 133 Void TComSampleAdaptiveOffset::create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ) 134 #endif 135 { 136 destroy(); 137 138 m_picWidth = picWidth; 139 m_picHeight= picHeight; 140 m_maxCUWidth= maxCUWidth; 141 m_maxCUHeight= maxCUHeight; 142 143 m_numCTUInWidth = (m_picWidth/m_maxCUWidth) + ((m_picWidth % m_maxCUWidth)?1:0); 144 m_numCTUInHeight= (m_picHeight/m_maxCUHeight) + ((m_picHeight % m_maxCUHeight)?1:0); 145 m_numCTUsPic = m_numCTUInHeight*m_numCTUInWidth; 146 147 //temporary picture buffer 148 if ( !m_tempPicYuv ) 149 { 150 m_tempPicYuv = new TComPicYuv; 151 #if AUXILIARY_PICTURES 152 m_tempPicYuv->create( m_picWidth, m_picHeight, chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, maxCUDepth ); 153 #else 154 m_tempPicYuv->create( m_picWidth, m_picHeight, m_maxCUWidth, m_maxCUHeight, maxCUDepth ); 155 #endif 156 } 157 158 //bit-depth related 159 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 160 { 161 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; 162 m_offsetStepLog2 [compIdx] = max(bitDepthSample - MAX_SAO_TRUNCATED_BITDEPTH, 0); 163 g_saoMaxOffsetQVal[compIdx] = (1<<(min(bitDepthSample,MAX_SAO_TRUNCATED_BITDEPTH)-5))-1; //Table 9-32, inclusive 164 } 165 166 //look-up table for clipping 167 for(Int compIdx =0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 168 { 169 Int bitDepthSample = (compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC; //exclusive 170 Int maxSampleValue = (1<< bitDepthSample); //exclusive 171 Int maxOffsetValue = (g_saoMaxOffsetQVal[compIdx] << m_offsetStepLog2[compIdx]); 172 173 m_offsetClipTable[compIdx] = new Int[(maxSampleValue + maxOffsetValue -1)+ (maxOffsetValue)+1 ]; //positive & negative range plus 0 174 m_offsetClip[compIdx] = &(m_offsetClipTable[compIdx][maxOffsetValue]); 175 176 //assign clipped values 177 Int* offsetClipPtr = m_offsetClip[compIdx]; 178 for(Int k=0; k< maxSampleValue; k++) 179 { 180 *(offsetClipPtr + k) = k; 181 } 182 for(Int k=0; k< maxOffsetValue; k++ ) 183 { 184 *(offsetClipPtr + maxSampleValue+ k) = maxSampleValue-1; 185 *(offsetClipPtr -k -1 ) = 0; 186 } 187 if(compIdx == SAO_Y) //g_bitDepthY is always larger than or equal to g_bitDepthC 188 { 189 m_signTable = new Short[ 2*(maxSampleValue-1) + 1 ]; 190 m_sign = &(m_signTable[maxSampleValue-1]); 191 192 m_sign[0] = 0; 193 for(Int k=1; k< maxSampleValue; k++) 194 { 195 m_sign[k] = 1; 196 m_sign[-k]= -1; 197 } 198 } 199 } 200 201 } 202 203 Void TComSampleAdaptiveOffset::destroy() 204 { 205 if ( m_tempPicYuv ) 206 { 207 m_tempPicYuv->destroy(); 208 delete m_tempPicYuv; 209 m_tempPicYuv = NULL; 210 } 211 212 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 213 { 214 if(m_offsetClipTable[compIdx]) 215 { 216 delete[] m_offsetClipTable[compIdx]; m_offsetClipTable[compIdx] = NULL; 217 } 218 } 219 if( m_signTable ) 220 { 221 delete[] m_signTable; m_signTable = NULL; 222 } 223 } 224 225 Void TComSampleAdaptiveOffset::invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets) 226 { 227 Int codedOffset[MAX_NUM_SAO_CLASSES]; 228 229 ::memcpy(codedOffset, srcOffsets, sizeof(Int)*MAX_NUM_SAO_CLASSES); 230 ::memset(dstOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 231 232 if(typeIdc == SAO_TYPE_START_BO) 233 { 234 for(Int i=0; i< 4; i++) 235 { 236 dstOffsets[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES] = codedOffset[(typeAuxInfo+ i)%NUM_SAO_BO_CLASSES]*(1<<m_offsetStepLog2[compIdx]); 237 } 238 } 239 else //EO 240 { 241 for(Int i=0; i< NUM_SAO_EO_CLASSES; i++) 242 { 243 dstOffsets[i] = codedOffset[i] *(1<<m_offsetStepLog2[compIdx]); 244 } 245 assert(dstOffsets[SAO_CLASS_EO_PLAIN] == 0); //keep EO plain offset as zero 246 } 247 248 } 249 250 Int TComSampleAdaptiveOffset::getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList) 251 { 252 Int ctuX = ctu % m_numCTUInWidth; 253 Int ctuY = ctu / m_numCTUInWidth; 254 Int mergedCTUPos; 255 Int numValidMergeCandidates = 0; 256 257 for(Int mergeType=0; mergeType< NUM_SAO_MERGE_TYPES; mergeType++) 258 { 259 SAOBlkParam* mergeCandidate = NULL; 260 261 switch(mergeType) 262 { 263 case SAO_MERGE_ABOVE: 264 { 265 if(ctuY > 0) 266 { 267 mergedCTUPos = ctu- m_numCTUInWidth; 268 if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) ) 269 { 270 mergeCandidate = &(blkParams[mergedCTUPos]); 271 } 272 } 273 } 274 break; 275 case SAO_MERGE_LEFT: 276 { 277 if(ctuX > 0) 278 { 279 mergedCTUPos = ctu- 1; 280 if( pic->getSAOMergeAvailability(ctu, mergedCTUPos) ) 281 { 282 mergeCandidate = &(blkParams[mergedCTUPos]); 283 } 284 } 285 } 286 break; 287 default: 288 { 289 printf("not a supported merge type"); 290 assert(0); 291 exit(-1); 292 } 293 } 294 295 mergeList.push_back(mergeCandidate); 296 if (mergeCandidate != NULL) 297 { 298 numValidMergeCandidates++; 299 } 300 } 301 302 return numValidMergeCandidates; 303 } 304 305 306 Void TComSampleAdaptiveOffset::reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList) 307 { 308 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 309 { 310 SAOOffset& offsetParam = recParam[compIdx]; 311 312 if(offsetParam.modeIdc == SAO_MODE_OFF) 313 { 314 continue; 315 } 316 317 switch(offsetParam.modeIdc) 318 { 319 case SAO_MODE_NEW: 320 { 321 invertQuantOffsets(compIdx, offsetParam.typeIdc, offsetParam.typeAuxInfo, offsetParam.offset, offsetParam.offset); 322 } 323 break; 324 case SAO_MODE_MERGE: 325 { 326 SAOBlkParam* mergeTarget = mergeList[offsetParam.typeIdc]; 327 assert(mergeTarget != NULL); 328 329 offsetParam = (*mergeTarget)[compIdx]; 330 } 331 break; 332 default: 333 { 334 printf("Not a supported mode"); 335 assert(0); 336 exit(-1); 337 } 338 } 339 } 340 } 341 342 Void TComSampleAdaptiveOffset::reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams) 343 { 344 m_picSAOEnabled[SAO_Y] = m_picSAOEnabled[SAO_Cb] = m_picSAOEnabled[SAO_Cr] = false; 345 346 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 347 { 348 std::vector<SAOBlkParam*> mergeList; 349 getMergeList(pic, ctu, saoBlkParams, mergeList); 350 351 reconstructBlkSAOParam(saoBlkParams[ctu], mergeList); 352 353 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 354 { 355 if(saoBlkParams[ctu][compIdx].modeIdc != SAO_MODE_OFF) 356 { 357 m_picSAOEnabled[compIdx] = true; 358 } 359 } 360 } 361 362 363 } 364 365 366 Void TComSampleAdaptiveOffset::offsetBlock(Int compIdx, Int typeIdx, Int* offset 367 , Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride, Int width, Int height 368 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail) 369 { 370 if(m_lineBufWidth != m_maxCUWidth) 371 { 372 m_lineBufWidth = m_maxCUWidth; 373 374 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 375 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 376 377 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 378 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 379 } 380 381 Int* offsetClip = m_offsetClip[compIdx]; 382 383 Int x,y, startX, startY, endX, endY, edgeType; 384 Int firstLineStartX, firstLineEndX, lastLineStartX, lastLineEndX; 385 Char signLeft, signRight, signDown; 386 387 Pel* srcLine = srcBlk; 388 Pel* resLine = resBlk; 389 390 switch(typeIdx) 391 { 392 case SAO_TYPE_EO_0: 393 { 394 offset += 2; 395 startX = isLeftAvail ? 0 : 1; 396 endX = isRightAvail ? width : (width -1); 397 for (y=0; y< height; y++) 398 { 399 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 400 for (x=startX; x< endX; x++) 401 { 402 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 403 edgeType = signRight + signLeft; 404 signLeft = -signRight; 405 406 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 407 } 408 srcLine += srcStride; 409 resLine += resStride; 410 } 411 412 } 413 break; 414 case SAO_TYPE_EO_90: 415 { 416 offset += 2; 417 Char *signUpLine = m_signLineBuf1; 418 419 startY = isAboveAvail ? 0 : 1; 420 endY = isBelowAvail ? height : height-1; 421 if (!isAboveAvail) 422 { 423 srcLine += srcStride; 424 resLine += resStride; 425 } 426 427 Pel* srcLineAbove= srcLine- srcStride; 428 for (x=0; x< width; x++) 429 { 430 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]]; 431 } 432 433 Pel* srcLineBelow; 434 for (y=startY; y<endY; y++) 435 { 436 srcLineBelow= srcLine+ srcStride; 437 438 for (x=0; x< width; x++) 439 { 440 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 441 edgeType = signDown + signUpLine[x]; 442 signUpLine[x]= -signDown; 443 444 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 445 } 446 srcLine += srcStride; 447 resLine += resStride; 448 } 449 450 } 451 break; 452 case SAO_TYPE_EO_135: 453 { 454 offset += 2; 455 Char *signUpLine, *signDownLine, *signTmpLine; 456 457 signUpLine = m_signLineBuf1; 458 signDownLine= m_signLineBuf2; 459 460 startX = isLeftAvail ? 0 : 1 ; 461 endX = isRightAvail ? width : (width-1); 462 463 //prepare 2nd line's upper sign 464 Pel* srcLineBelow= srcLine+ srcStride; 465 for (x=startX; x< endX+1; x++) 466 { 467 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x- 1]]; 468 } 469 470 //1st line 471 Pel* srcLineAbove= srcLine- srcStride; 472 firstLineStartX = isAboveLeftAvail ? 0 : 1; 473 firstLineEndX = isAboveAvail? endX: 1; 474 for(x= firstLineStartX; x< firstLineEndX; x++) 475 { 476 edgeType = m_sign[srcLine[x] - srcLineAbove[x- 1]] - signUpLine[x+1]; 477 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 478 } 479 srcLine += srcStride; 480 resLine += resStride; 481 482 483 //middle lines 484 for (y= 1; y< height-1; y++) 485 { 486 srcLineBelow= srcLine+ srcStride; 487 488 for (x=startX; x<endX; x++) 489 { 490 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+ 1]] ; 491 edgeType = signDown + signUpLine[x]; 492 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 493 494 signDownLine[x+1] = -signDown; 495 } 496 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]]; 497 498 signTmpLine = signUpLine; 499 signUpLine = signDownLine; 500 signDownLine = signTmpLine; 501 502 srcLine += srcStride; 503 resLine += resStride; 504 } 505 506 //last line 507 srcLineBelow= srcLine+ srcStride; 508 lastLineStartX = isBelowAvail ? startX : (width -1); 509 lastLineEndX = isBelowRightAvail ? width : (width -1); 510 for(x= lastLineStartX; x< lastLineEndX; x++) 511 { 512 edgeType = m_sign[srcLine[x] - srcLineBelow[x+ 1]] + signUpLine[x]; 513 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 514 515 } 516 } 517 break; 518 case SAO_TYPE_EO_45: 519 { 520 offset += 2; 521 Char *signUpLine = m_signLineBuf1+1; 522 523 startX = isLeftAvail ? 0 : 1; 524 endX = isRightAvail ? width : (width -1); 525 526 //prepare 2nd line upper sign 527 Pel* srcLineBelow= srcLine+ srcStride; 528 for (x=startX-1; x< endX; x++) 529 { 530 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]]; 531 } 532 533 534 //first line 535 Pel* srcLineAbove= srcLine- srcStride; 536 firstLineStartX = isAboveAvail ? startX : (width -1 ); 537 firstLineEndX = isAboveRightAvail ? width : (width-1); 538 for(x= firstLineStartX; x< firstLineEndX; x++) 539 { 540 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] -signUpLine[x-1]; 541 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 542 } 543 srcLine += srcStride; 544 resLine += resStride; 545 546 //middle lines 547 for (y= 1; y< height-1; y++) 548 { 549 srcLineBelow= srcLine+ srcStride; 550 551 for(x= startX; x< endX; x++) 552 { 553 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ; 554 edgeType = signDown + signUpLine[x]; 555 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 556 signUpLine[x-1] = -signDown; 557 } 558 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]]; 559 srcLine += srcStride; 560 resLine += resStride; 561 } 562 563 //last line 564 srcLineBelow= srcLine+ srcStride; 565 lastLineStartX = isBelowLeftAvail ? 0 : 1; 566 lastLineEndX = isBelowAvail ? endX : 1; 567 for(x= lastLineStartX; x< lastLineEndX; x++) 568 { 569 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + signUpLine[x]; 570 resLine[x] = offsetClip[srcLine[x] + offset[edgeType]]; 571 572 } 573 } 574 break; 575 case SAO_TYPE_BO: 576 { 577 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2; 578 for (y=0; y< height; y++) 579 { 580 for (x=0; x< width; x++) 581 { 582 resLine[x] = offsetClip[ srcLine[x] + offset[srcLine[x] >> shiftBits] ]; 583 } 584 srcLine += srcStride; 585 resLine += resStride; 586 } 587 } 588 break; 589 default: 590 { 591 printf("Not a supported SAO types\n"); 592 assert(0); 593 exit(-1); 594 } 595 } 596 597 598 } 599 600 Void TComSampleAdaptiveOffset::offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic) 601 { 602 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 603 604 if( 605 (saoblkParam[SAO_Y ].modeIdc == SAO_MODE_OFF) && 606 (saoblkParam[SAO_Cb].modeIdc == SAO_MODE_OFF) && 607 (saoblkParam[SAO_Cr].modeIdc == SAO_MODE_OFF) 608 ) 609 { 610 return; 611 } 612 613 //block boundary availability 614 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 615 616 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 617 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 618 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 619 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 620 621 for(Int compIdx= 0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 622 { 623 SAOOffset& ctbOffset = saoblkParam[compIdx]; 624 625 if(ctbOffset.modeIdc != SAO_MODE_OFF) 626 { 627 Bool isLuma = (compIdx == SAO_Y); 628 Int formatShift= isLuma?0:1; 629 630 Int blkWidth = (width >> formatShift); 631 Int blkHeight = (height >> formatShift); 632 Int blkYPos = (yPos >> formatShift); 633 Int blkXPos = (xPos >> formatShift); 634 635 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 636 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 637 638 Int resStride = isLuma?resYuv->getStride():resYuv->getCStride(); 639 Pel* resBlk = getPicBuf(resYuv, compIdx)+ blkYPos*resStride+ blkXPos; 640 641 offsetBlock( compIdx, ctbOffset.typeIdc, ctbOffset.offset 642 , srcBlk, resBlk, srcStride, resStride, blkWidth, blkHeight 643 , isLeftAvail, isRightAvail 644 , isAboveAvail, isBelowAvail 645 , isAboveLeftAvail, isAboveRightAvail 646 , isBelowLeftAvail, isBelowRightAvail 647 ); 648 } 649 } //compIdx 650 651 } 652 653 654 Void TComSampleAdaptiveOffset::SAOProcess(TComPic* pDecPic) 655 { 656 if(!m_picSAOEnabled[SAO_Y] && !m_picSAOEnabled[SAO_Cb] && !m_picSAOEnabled[SAO_Cr]) 657 { 658 return; 659 } 660 TComPicYuv* resYuv = pDecPic->getPicYuvRec(); 661 TComPicYuv* srcYuv = m_tempPicYuv; 662 resYuv->copyToPic(srcYuv); 663 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 664 { 665 offsetCTU(ctu, srcYuv, resYuv, (pDecPic->getPicSym()->getSAOBlkParam())[ctu], pDecPic); 666 } //ctu 667 } 668 669 670 Pel* TComSampleAdaptiveOffset::getPicBuf(TComPicYuv* pPicYuv, Int compIdx) 671 { 672 Pel* pBuf = NULL; 673 switch(compIdx) 674 { 675 case SAO_Y: 676 { 677 pBuf = pPicYuv->getLumaAddr(); 678 } 679 break; 680 case SAO_Cb: 681 { 682 pBuf = pPicYuv->getCbAddr(); 683 } 684 break; 685 case SAO_Cr: 686 { 687 pBuf = pPicYuv->getCrAddr(); 688 } 689 break; 690 default: 691 { 692 printf("Not a legal component ID for SAO\n"); 693 assert(0); 694 exit(-1); 695 } 696 } 697 698 return pBuf; 699 } 700 #else 46 701 47 702 SAOParam::~SAOParam() … … 1364 2019 } 1365 2020 } 1366 2021 #endif 1367 2022 /** PCM LF disable process. 1368 2023 * \param pcPic picture (TComPic) pointer -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComSampleAdaptiveOffset.h
r313 r532 45 45 //! \{ 46 46 47 48 #if HM_CLEANUP_SAO 49 // ==================================================================================================================== 50 // Constants 51 // ==================================================================================================================== 52 53 #define MAX_SAO_TRUNCATED_BITDEPTH 10 54 // ==================================================================================================================== 55 // Class definition 56 // ==================================================================================================================== 57 extern UInt g_saoMaxOffsetQVal[NUM_SAO_COMPONENTS]; 58 59 class TComSampleAdaptiveOffset 60 { 61 public: 62 TComSampleAdaptiveOffset(); 63 virtual ~TComSampleAdaptiveOffset(); 64 Void SAOProcess(TComPic* pDecPic); 65 #if AUXILIARY_PICTURES 66 Void create( Int picWidth, Int picHeight, ChromaFormat chromaFormatIDC, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ); 67 #else 68 Void create( Int picWidth, Int picHeight, UInt maxCUWidth, UInt maxCUHeight, UInt maxCUDepth ); 69 #endif 70 Void destroy(); 71 Void reconstructBlkSAOParams(TComPic* pic, SAOBlkParam* saoBlkParams); 72 Void PCMLFDisableProcess (TComPic* pcPic); 73 protected: 74 Void offsetBlock(Int compIdx, Int typeIdx, Int* offset, Pel* srcBlk, Pel* resBlk, Int srcStride, Int resStride, Int width, Int height 75 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail); 76 Pel* getPicBuf(TComPicYuv* pPicYuv, Int compIdx); 77 Void invertQuantOffsets(Int compIdx, Int typeIdc, Int typeAuxInfo, Int* dstOffsets, Int* srcOffsets); 78 Void reconstructBlkSAOParam(SAOBlkParam& recParam, std::vector<SAOBlkParam*>& mergeList); 79 Int getMergeList(TComPic* pic, Int ctu, SAOBlkParam* blkParams, std::vector<SAOBlkParam*>& mergeList); 80 Void offsetCTU(Int ctu, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam& saoblkParam, TComPic* pPic); 81 Void xPCMRestoration(TComPic* pcPic); 82 Void xPCMCURestoration ( TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth ); 83 Void xPCMSampleRestoration (TComDataCU* pcCU, UInt uiAbsZorderIdx, UInt uiDepth, TextType ttText); 84 protected: 85 UInt m_offsetStepLog2[NUM_SAO_COMPONENTS]; //offset step 86 Int* m_offsetClip[NUM_SAO_COMPONENTS]; //clip table for fast operation 87 Short* m_sign; //sign table for fast operation 88 TComPicYuv* m_tempPicYuv; //temporary buffer 89 Int m_picWidth; 90 Int m_picHeight; 91 Int m_maxCUWidth; 92 Int m_maxCUHeight; 93 Int m_numCTUInWidth; 94 Int m_numCTUInHeight; 95 Int m_numCTUsPic; 96 97 98 Int m_lineBufWidth; 99 Char* m_signLineBuf1; 100 Char* m_signLineBuf2; 101 private: 102 Bool m_picSAOEnabled[NUM_SAO_COMPONENTS]; 103 Int* m_offsetClipTable[NUM_SAO_COMPONENTS]; 104 Short* m_signTable; 105 106 }; 107 #else 108 47 109 // ==================================================================================================================== 48 110 // Constants … … 145 207 }; 146 208 209 #endif 210 147 211 //! \} 148 212 #endif -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComSlice.cpp
r531 r532 76 76 , m_colFromL0Flag ( 1 ) 77 77 , m_colRefIdx ( 0 ) 78 #if SAO_CHROMA_LAMBDA79 , m_dLambdaLuma( 0.0 )80 , m_dLambdaChroma( 0.0 )81 #else82 , m_dLambda ( 0.0 )83 #endif84 78 , m_uiTLayer ( 0 ) 85 79 , m_bTLayerSwitchingFlag ( false ) … … 142 136 initEqualRef(); 143 137 138 for (Int component = 0; component < 3; component++) 139 { 140 m_lambdas[component] = 0.0; 141 } 142 144 143 for ( Int idx = 0; idx < MAX_NUM_REF; idx++ ) 145 144 { … … 156 155 initWpAcDcParam(); 157 156 m_saoEnabledFlag = false; 157 #if HM_CLEANUP_SAO 158 m_saoEnabledFlagChroma = false; 159 #endif 158 160 } 159 161 … … 360 362 } 361 363 362 #if FIX1071363 364 #if SVC_EXTENSION 364 365 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr, TComPic** ilpPic) … … 366 367 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr ) 367 368 #endif 368 #else 369 Void TComSlice::setRefPicList( TComList<TComPic*>& rcListPic ) 370 #endif 371 { 372 #if FIX1071 369 { 373 370 if (!checkNumPocTotalCurr) 374 #endif375 371 { 376 372 if (m_eSliceType == I_SLICE) … … 602 598 Int numPocTotalCurr = NumPocStCurr0 + NumPocStCurr1 + NumPocLtCurr; 603 599 #endif //SVC_EXTENSION 604 #if FIX1071 600 605 601 if (checkNumPocTotalCurr) 606 602 { … … 632 628 m_aiNumRefIdx[1] = getNumRefIdx(REF_PIC_LIST_1); 633 629 } 634 #endif635 630 636 631 #if M0457_IL_SAMPLE_PRED_ONLY_FLAG … … 1192 1187 m_colFromL0Flag = pSrc->m_colFromL0Flag; 1193 1188 m_colRefIdx = pSrc->m_colRefIdx; 1194 #if SAO_CHROMA_LAMBDA 1195 m_dLambdaLuma = pSrc->m_dLambdaLuma; 1196 m_dLambdaChroma = pSrc->m_dLambdaChroma; 1197 #else 1198 m_dLambda = pSrc->m_dLambda; 1199 #endif 1189 setLambdas(pSrc->getLambdas()); 1200 1190 for (i = 0; i < 2; i++) 1201 1191 { … … 1522 1512 assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer()); 1523 1513 //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture 1524 if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_T LA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)1514 if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N) 1525 1515 { 1526 1516 assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer()); … … 1681 1671 /** Function for constructing an explicit Reference Picture Set out of the available pictures in a referenced Reference Picture Set 1682 1672 */ 1683 #if FIX10711684 1673 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP) 1685 #else1686 Void TComSlice::createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet)1687 #endif1688 1674 { 1689 1675 TComPic* rpcPic; … … 1710 1696 // and should be added to the explicit Reference Picture Set 1711 1697 pcRPS->setDeltaPOC(k, pReferencePictureSet->getDeltaPOC(i)); 1712 #if FIX10711713 1698 pcRPS->setUsed(k, pReferencePictureSet->getUsed(i) && (!isRAP)); 1714 #else1715 pcRPS->setUsed(k, pReferencePictureSet->getUsed(i));1716 #endif1717 1699 if(pcRPS->getDeltaPOC(k) < 0) 1718 1700 { … … 2870 2852 for(UInt listId=0;listId<g_scalingListNum[sizeId];listId++) 2871 2853 { 2872 getScalingList()->processDefaultMa rix(sizeId, listId);2854 getScalingList()->processDefaultMatrix(sizeId, listId); 2873 2855 } 2874 2856 } … … 3045 3027 * \param Index of input matrix 3046 3028 */ 3047 Void TComScalingList::processDefaultMa rix(UInt sizeId, UInt listId)3029 Void TComScalingList::processDefaultMatrix(UInt sizeId, UInt listId) 3048 3030 { 3049 3031 ::memcpy(getScalingListAddress(sizeId, listId),getScalingListDefaultAddress(sizeId,listId),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])); … … 3062 3044 if(getScalingListDC(sizeId,listId) == 0) 3063 3045 { 3064 processDefaultMa rix(sizeId, listId);3046 processDefaultMatrix(sizeId, listId); 3065 3047 } 3066 3048 } … … 3250 3232 #endif 3251 3233 3252 VoidTComSlice::setBaseColPic( TComList<TComPic*>& rcListPic, UInt refLayerIdc )3234 Bool TComSlice::setBaseColPic( TComList<TComPic*>& rcListPic, UInt refLayerIdc ) 3253 3235 { 3254 3236 if(m_layerId == 0) … … 3258 3240 } 3259 3241 #if POC_RESET_FLAG 3260 if( this->getPocResetFlag() ) 3261 { 3262 setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, 0)); 3242 TComPic* pic = xGetRefPic( rcListPic, m_bPocResetFlag ? 0 : m_iPOC ); 3243 3244 if( pic ) 3245 { 3246 setBaseColPic(refLayerIdc, pic ); 3263 3247 } 3264 3248 else 3265 3249 { 3266 setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 3267 } 3250 return false; 3251 } 3252 3253 return true; 3268 3254 #else 3269 3255 setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComSlice.h
r531 r532 156 156 Void setScalingListPresentFlag (Bool b) { m_scalingListPresentFlag = b; } 157 157 Bool getScalingListPresentFlag () { return m_scalingListPresentFlag; } 158 159 158 Int* getScalingListAddress (UInt sizeId, UInt listId) { return m_scalingListCoef[sizeId][listId]; } //!< get matrix coefficient 160 159 Bool checkPredMode (UInt sizeId, UInt listId); … … 162 161 UInt getRefMatrixId (UInt sizeId, UInt listId) { return m_refMatrixId[sizeId][listId]; } //!< get reference matrix ID 163 162 Int* getScalingListDefaultAddress (UInt sizeId, UInt listId); //!< get default matrix coefficient 164 Void processDefaultMa rix (UInt sizeId, UInt listId);163 Void processDefaultMatrix (UInt sizeId, UInt listId); 165 164 Void setScalingListDC (UInt sizeId, UInt listId, UInt u) { m_scalingListDC[sizeId][listId] = u; } //!< set DC value 165 166 166 Int getScalingListDC (UInt sizeId, UInt listId) { return m_scalingListDC[sizeId][listId]; } //!< get DC value 167 167 Void checkDcOfMatrix (); … … 1579 1579 Int m_deblockingFilterTcOffsetDiv2; //< tc offset for deblocking filter 1580 1580 Bool m_scalingListPresentFlag; 1581 1582 1581 TComScalingList* m_scalingList; //!< ScalingList class pointer 1583 1584 1582 Bool m_listsModificationPresentFlag; 1585 1583 UInt m_log2ParallelMergeLevelMinus2; … … 1813 1811 UInt m_maxNumMergeCand; 1814 1812 1815 #if SAO_CHROMA_LAMBDA 1816 Double m_dLambdaLuma; 1817 Double m_dLambdaChroma; 1818 #else 1819 Double m_dLambda; 1820 #endif 1813 Double m_lambdas[3]; 1821 1814 1822 1815 Bool m_abEqualRef [2][MAX_NUM_REF][MAX_NUM_REF]; … … 2004 1997 Void setDepth ( Int iDepth ) { m_iDepth = iDepth; } 2005 1998 2006 #if FIX10712007 1999 #if SVC_EXTENSION 2008 2000 Void setRefPicList ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false, TComPic** ilpPic = NULL ); 2009 2001 #else 2010 2002 Void setRefPicList ( TComList<TComPic*>& rcListPic, Bool checkNumPocTotalCurr = false ); 2011 #endif2012 #else2013 Void setRefPicList ( TComList<TComPic*>& rcListPic );2014 2003 #endif 2015 2004 Void setRefPOCList (); … … 2023 2012 Bool isInterP () { return m_eSliceType == P_SLICE; } 2024 2013 2025 #if SAO_CHROMA_LAMBDA 2026 Void setLambda( Double d, Double e ) { m_dLambdaLuma = d; m_dLambdaChroma = e;} 2027 Double getLambdaLuma() { return m_dLambdaLuma; } 2028 Double getLambdaChroma() { return m_dLambdaChroma; } 2029 #else 2030 Void setLambda( Double d ) { m_dLambda = d; } 2031 Double getLambda() { return m_dLambda; } 2032 #endif 2014 Void setLambdas ( const Double lambdas[3] ) { for (Int component = 0; component < 3; component++) m_lambdas[component] = lambdas[component]; } 2015 const Double* getLambdas() const { return m_lambdas; } 2033 2016 2034 2017 Void initEqualRef(); … … 2057 2040 Bool isStepwiseTemporalLayerSwitchingPointCandidate( TComList<TComPic*>& rcListPic ); 2058 2041 Int checkThatAllRefPicsAreAvailable( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool printErrors, Int pocRandomAccess = 0); 2059 #if FIX10712060 2042 Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet, Bool isRAP); 2061 #else2062 Void createExplicitReferencePictureSetFromReference( TComList<TComPic*>& rcListPic, TComReferencePictureSet *pReferencePictureSet);2063 #endif2064 2043 2065 2044 Void setMaxNumMergeCand (UInt val ) { m_maxNumMergeCand = val; } -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComTrQuant.cpp
r529 r532 54 54 { 55 55 iNNZbeforePos0 = 0; 56 d64CodedLevelandDist = 0;57 d64UncodedDist = 0;58 d64SigCost = 0;59 d64SigCost_0 = 0;56 d64CodedLevelandDist = 0; 57 d64UncodedDist = 0; 58 d64SigCost = 0; 59 d64SigCost_0 = 0; 60 60 } 61 61 #endif … … 1944 1944 Int64 costUp = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ; 1945 1945 Int64 costDown = rdFactor * ( deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos] 1946 - ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0);1946 - ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0); 1947 1947 1948 1948 if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1) … … 2163 2163 { 2164 2164 Double dErr = Double( lLevelDouble - ( uiAbsLevel << iQBits ) ); 2165 Double dCurrCost = dErr * dErr * dTemp + xGetIC RateCost( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx);2165 Double dCurrCost = dErr * dErr * dTemp + xGetICost(xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx )); 2166 2166 dCurrCost += dCurrCostSig; 2167 2167 … … 2184 2184 * \returns cost of given absolute transform level 2185 2185 */ 2186 __inline Double TComTrQuant::xGetICRateCost( UInt uiAbsLevel,2186 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel, 2187 2187 UShort ui16CtxNumOne, 2188 2188 UShort ui16CtxNumAbs, … … 2192 2192 ) const 2193 2193 { 2194 Double iRate = xGetIEPRate();2194 Int iRate = Int(xGetIEPRate()); 2195 2195 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2196 2196 … … 2236 2236 else 2237 2237 { 2238 assert (0); 2239 } 2240 return xGetICost( iRate ); 2241 } 2242 2243 __inline Int TComTrQuant::xGetICRate ( UInt uiAbsLevel, 2244 UShort ui16CtxNumOne, 2245 UShort ui16CtxNumAbs, 2246 UShort ui16AbsGoRice 2247 , UInt c1Idx, 2248 UInt c2Idx 2249 ) const 2250 { 2251 Int iRate = 0; 2252 UInt baseLevel = (c1Idx < C1FLAG_NUMBER)? (2 + (c2Idx < C2FLAG_NUMBER)) : 1; 2253 2254 if ( uiAbsLevel >= baseLevel ) 2255 { 2256 UInt uiSymbol = uiAbsLevel - baseLevel; 2257 UInt uiMaxVlc = g_auiGoRiceRange[ ui16AbsGoRice ]; 2258 Bool bExpGolomb = ( uiSymbol > uiMaxVlc ); 2259 2260 if( bExpGolomb ) 2261 { 2262 uiAbsLevel = uiSymbol - uiMaxVlc; 2263 Int iEGS = 1; for( UInt uiMax = 2; uiAbsLevel >= uiMax; uiMax <<= 1, iEGS += 2 ); 2264 iRate += iEGS << 15; 2265 uiSymbol = min<UInt>( uiSymbol, ( uiMaxVlc + 1 ) ); 2266 } 2267 2268 UShort ui16PrefLen = UShort( uiSymbol >> ui16AbsGoRice ) + 1; 2269 UShort ui16NumBins = min<UInt>( ui16PrefLen, g_auiGoRicePrefixLen[ ui16AbsGoRice ] ) + ui16AbsGoRice; 2270 2271 iRate += ui16NumBins << 15; 2272 2273 if (c1Idx < C1FLAG_NUMBER) 2274 { 2275 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ]; 2276 2277 if (c2Idx < C2FLAG_NUMBER) 2278 { 2279 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 1 ]; 2280 } 2281 } 2282 } 2283 else 2284 if( uiAbsLevel == 0 ) 2285 { 2286 return 0; 2287 } 2288 else if( uiAbsLevel == 1 ) 2289 { 2290 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 0 ]; 2291 } 2292 else if( uiAbsLevel == 2 ) 2293 { 2294 iRate += m_pcEstBitsSbac->m_greaterOneBits[ ui16CtxNumOne ][ 1 ]; 2295 iRate += m_pcEstBitsSbac->m_levelAbsBits[ ui16CtxNumAbs ][ 0 ]; 2296 } 2297 else 2298 { 2299 assert(0); 2238 iRate = 0; 2300 2239 } 2301 2240 return iRate; -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TComTrQuant.h
r529 r532 150 150 151 151 #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]); } 154 154 #else 155 155 Void setLambda(Double dLambda) { m_dLambda = dLambda;} … … 207 207 QpParam m_cQP; 208 208 #if RDOQ_CHROMA_LAMBDA 209 Double m_dLambdaLuma; 210 Double m_dLambdaChroma; 209 Double m_lambdas[3]; 211 210 #endif 212 211 Double m_dLambda; … … 273 272 Double dTemp, 274 273 Bool bLast ) const; 275 __inline Double xGetICRateCost ( UInt uiAbsLevel,276 UShort ui16CtxNumOne,277 UShort ui16CtxNumAbs,278 UShort ui16AbsGoRice279 , UInt c1Idx,280 UInt c2Idx281 ) const;282 274 __inline Int xGetICRate ( UInt uiAbsLevel, 283 275 UShort ui16CtxNumOne, -
branches/SHM-4.1-dev/source/Lib/TLibCommon/TypeDef.h
r531 r532 219 219 //! \{ 220 220 221 #define FIX1071 1 ///< fix for issue #1071 221 #define HM_CLEANUP_SAO 1 ///< JCTVC-N0230, 1) three SAO encoder-only software bugfixes. 2) new SAO implementation without picture quadtree, fine-grained slice legacies, and other redundancies. 222 #if HM_CLEANUP_SAO 223 #define SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1 224 #endif 222 225 223 226 #define MAX_NUM_PICS_IN_SOP 1024 … … 238 241 #define MAX_VPS_NUH_RESERVED_ZERO_LAYER_ID_PLUS1 1 239 242 #endif 240 #define RATE_CONTROL_LAMBDA_DOMAIN 1 ///< JCTVC-K0103, rate control by R-lambda model241 #define M0036_RC_IMPROVEMENT 1 ///< JCTVC-M0036, improvement for R-lambda model based rate control242 #define TICKET_1090_FIX 1243 244 #define RC_FIX 1 /// suggested fix for M0036245 #define RATE_CONTROL_INTRA 1 ///< JCTVC-M0257, rate control for intra246 243 247 244 #define MAX_CPB_CNT 32 ///< Upper bound of (cpb_cnt_minus1 + 1) … … 262 259 #define C1FLAG_NUMBER 8 // maximum number of largerThan1 flag coded in one chunk : 16 in HM5 263 260 #define C2FLAG_NUMBER 1 // maximum number of largerThan2 flag coded in one chunk: 16 in HM5 264 261 #if !HM_CLEANUP_SAO 265 262 #define REMOVE_SAO_LCU_ENC_CONSTRAINTS_3 1 ///< disable the encoder constraint that conditionally disable SAO for chroma for entire slice in interleaved mode 266 263 #endif 267 264 #define SAO_ENCODING_CHOICE 1 ///< I0184: picture early termination 268 265 #if SAO_ENCODING_CHOICE … … 278 275 #define MAX_NUM_PPS 64 279 276 280 #define WEIGHTED_CHROMA_DISTORTION 1 ///< F386: weighting of chroma for RDO281 277 #define RDOQ_CHROMA_LAMBDA 1 ///< F386: weighting of chroma for RDOQ 282 #define SAO_CHROMA_LAMBDA 1 ///< F386: weighting of chroma for SAO283 278 284 279 #define MIN_SCAN_POS_CROSS 4 … … 294 289 #define LEVEL_RANGE 30 ///< G382: max coefficient level in statistics collection 295 290 #endif 296 297 #define NS_HAD 0298 291 299 292 #define HHI_RQT_INTRA_SPEEDUP 1 ///< tests one best mode with full rqt … … 362 355 #define AMP_MRG 1 ///< encoder only force merge for AMP partition (no motion search for AMP) 363 356 #endif 364 365 #define SCALING_LIST_OUTPUT_RESULT 0 //JCTVC-G880/JCTVC-G1016 quantization matrices366 357 367 358 #define CABAC_INIT_PRESENT_FLAG 1 … … 423 414 }; 424 415 416 #if HM_CLEANUP_SAO 417 enum SAOComponentIdx 418 { 419 SAO_Y =0, 420 SAO_Cb, 421 SAO_Cr, 422 NUM_SAO_COMPONENTS 423 }; 424 425 enum SAOMode //mode 426 { 427 SAO_MODE_OFF = 0, 428 SAO_MODE_NEW, 429 SAO_MODE_MERGE, 430 NUM_SAO_MODES 431 }; 432 433 enum SAOModeMergeTypes 434 { 435 SAO_MERGE_LEFT =0, 436 SAO_MERGE_ABOVE, 437 NUM_SAO_MERGE_TYPES 438 }; 439 440 441 enum SAOModeNewTypes 442 { 443 SAO_TYPE_START_EO =0, 444 SAO_TYPE_EO_0 = SAO_TYPE_START_EO, 445 SAO_TYPE_EO_90, 446 SAO_TYPE_EO_135, 447 SAO_TYPE_EO_45, 448 449 SAO_TYPE_START_BO, 450 SAO_TYPE_BO = SAO_TYPE_START_BO, 451 452 NUM_SAO_NEW_TYPES 453 }; 454 #define NUM_SAO_EO_TYPES_LOG2 2 455 456 enum SAOEOClasses 457 { 458 SAO_CLASS_EO_FULL_VALLEY = 0, 459 SAO_CLASS_EO_HALF_VALLEY = 1, 460 SAO_CLASS_EO_PLAIN = 2, 461 SAO_CLASS_EO_HALF_PEAK = 3, 462 SAO_CLASS_EO_FULL_PEAK = 4, 463 NUM_SAO_EO_CLASSES, 464 }; 465 466 467 #define NUM_SAO_BO_CLASSES_LOG2 5 468 enum SAOBOClasses 469 { 470 //SAO_CLASS_BO_BAND0 = 0, 471 //SAO_CLASS_BO_BAND1, 472 //SAO_CLASS_BO_BAND2, 473 //... 474 //SAO_CLASS_BO_BAND31, 475 476 NUM_SAO_BO_CLASSES = (1<<NUM_SAO_BO_CLASSES_LOG2), 477 }; 478 #define MAX_NUM_SAO_CLASSES 32 //(NUM_SAO_EO_GROUPS > NUM_SAO_BO_GROUPS)?NUM_SAO_EO_GROUPS:NUM_SAO_BO_GROUPS 479 480 struct SAOOffset 481 { 482 Int modeIdc; //NEW, MERGE, OFF 483 Int typeIdc; //NEW: EO_0, EO_90, EO_135, EO_45, BO. MERGE: left, above 484 Int typeAuxInfo; //BO: starting band index 485 Int offset[MAX_NUM_SAO_CLASSES]; 486 487 SAOOffset(); 488 ~SAOOffset(); 489 Void reset(); 490 491 const SAOOffset& operator= (const SAOOffset& src); 492 }; 493 494 struct SAOBlkParam 495 { 496 497 SAOBlkParam(); 498 ~SAOBlkParam(); 499 Void reset(); 500 const SAOBlkParam& operator= (const SAOBlkParam& src); 501 SAOOffset& operator[](Int compIdx){ return offsetParam[compIdx];} 502 private: 503 SAOOffset offsetParam[NUM_SAO_COMPONENTS]; 504 505 }; 506 507 508 #else 425 509 #define NUM_DOWN_PART 4 426 510 … … 494 578 ~SAOParam(); 495 579 }; 496 580 #endif 497 581 /// parameters for deblocking filter 498 582 typedef struct _LFCUParam -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/NALread.cpp
r313 r532 126 126 else 127 127 { 128 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_T LA_R128 assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R 129 129 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N 130 130 && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp
r531 r532 1938 1938 Int pocLTCurr = rpcSlice->getPOC() - deltaPocMSBCycleLT * maxPicOrderCntLSB 1939 1939 - iPOClsb + pocLsbLt; 1940 1941 1940 rps->setPOC (j, pocLTCurr); 1942 1941 rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLTCurr); … … 2876 2875 UInt code, sizeId, listId; 2877 2876 Bool scalingListPredModeFlag; 2878 2879 2877 //for each size 2880 2878 for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) … … 2961 2959 return (cnt>0); 2962 2960 } 2961 2963 2962 //! \} 2964 2963 -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecCu.cpp
r524 r532 963 963 964 964 } 965 965 966 //! \} -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecEntropy.h
r494 r532 106 106 virtual Void parseCoeffNxN( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0; 107 107 virtual Void parseTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, UInt uiDepth, TextType eTType) = 0; 108 109 108 virtual Void updateContextTables( SliceType eSliceType, Int iQp ) = 0; 110 109 … … 166 165 Void updateContextTables ( SliceType eSliceType, Int iQp ) { m_pcEntropyDecoderIf->updateContextTables( eSliceType, iQp ); } 167 166 167 168 168 private: 169 169 Void xDecodeTransform ( TComDataCU* pcCU, UInt offsetLuma, UInt offsetChroma, UInt uiAbsPartIdx, UInt uiDepth, UInt width, UInt height, UInt uiTrIdx, Bool& bCodeDQP ); -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecGop.cpp
r442 r532 128 128 //-- For time output for each slice 129 129 long iBeforeTime = clock(); 130 130 #if !HM_CLEANUP_SAO 131 131 UInt uiStartCUAddr = pcSlice->getSliceSegmentCurStartCUAddr(); 132 132 … … 136 136 m_sliceStartCUAddress.push_back(uiSliceStartCuAddr); 137 137 } 138 138 #endif 139 139 m_pcSbacDecoder->init( (TDecBinIf*)m_pcBinCABAC ); 140 140 m_pcEntropyDecoder->setEntropyDecoder (m_pcSbacDecoder); … … 163 163 m_pcEntropyDecoder->setBitstream ( ppcSubstreams[0] ); 164 164 m_pcEntropyDecoder->resetEntropy (pcSlice); 165 165 #if !HM_CLEANUP_SAO 166 166 if(uiSliceStartCuAddr == uiStartCUAddr) 167 167 { 168 168 m_LFCrossSliceBoundaryFlag.push_back( pcSlice->getLFCrossSliceBoundaryFlag()); 169 169 } 170 #endif 170 171 m_pcSbacDecoders[0].load(m_pcSbacDecoder); 171 172 m_pcSliceDecoder->decompressSlice( ppcSubstreams, rpcPic, m_pcSbacDecoder, m_pcSbacDecoders); … … 195 196 m_pcLoopFilter->setCfg(bLFCrossTileBoundary); 196 197 m_pcLoopFilter->loopFilterPic( rpcPic ); 197 198 #if !HM_CLEANUP_SAO 198 199 if(pcSlice->getSPS()->getUseSAO()) 199 200 { … … 201 202 rpcPic->createNonDBFilterInfo(m_sliceStartCUAddress, 0, &m_LFCrossSliceBoundaryFlag, rpcPic->getPicSym()->getNumTiles(), bLFCrossTileBoundary); 202 203 } 203 204 #endif 204 205 if( pcSlice->getSPS()->getUseSAO() ) 205 206 { 207 #if HM_CLEANUP_SAO 208 m_pcSAO->reconstructBlkSAOParams(rpcPic, rpcPic->getPicSym()->getSAOBlkParam()); 209 m_pcSAO->SAOProcess(rpcPic); 210 m_pcSAO->PCMLFDisableProcess(rpcPic); 211 #else 206 212 { 207 213 SAOParam *saoParam = rpcPic->getPicSym()->getSaoParam(); … … 214 220 m_pcSAO->destroyPicSaoInfo(); 215 221 } 216 } 217 222 #endif 223 } 224 #if !HM_CLEANUP_SAO 218 225 if(pcSlice->getSPS()->getUseSAO()) 219 226 { 220 227 rpcPic->destroyNonDBFilterInfo(); 221 228 } 222 229 #endif 223 230 rpcPic->compressMotion(); 224 231 Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); … … 283 290 rpcPic->setOutputMark(true); 284 291 rpcPic->setReconMark(true); 292 #if !HM_CLEANUP_SAO 285 293 m_sliceStartCUAddress.clear(); 286 294 m_LFCrossSliceBoundaryFlag.clear(); 295 #endif 287 296 } 288 297 -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecGop.h
r313 r532 83 83 Int m_decodedPictureHashSEIEnabled; ///< Checksum(3)/CRC(2)/MD5(1)/disable(0) acting on decoded picture hash SEI message 84 84 85 #if !HM_CLEANUP_SAO 85 86 //! list that contains the CU address of each slice plus the end address 86 87 std::vector<Int> m_sliceStartCUAddress; 87 88 std::vector<Bool> m_LFCrossSliceBoundaryFlag; 88 89 #endif 89 90 #if SVC_EXTENSION 90 91 UInt m_layerId; -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecSbac.cpp
r494 r532 368 368 #if AUXILIARY_PICTURES 369 369 if (format == CHROMA_400) 370 { 370 371 uiSample = uiGrayVal; 372 } 371 373 else 372 374 #endif … … 389 391 #if AUXILIARY_PICTURES 390 392 if (format == CHROMA_400) 393 { 391 394 uiSample = uiGrayVal; 395 } 392 396 else 393 397 #endif … … 1378 1382 if (uiCode == 0) 1379 1383 { 1384 #if HM_CLEANUP_SAO 1385 ruiVal = 1; 1386 #else 1380 1387 ruiVal = 5; 1388 #endif 1381 1389 } 1382 1390 else 1383 1391 { 1392 #if HM_CLEANUP_SAO 1393 ruiVal = 2; 1394 #else 1384 1395 ruiVal = 1; 1385 } 1386 } 1387 } 1396 #endif 1397 } 1398 } 1399 } 1400 1401 #if HM_CLEANUP_SAO 1402 1403 Void TDecSbac::parseSaoSign(UInt& val) 1404 { 1405 m_pcTDecBinIf->decodeBinEP ( val ); 1406 } 1407 1408 Void TDecSbac::parseSAOBlkParam (SAOBlkParam& saoBlkParam 1409 , Bool* sliceEnabled 1410 , Bool leftMergeAvail 1411 , Bool aboveMergeAvail 1412 ) 1413 { 1414 UInt uiSymbol; 1415 1416 Bool isLeftMerge = false; 1417 Bool isAboveMerge= false; 1418 1419 if(leftMergeAvail) 1420 { 1421 parseSaoMerge(uiSymbol); //sao_merge_left_flag 1422 isLeftMerge = (uiSymbol?true:false); 1423 } 1424 1425 if( aboveMergeAvail && !isLeftMerge) 1426 { 1427 parseSaoMerge(uiSymbol); //sao_merge_up_flag 1428 isAboveMerge = (uiSymbol?true:false); 1429 } 1430 1431 if(isLeftMerge || isAboveMerge) //merge mode 1432 { 1433 saoBlkParam[SAO_Y].modeIdc = saoBlkParam[SAO_Cb].modeIdc = saoBlkParam[SAO_Cr].modeIdc = SAO_MODE_MERGE; 1434 saoBlkParam[SAO_Y].typeIdc = saoBlkParam[SAO_Cb].typeIdc = saoBlkParam[SAO_Cr].typeIdc = (isLeftMerge)?SAO_MERGE_LEFT:SAO_MERGE_ABOVE; 1435 } 1436 else //new or off mode 1437 { 1438 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 1439 { 1440 SAOOffset& ctbParam = saoBlkParam[compIdx]; 1441 1442 if(!sliceEnabled[compIdx]) 1443 { 1444 //off 1445 ctbParam.modeIdc = SAO_MODE_OFF; 1446 continue; 1447 } 1448 1449 //type 1450 if(compIdx == SAO_Y || compIdx == SAO_Cb) 1451 { 1452 parseSaoTypeIdx(uiSymbol); //sao_type_idx_luma or sao_type_idx_chroma 1453 1454 assert(uiSymbol ==0 || uiSymbol ==1 || uiSymbol ==2); 1455 1456 if(uiSymbol ==0) //OFF 1457 { 1458 ctbParam.modeIdc = SAO_MODE_OFF; 1459 } 1460 else if(uiSymbol == 1) //BO 1461 { 1462 ctbParam.modeIdc = SAO_MODE_NEW; 1463 ctbParam.typeIdc = SAO_TYPE_START_BO; 1464 } 1465 else //2, EO 1466 { 1467 ctbParam.modeIdc = SAO_MODE_NEW; 1468 ctbParam.typeIdc = SAO_TYPE_START_EO; 1469 } 1470 1471 } 1472 else //Cr, follow Cb SAO type 1473 { 1474 ctbParam.modeIdc = saoBlkParam[SAO_Cb].modeIdc; 1475 ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc; 1476 } 1477 1478 if(ctbParam.modeIdc == SAO_MODE_NEW) 1479 { 1480 Int offset[4]; 1481 for(Int i=0; i< 4; i++) 1482 { 1483 parseSaoMaxUvlc(uiSymbol, g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs 1484 offset[i] = (Int)uiSymbol; 1485 } 1486 1487 if(ctbParam.typeIdc == SAO_TYPE_START_BO) 1488 { 1489 for(Int i=0; i< 4; i++) 1490 { 1491 if(offset[i] != 0) 1492 { 1493 parseSaoSign(uiSymbol); //sao_offset_sign 1494 if(uiSymbol) 1495 { 1496 offset[i] = -offset[i]; 1497 } 1498 } 1499 } 1500 parseSaoUflc(NUM_SAO_BO_CLASSES_LOG2, uiSymbol ); //sao_band_position 1501 ctbParam.typeAuxInfo = uiSymbol; 1502 1503 for(Int i=0; i<4; i++) 1504 { 1505 ctbParam.offset[(ctbParam.typeAuxInfo+i)%MAX_NUM_SAO_CLASSES] = offset[i]; 1506 } 1507 1508 } 1509 else //EO 1510 { 1511 ctbParam.typeAuxInfo = 0; 1512 1513 if(compIdx == SAO_Y || compIdx == SAO_Cb) 1514 { 1515 parseSaoUflc(NUM_SAO_EO_TYPES_LOG2, uiSymbol ); //sao_eo_class_luma or sao_eo_class_chroma 1516 ctbParam.typeIdc += uiSymbol; 1517 } 1518 else 1519 { 1520 ctbParam.typeIdc = saoBlkParam[SAO_Cb].typeIdc; 1521 } 1522 ctbParam.offset[SAO_CLASS_EO_FULL_VALLEY] = offset[0]; 1523 ctbParam.offset[SAO_CLASS_EO_HALF_VALLEY] = offset[1]; 1524 ctbParam.offset[SAO_CLASS_EO_PLAIN ] = 0; 1525 ctbParam.offset[SAO_CLASS_EO_HALF_PEAK ] = -offset[2]; 1526 ctbParam.offset[SAO_CLASS_EO_FULL_PEAK ] = -offset[3]; 1527 } 1528 } 1529 } 1530 } 1531 } 1532 1533 #else 1388 1534 1389 1535 inline Void copySaoOneLcuParam(SaoLcuParam* psDst, SaoLcuParam* psSrc) … … 1559 1705 } 1560 1706 1707 #endif 1708 1561 1709 /** 1562 1710 - Initialize our contexts from the nominated source. -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecSbac.h
r494 r532 90 90 Void parseSaoTypeIdx ( UInt& ruiVal ); 91 91 Void parseSaoUflc ( UInt uiLength, UInt& ruiVal ); 92 #if HM_CLEANUP_SAO 93 Void parseSAOBlkParam (SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail); 94 Void parseSaoSign(UInt& val); 95 #else 92 96 Void parseSaoOneLcuInterleaving(Int rx, Int ry, SAOParam* pSaoParam, TComDataCU* pcCU, Int iCUAddrInSlice, Int iCUAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp); 93 97 Void parseSaoOffset (SaoLcuParam* psSaoLcuParam, UInt compIdx); 98 #endif 94 99 private: 95 100 Void xReadUnarySymbol ( UInt& ruiSymbol, ContextModel* pcSCModel, Int iOffset ); -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecSlice.cpp
r345 r532 197 197 UInt uiTileLCUX; 198 198 Int iNumSubstreamsPerTile = 1; // if independent. 199 200 199 Bool depSliceSegmentsEnabled = rpcPic->getSlice(rpcPic->getCurrSliceIdx())->getPPS()->getDependentSliceSegmentsEnabledFlag(); 201 200 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(iStartCUAddr))->getFirstCUAddr(); … … 323 322 g_bJustDoIt = g_bEncDecTraceEnable; 324 323 #endif 324 325 #if HM_CLEANUP_SAO 326 if ( pcSlice->getSPS()->getUseSAO() ) 327 { 328 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[iCUAddr]; 329 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 330 { 331 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 332 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 333 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 334 335 Bool leftMergeAvail = false; 336 Bool aboveMergeAvail= false; 337 338 //merge left condition 339 Int rx = (iCUAddr % uiWidthInLCUs); 340 if(rx > 0) 341 { 342 leftMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-1); 343 } 344 //merge up condition 345 Int ry = (iCUAddr / uiWidthInLCUs); 346 if(ry > 0) 347 { 348 aboveMergeAvail = rpcPic->getSAOMergeAvailability(iCUAddr, iCUAddr-uiWidthInLCUs); 349 } 350 351 pcSbacDecoder->parseSAOBlkParam( saoblkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail); 352 } 353 else 354 { 355 saoblkParam[SAO_Y ].modeIdc = SAO_MODE_OFF; 356 saoblkParam[SAO_Cb].modeIdc = SAO_MODE_OFF; 357 saoblkParam[SAO_Cr].modeIdc = SAO_MODE_OFF; 358 } 359 } 360 #else 325 361 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 326 362 { … … 374 410 } 375 411 } 412 #endif 413 376 414 m_pcCuDecoder->decodeCU ( pcCU, uiIsLast ); 377 415 m_pcCuDecoder->decompressCU ( pcCU ); -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
r531 r532 371 371 #endif 372 372 #endif 373 373 #if !HM_CLEANUP_SAO 374 374 rpcPic->getPicSym()->allocSaoParam(&m_cSAO); 375 #endif 375 376 m_cListPic.pushBack( rpcPic ); 376 377 … … 452 453 #endif 453 454 #endif 455 #if !HM_CLEANUP_SAO 454 456 rpcPic->getPicSym()->allocSaoParam(&m_cSAO); 457 #endif 455 458 } 456 459 … … 747 750 m_cSAO.destroy(); 748 751 #if REPN_FORMAT_IN_VPS 752 #if AUXILIARY_PICTURES 753 #if HM_CLEANUP_SAO 754 m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() ); 755 #else 756 m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getChromaFormatIdc(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); 757 #endif 758 #else 759 #if HM_CLEANUP_SAO 760 m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() ); 761 #else 749 762 m_cSAO.create( m_apcSlicePilot->getPicWidthInLumaSamples(), m_apcSlicePilot->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); 763 #endif 764 #endif 765 #else 766 #if HM_CLEANUP_SAO 767 m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight(), sps->getMaxCUDepth() ); 750 768 #else 751 769 m_cSAO.create( sps->getPicWidthInLumaSamples(), sps->getPicHeightInLumaSamples(), sps->getMaxCUWidth(), sps->getMaxCUHeight() ); 770 #endif 752 771 #endif 753 772 m_cLoopFilter.create( sps->getMaxCUDepth() ); … … 969 988 // Check for TSA alignment 970 989 if( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || 971 m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_T LA_R990 m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R 972 991 ) 973 992 { … … 979 998 { 980 999 assert( m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N || 981 m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_T LA_R ); // TSA pictures should be aligned among depenedent layers1000 m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ); // TSA pictures should be aligned among depenedent layers 982 1001 } 983 1002 } … … 1275 1294 if (m_layerId == 0) 1276 1295 #endif 1277 #if FIX10711278 1296 pcSlice->setRefPicList( m_cListPic, true ); 1279 #else1280 pcSlice->setRefPicList( m_cListPic );1281 #endif1282 1297 1283 1298 #if SVC_EXTENSION … … 1524 1539 { 1525 1540 pcSlice->setScalingList ( pcSlice->getSPS()->getScalingList() ); 1526 1527 1541 if(pcSlice->getPPS()->getScalingListPresentFlag()) 1528 1542 { … … 1770 1784 case NAL_UNIT_CODED_SLICE_TRAIL_R: 1771 1785 case NAL_UNIT_CODED_SLICE_TRAIL_N: 1772 case NAL_UNIT_CODED_SLICE_T LA_R:1786 case NAL_UNIT_CODED_SLICE_TSA_R: 1773 1787 case NAL_UNIT_CODED_SLICE_TSA_N: 1774 1788 case NAL_UNIT_CODED_SLICE_STSA_R: … … 1790 1804 #endif 1791 1805 break; 1806 1807 case NAL_UNIT_EOS: 1808 m_associatedIRAPType = NAL_UNIT_INVALID; 1809 m_pocCRA = 0; 1810 m_pocRandomAccess = MAX_INT; 1811 m_prevPOC = MAX_INT; 1812 m_bFirstSliceInPicture = true; 1813 m_bFirstSliceInSequence = true; 1814 m_prevSliceSkipped = false; 1815 m_skippedPOC = 0; 1816 return false; 1817 1818 case NAL_UNIT_ACCESS_UNIT_DELIMITER: 1819 // TODO: process AU delimiter 1820 return false; 1821 1822 case NAL_UNIT_EOB: 1823 return false; 1824 1792 1825 default: 1793 assert ( 1);1826 assert (0); 1794 1827 } 1795 1828 -
branches/SHM-4.1-dev/source/Lib/TLibDecoder/TDecTop.h
r531 r532 73 73 TComList<TComPic*> m_cListPic; // Dynamic buffer 74 74 ParameterSetManagerDecoder m_parameterSetManagerDecoder; // storage for parameter sets 75 76 75 TComSlice* m_apcSlicePilot; 77 76 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp
r442 r532 58 58 59 59 TEncAnalyze m_gcAnalyzeAll_in; 60 60 61 //! \} -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h
r442 r532 160 160 } 161 161 162 162 163 Void printSummary(Char ch) 163 164 { … … 207 208 208 209 extern TEncAnalyze m_gcAnalyzeAll_in; 210 209 211 //! \} 210 212 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
r531 r532 239 239 240 240 WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0, "pps_scaling_list_data_present_flag" ); 241 242 241 if( pcPPS->getScalingListPresentFlag() ) 243 242 { 244 #if SCALING_LIST_OUTPUT_RESULT245 printf("PPS\n");246 #endif247 243 codeScalingList( m_pcSlice->getScalingList() ); 248 244 } … … 521 517 WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1, "max_transform_hierarchy_depth_intra" ); 522 518 WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0, "scaling_list_enabled_flag" ); 523 524 519 if(pcSPS->getScalingListFlag()) 525 520 { … … 543 538 if(pcSPS->getScalingListPresentFlag()) 544 539 { 545 #if SCALING_LIST_OUTPUT_RESULT546 printf("SPS\n");547 #endif548 540 codeScalingList( m_pcSlice->getScalingList() ); 549 541 } … … 1427 1419 TComReferencePictureSet* rps = pcSlice->getRPS(); 1428 1420 1429 #if FIX10711430 1421 // check for bitstream restriction stating that: 1431 1422 // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. … … 1441 1432 } 1442 1433 } 1443 #endif1444 1434 1445 1435 if(pcSlice->getRPSidx() < 0) … … 1595 1585 if (pcSlice->getSPS()->getUseSAO()) 1596 1586 { 1597 WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" ); 1587 WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" ); 1588 #if AUXILIARY_PICTURES 1589 if (pcSlice->getChromaFormatIdc() != CHROMA_400) 1598 1590 { 1591 #endif 1592 #if HM_CLEANUP_SAO 1593 WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" ); 1594 #else 1595 { 1596 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1597 WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" ); 1598 } 1599 #endif 1599 1600 #if AUXILIARY_PICTURES 1600 if (pcSlice->getChromaFormatIdc() != CHROMA_400)1601 {1602 #endif1603 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();1604 WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );1605 #if AUXILIARY_PICTURES1606 }1607 #endif1608 1601 } 1609 } 1610 } 1602 #endif 1603 } 1604 } 1611 1605 1612 1606 //check if numrefidxes match the defaults. If not, override … … 2154 2148 Bool scalingListPredModeFlag; 2155 2149 2156 #if SCALING_LIST_OUTPUT_RESULT2157 Int startBit;2158 Int startTotalBit;2159 startBit = m_pcBitIf->getNumberOfWrittenBits();2160 startTotalBit = m_pcBitIf->getNumberOfWrittenBits();2161 #endif2162 2163 2150 //for each size 2164 2151 for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) … … 2166 2153 for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) 2167 2154 { 2168 #if SCALING_LIST_OUTPUT_RESULT2169 startBit = m_pcBitIf->getNumberOfWrittenBits();2170 #endif2171 2155 scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId ); 2172 2156 WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); … … 2179 2163 xCodeScalingList(scalingList, sizeId, listId); 2180 2164 } 2181 2182 #if SCALING_LIST_OUTPUT_RESULT 2183 printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit); 2184 #endif 2185 2186 } 2187 } 2188 #if SCALING_LIST_OUTPUT_RESULT 2189 printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit); 2190 #endif 2165 } 2166 } 2191 2167 return; 2192 2168 } … … 2203 2179 Int data; 2204 2180 Int *src = scalingList->getScalingListAddress(sizeId, listId); 2205 2206 2181 if( sizeId > SCALING_LIST_8x8 ) 2207 2182 { -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncCavlc.h
r442 r532 109 109 110 110 Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); 111 #if HM_CLEANUP_SAO 112 Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);} 113 #else 111 114 Void codeSAOSign ( UInt code ) { printf("Not supported\n"); assert (0); } 112 115 Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ){printf("Not supported\n"); assert (0);} … … 114 117 Void codeSaoTypeIdx ( UInt uiCode ){printf("Not supported\n"); assert (0);} 115 118 Void codeSaoUflc ( UInt uiLength, UInt uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);} 116 119 #endif 117 120 Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ); 118 121 Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncCfg.h
r531 r532 196 196 Int m_maxNumOffsetsPerPic; 197 197 Bool m_saoLcuBoundary; 198 #if !HM_CLEANUP_SAO 198 199 Bool m_saoLcuBasedOptimization; 199 200 #endif 200 201 //====== Lossless ======== 201 202 Bool m_useLossless; … … 328 329 Int m_TMVPModeId; 329 330 Int m_signHideFlag; 330 #if RATE_CONTROL_LAMBDA_DOMAIN331 331 Bool m_RCEnableRateControl; 332 332 Int m_RCTargetBitrate; 333 #if M0036_RC_IMPROVEMENT334 333 Int m_RCKeepHierarchicalBit; 335 #else336 Bool m_RCKeepHierarchicalBit;337 #endif338 334 Bool m_RCLCULevelRC; 339 335 Bool m_RCUseLCUSeparateModel; 340 336 Int m_RCInitialQP; 341 337 Bool m_RCForceIntraQP; 342 #else343 Bool m_enableRateCtrl; ///< Flag for using rate control algorithm344 Int m_targetBitrate; ///< target bitrate345 Int m_numLCUInUnit; ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit346 #endif347 338 Bool m_TransquantBypassEnableFlag; ///< transquant_bypass_enable_flag setting in PPS. 348 339 Bool m_CUTransquantBypassFlagValue; ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag. … … 638 629 Void setSaoLcuBoundary (Bool val) { m_saoLcuBoundary = val; } 639 630 Bool getSaoLcuBoundary () { return m_saoLcuBoundary; } 631 #if !HM_CLEANUP_SAO 640 632 Void setSaoLcuBasedOptimization (Bool val) { m_saoLcuBasedOptimization = val; } 641 633 Bool getSaoLcuBasedOptimization () { return m_saoLcuBasedOptimization; } 634 #endif 642 635 Void setLFCrossTileBoundaryFlag ( Bool val ) { m_loopFilterAcrossTilesEnabledFlag = val; } 643 636 Bool getLFCrossTileBoundaryFlag () { return m_loopFilterAcrossTilesEnabledFlag; } … … 815 808 Void setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; } 816 809 Int getSignHideFlag() { return m_signHideFlag; } 817 #if RATE_CONTROL_LAMBDA_DOMAIN818 810 Bool getUseRateCtrl () { return m_RCEnableRateControl; } 819 811 Void setUseRateCtrl ( Bool b ) { m_RCEnableRateControl = b; } 820 812 Int getTargetBitrate () { return m_RCTargetBitrate; } 821 813 Void setTargetBitrate ( Int bitrate ) { m_RCTargetBitrate = bitrate; } 822 #if M0036_RC_IMPROVEMENT823 814 Int getKeepHierBit () { return m_RCKeepHierarchicalBit; } 824 815 Void setKeepHierBit ( Int i ) { m_RCKeepHierarchicalBit = i; } 825 #else826 Bool getKeepHierBit () { return m_RCKeepHierarchicalBit; }827 Void setKeepHierBit ( Bool b ) { m_RCKeepHierarchicalBit = b; }828 #endif829 816 Bool getLCULevelRC () { return m_RCLCULevelRC; } 830 817 Void setLCULevelRC ( Bool b ) { m_RCLCULevelRC = b; } … … 835 822 Bool getForceIntraQP () { return m_RCForceIntraQP; } 836 823 Void setForceIntraQP ( Bool b ) { m_RCForceIntraQP = b; } 837 #else838 Bool getUseRateCtrl () { return m_enableRateCtrl; }839 Void setUseRateCtrl (Bool flag) { m_enableRateCtrl = flag; }840 Int getTargetBitrate () { return m_targetBitrate; }841 Void setTargetBitrate (Int target) { m_targetBitrate = target; }842 Int getNumLCUInUnit () { return m_numLCUInUnit; }843 Void setNumLCUInUnit (Int numLCUs) { m_numLCUInUnit = numLCUs; }844 #endif845 824 Bool getTransquantBypassEnableFlag() { return m_TransquantBypassEnableFlag; } 846 825 Void setTransquantBypassEnableFlag(Bool flag) { m_TransquantBypassEnableFlag = flag; } -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncCu.cpp
r524 r532 95 95 96 96 m_bEncodeDQP = false; 97 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT98 m_LCUPredictionSAD = 0;99 m_addSADDepth = 0;100 m_temporalSAD = 0;101 #endif102 97 103 98 // initialize partition order. … … 243 238 m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); 244 239 m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); 245 246 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT247 m_addSADDepth = 0;248 m_LCUPredictionSAD = 0;249 m_temporalSAD = 0;250 #endif251 240 252 241 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI … … 433 422 } 434 423 435 #if RATE_CONTROL_LAMBDA_DOMAIN436 424 if ( m_pcEncCfg->getUseRateCtrl() ) 437 425 { … … 439 427 iMaxQP = m_pcRateCtrl->getRCQP(); 440 428 } 441 #else442 if(m_pcEncCfg->getUseRateCtrl())443 {444 Int qp = m_pcRateCtrl->getUnitQP();445 iMinQP = Clip3( MIN_QP, MAX_QP, qp);446 iMaxQP = Clip3( MIN_QP, MAX_QP, qp);447 }448 #endif449 429 450 430 // If slice start or slice end is within this cu... … … 538 518 } 539 519 } 540 541 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT542 if ( uiDepth <= m_addSADDepth )543 {544 m_LCUPredictionSAD += m_temporalSAD;545 m_addSADDepth = uiDepth;546 }547 #endif548 520 549 521 if(!earlyDetectionSkipMode) … … 796 768 { 797 769 bBoundary = true; 798 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT799 m_addSADDepth++;800 #endif801 770 } 802 771 … … 842 811 iMaxQP = iStartQP; 843 812 } 844 #if RATE_CONTROL_LAMBDA_DOMAIN845 813 if ( m_pcEncCfg->getUseRateCtrl() ) 846 814 { … … 848 816 iMaxQP = m_pcRateCtrl->getRCQP(); 849 817 } 850 #else851 if(m_pcEncCfg->getUseRateCtrl())852 {853 Int qp = m_pcRateCtrl->getUnitQP();854 iMinQP = Clip3( MIN_QP, MAX_QP, qp);855 iMaxQP = Clip3( MIN_QP, MAX_QP, qp);856 }857 #endif858 818 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 859 819 { … … 1250 1210 } 1251 1211 1252 #if RATE_CONTROL_INTRA1253 1212 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 1254 1213 { … … 1365 1324 return(iSumHad); 1366 1325 } 1367 #endif1368 1326 1369 1327 /** check RD costs for a CU block encoded with merge … … 1542 1500 #endif 1543 1501 1544 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT1545 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )1546 {1547 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),1548 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),1549 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );1550 m_temporalSAD = (Int)SAD;1551 }1552 #endif1553 1554 1502 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 1555 1503 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); … … 1582 1530 1583 1531 m_pcEntropyCoder->resetBits(); 1584 1585 1532 if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) 1586 1533 { … … 1636 1583 1637 1584 m_pcEntropyCoder->resetBits(); 1638 1639 1585 if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) 1640 1586 { -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncCu.h
r524 r532 103 103 Bool m_bUseSBACRD; 104 104 TEncRateCtrl* m_pcRateCtrl; 105 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT 106 UInt m_LCUPredictionSAD; 107 Int m_addSADDepth; 108 Int m_temporalSAD; 109 #endif 105 110 106 #if N0383_IL_CONSTRAINED_TILE_SETS_SEI 111 107 Bool m_disableILP; … … 128 124 129 125 Void setBitCounter ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; } 130 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT131 UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }132 #endif133 #if RATE_CONTROL_INTRA134 126 Int updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height ); 135 #endif136 137 127 protected: 138 128 Void finishCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncEntropy.cpp
r494 r532 51 51 Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) 52 52 { 53 #if !HM_CLEANUP_SAO 53 54 if (pcSlice->getSPS()->getUseSAO()) 54 55 { … … 59 60 } 60 61 } 61 62 #endif 62 63 m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); 63 64 return; … … 638 639 } 639 640 641 #if !HM_CLEANUP_SAO 640 642 /** Encode SAO Offset 641 643 * \param saoLcuParam SAO LCU paramters … … 731 733 } 732 734 735 #endif 736 733 737 Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) 734 738 { -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncEntropy.h
r345 r532 105 105 virtual Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0; 106 106 virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0; 107 #if HM_CLEANUP_SAO 108 virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false) =0; 109 #else 107 110 virtual Void codeSAOSign ( UInt code ) = 0; 108 111 virtual Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) = 0; … … 110 113 virtual Void codeSaoTypeIdx ( UInt uiCode) = 0; 111 114 virtual Void codeSaoUflc ( UInt uiLength, UInt uiCode ) = 0; 115 #endif 112 116 virtual Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0; 113 117 … … 188 192 189 193 Void estimateBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType); 194 #if HM_CLEANUP_SAO 195 Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);} 196 #else 190 197 Void encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx); 191 198 Void encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp); 199 #endif 192 200 static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ); 193 201 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
r531 r532 971 971 pcSlice->getRPS()->setNumberOfLongtermPictures(0); 972 972 973 #if FIX1071974 973 if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) 975 974 { 976 975 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); 977 976 } 978 #else979 if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)980 {981 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());982 }983 #endif984 977 pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); 985 978 … … 999 992 { 1000 993 if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) || 1001 ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_T LA_R )994 ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ) 1002 995 ) 1003 996 { … … 1008 1001 else 1009 1002 { 1010 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_T LA_R );1003 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R ); 1011 1004 } 1012 1005 oneRefLayerTSA = true; … … 1040 1033 else 1041 1034 { 1042 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_T LA_R );1035 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R ); 1043 1036 } 1044 1037 } … … 1051 1044 else 1052 1045 { 1053 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_T LA_R);1046 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); 1054 1047 } 1055 1048 #endif … … 1421 1414 pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); 1422 1415 1423 #if RATE_CONTROL_LAMBDA_DOMAIN1424 1416 Double lambda = 0.0; 1425 1417 Int actualHeadBits = 0; … … 1454 1446 else if ( frameLevel == 0 ) // intra case, but use the model 1455 1447 { 1456 #if RATE_CONTROL_INTRA1457 1448 m_pcSliceEncoder->calCostSliceI(pcPic); 1458 #endif1459 1449 if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case 1460 1450 { 1461 1451 Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); 1462 #if RATE_CONTROL_INTRA1463 1452 bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); 1464 #else1465 bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );1466 #endif1467 1453 if ( bits < 200 ) 1468 1454 { … … 1473 1459 1474 1460 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 1475 #if RATE_CONTROL_INTRA1476 1461 m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); 1477 1462 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 1478 #else1479 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );1480 #endif1481 1463 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 1482 1464 } … … 1484 1466 { 1485 1467 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 1486 #if RATE_CONTROL_INTRA1487 1468 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 1488 #else1489 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );1490 #endif1491 1469 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 1492 1470 } … … 1501 1479 m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); 1502 1480 } 1503 #endif1504 1481 1505 1482 UInt uiNumSlices = 1; … … 1712 1689 1713 1690 // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas 1691 #if HM_CLEANUP_SAO 1692 if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() ) 1693 { 1694 m_pcSAO->getPreDBFStatistics(pcPic); 1695 } 1696 #else 1714 1697 if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) 1715 1698 { … … 1717 1700 m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); 1718 1701 } 1719 1702 #endif 1720 1703 //-- Loop filter 1721 1704 Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); … … 1727 1710 m_pcLoopFilter->loopFilterPic( pcPic ); 1728 1711 1712 #if !HM_CLEANUP_SAO 1729 1713 pcSlice = pcPic->getSlice(0); 1730 1714 if(pcSlice->getSPS()->getUseSAO()) … … 1746 1730 m_pcSAO->createPicSaoInfo(pcPic); 1747 1731 } 1748 1732 #endif 1749 1733 /////////////////////////////////////////////////////////////////////////////////////////////////// File writing 1750 1734 // Set entropy coder … … 1778 1762 writeRBSPTrailingBits(nalu.m_Bitstream); 1779 1763 accessUnit.push_back(new NALUnitEBSP(nalu)); 1780 #if RATE_CONTROL_LAMBDA_DOMAIN1781 1764 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1782 #endif1783 1765 #if SVC_EXTENSION 1784 1766 } … … 1821 1803 writeRBSPTrailingBits(nalu.m_Bitstream); 1822 1804 accessUnit.push_back(new NALUnitEBSP(nalu)); 1823 #if RATE_CONTROL_LAMBDA_DOMAIN1824 1805 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1825 #endif1826 1806 1827 1807 #if SVC_EXTENSION … … 1837 1817 writeRBSPTrailingBits(nalu.m_Bitstream); 1838 1818 accessUnit.push_back(new NALUnitEBSP(nalu)); 1839 #if RATE_CONTROL_LAMBDA_DOMAIN1840 1819 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1841 #endif1842 1820 1843 1821 xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS()); … … 2159 2137 } 2160 2138 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 2161 #if RATE_CONTROL_LAMBDA_DOMAIN2162 2139 tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); 2163 #endif2164 2165 2140 m_pcEntropyCoder->encodeSliceHeader(pcSlice); 2166 2167 #if RATE_CONTROL_LAMBDA_DOMAIN2168 2141 actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); 2169 #endif2170 2142 2171 2143 // is it needed? … … 2288 2260 xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); 2289 2261 accessUnit.push_back(new NALUnitEBSP(nalu)); 2290 #if RATE_CONTROL_LAMBDA_DOMAIN2291 2262 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 2292 #endif2293 2263 bNALUAlignedWrittenToList = true; 2294 2264 uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment … … 2338 2308 m_pcEntropyCoder->resetEntropy(); 2339 2309 m_pcEntropyCoder->setBitstream( m_pcBitCounter ); 2310 #if HM_CLEANUP_SAO 2311 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 2312 m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); 2313 m_pcSAO->SAOProcess(pcPic 2314 , sliceEnabled 2315 , pcPic->getSlice(0)->getLambdas() 2316 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 2317 , m_pcCfg->getSaoLcuBoundary() 2318 #endif 2319 ); 2320 m_pcSAO->PCMLFDisableProcess(pcPic); 2321 2322 //assign SAO slice header 2323 for(Int s=0; s< uiNumSlices; s++) 2324 { 2325 pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]); 2326 assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]); 2327 pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]); 2328 } 2329 #else 2340 2330 m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); 2341 2331 SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); 2342 2332 2343 #if SAO_CHROMA_LAMBDA2344 2333 #if SAO_ENCODING_CHOICE 2345 2334 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); … … 2347 2336 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); 2348 2337 #endif 2349 #else2350 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda());2351 #endif2352 2338 m_pcSAO->endSaoEnc(); 2353 2339 m_pcSAO->PCMLFDisableProcess(pcPic); 2340 #endif 2354 2341 } 2342 #if !HM_CLEANUP_SAO 2355 2343 #if SAO_RDO 2356 2344 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); 2357 2345 #endif 2346 #endif 2358 2347 processingState = ENCODE_SLICE; 2348 #if !HM_CLEANUP_SAO 2359 2349 #if HIGHER_LAYER_IRAP_SKIP_FLAG 2360 2350 if ( ( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) ) … … 2371 2361 } 2372 2362 } 2363 #endif 2373 2364 } 2374 2365 break; … … 2381 2372 } 2382 2373 } // end iteration over slices 2383 2374 #if !HM_CLEANUP_SAO 2384 2375 if(pcSlice->getSPS()->getUseSAO()) 2385 2376 { … … 2390 2381 pcPic->destroyNonDBFilterInfo(); 2391 2382 } 2392 2383 #endif 2393 2384 pcPic->compressMotion(); 2394 2385 … … 2490 2481 } 2491 2482 } 2492 #if RATE_CONTROL_LAMBDA_DOMAIN2493 2483 if ( m_pcCfg->getUseRateCtrl() ) 2494 2484 { 2495 #if !M0036_RC_IMPROVEMENT2496 Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();2497 #endif2498 2485 Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); 2499 2486 Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); … … 2502 2489 avgLambda = lambda; 2503 2490 } 2504 #if M0036_RC_IMPROVEMENT2505 #if RATE_CONTROL_INTRA2506 2491 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); 2507 #else2508 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );2509 #endif2510 #else2511 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );2512 #endif2513 2492 m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); 2514 2493 … … 2523 2502 } 2524 2503 } 2525 #else2526 if(m_pcCfg->getUseRateCtrl())2527 {2528 UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];2529 m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());2530 }2531 #endif2532 2504 2533 2505 if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && … … 2714 2686 delete[] pcSubstreamsOut; 2715 2687 } 2716 #if !RATE_CONTROL_LAMBDA_DOMAIN2717 if(m_pcCfg->getUseRateCtrl())2718 {2719 m_pcRateCtrl->updateRCGOPStatus();2720 }2721 #endif2722 2688 delete pcBitstreamRedirect; 2723 2689 … … 2802 2768 m_pcEntropyCoder->resetEntropy (); 2803 2769 m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); 2770 #if !HM_CLEANUP_SAO 2804 2771 pcSlice = pcPic->getSlice(0); 2805 2772 if(pcSlice->getSPS()->getUseSAO()) … … 2816 2783 pcPic->destroyNonDBFilterInfo(); 2817 2784 } 2818 2785 #endif 2819 2786 m_pcEntropyCoder->resetEntropy (); 2820 2787 ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); … … 2888 2855 iterPicYuvRec--; 2889 2856 } 2857 2890 2858 } 2891 2859 … … 2983 2951 case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; 2984 2952 case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; 2985 case NAL_UNIT_CODED_SLICE_T LA_R: return "TLA_R";2953 case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R"; 2986 2954 case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; 2987 2955 case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; … … 3218 3186 for (Int x = 0; x < width; x++) 3219 3187 { 3220 dst[x] = isTff ? (UChar) top[x] : (UChar)bottom[x];3221 dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar)top[x];3188 dst[x] = isTff ? top[x] : bottom[x]; 3189 dst[stride+x] = isTff ? bottom[x] : top[x]; 3222 3190 } 3223 3191 top += stride; … … 3376 3344 delete pcRecInterlaced; 3377 3345 } 3346 3347 3378 3348 3379 3349 /** Function for deciding the nal_unit_type. -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncRateCtrl.cpp
r313 r532 42 42 using namespace std; 43 43 44 #if RATE_CONTROL_LAMBDA_DOMAIN45 46 44 //sequence level 47 45 TEncRCSeq::TEncRCSeq() … … 67 65 m_bitsLeft = 0; 68 66 m_useLCUSeparateModel = false; 69 #if M0036_RC_IMPROVEMENT70 67 m_adaptiveBit = 0; 71 68 m_lastLambda = 0.0; 72 #endif73 69 } 74 70 … … 78 74 } 79 75 80 #if M0036_RC_IMPROVEMENT81 76 Void 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 #else83 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )84 #endif85 77 { 86 78 destroy(); … … 109 101 m_betaUpdate = 0.025; 110 102 } 111 #if M0036_RC_IMPROVEMENT112 103 else if ( m_seqTargetBpp < 0.2 ) 113 104 { … … 125 116 m_betaUpdate = 0.2; 126 117 } 127 #else128 else129 {130 m_alphaUpdate = 0.1;131 m_betaUpdate = 0.05;132 }133 #endif134 118 m_averageBits = (Int)(m_targetBits / totalFrames); 135 119 Int picWidthInBU = ( m_picWidth % m_LCUWidth ) == 0 ? m_picWidth / m_LCUWidth : m_picWidth / m_LCUWidth + 1; … … 172 156 m_framesLeft = m_totalFrames; 173 157 m_bitsLeft = m_targetBits; 174 #if M0036_RC_IMPROVEMENT175 158 m_adaptiveBit = adaptiveBit; 176 159 m_lastLambda = 0.0; 177 #endif178 160 } 179 161 … … 233 215 for ( Int i=0; i<m_numberOfLevel; i++ ) 234 216 { 235 #if RATE_CONTROL_INTRA236 217 if (i>0) 237 218 { … … 244 225 m_picPara[i].m_beta = BETA2; 245 226 } 246 #else247 m_picPara[i].m_alpha = 3.2003;248 m_picPara[i].m_beta = -1.367;249 #endif250 227 } 251 228 } … … 271 248 for ( Int j=0; j<m_numberOfLCU; j++) 272 249 { 273 #if RATE_CONTROL_INTRA274 250 m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha; 275 251 m_LCUPara[i][j].m_beta = m_picPara[i].m_beta; 276 #else277 m_LCUPara[i][j].m_alpha = 3.2003;278 m_LCUPara[i][j].m_beta = -1.367;279 #endif280 252 } 281 253 } … … 299 271 } 300 272 301 #if !RATE_CONTROL_INTRA302 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 #endif316 317 #if M0036_RC_IMPROVEMENT318 273 Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB ) 319 274 { … … 326 281 delete[] bitsRatio; 327 282 } 328 #endif329 283 330 284 //GOP level … … 349 303 Int targetBits = xEstGOPTargetBits( encRCSeq, numPic ); 350 304 351 #if M0036_RC_IMPROVEMENT352 305 if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 ) 353 306 { … … 409 362 delete []equaCoeffB; 410 363 } 411 #endif412 364 413 365 m_picTargetBitInGOP = new Int[numPic]; … … 422 374 { 423 375 currPicRatio = encRCSeq->getBitRatio( i ); 424 #if M0036_RC_IMPROVEMENT425 376 m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio ); 426 #else427 m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;428 #endif429 377 } 430 378 … … 436 384 } 437 385 438 #if M0036_RC_IMPROVEMENT439 386 Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ) 440 387 { … … 482 429 return solution; 483 430 } 484 #endif485 431 486 432 Void TEncRCGOP::destroy() … … 534 480 535 481 m_LCUs = NULL; 536 #if !M0036_RC_IMPROVEMENT537 m_lastPicture = NULL;538 #endif539 482 m_picActualHeaderBits = 0; 540 #if !M0036_RC_IMPROVEMENT541 m_totalMAD = 0.0;542 #endif543 483 m_picActualBits = 0; 544 484 m_picQP = 0; … … 565 505 } 566 506 567 #if M0036_RC_IMPROVEMENT568 507 targetBits = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio ); 569 #else570 targetBits = Int( GOPbitsLeft * currPicRatio / totalPicRatio );571 #endif572 508 573 509 if ( targetBits < 100 ) … … 665 601 m_LCUs[LCUIdx].m_lambda = 0.0; 666 602 m_LCUs[LCUIdx].m_targetBits = 0; 667 #if M0036_RC_IMPROVEMENT668 603 m_LCUs[LCUIdx].m_bitWeight = 1.0; 669 #else670 m_LCUs[LCUIdx].m_MAD = 0.0;671 #endif672 604 Int currWidth = ( (i == picWidthInLCU -1) ? picWidth - LCUWidth *(picWidthInLCU -1) : LCUWidth ); 673 605 Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight ); … … 676 608 } 677 609 m_picActualHeaderBits = 0; 678 #if !M0036_RC_IMPROVEMENT679 m_totalMAD = 0.0;680 #endif681 610 m_picActualBits = 0; 682 611 m_picQP = 0; 683 612 m_picLambda = 0.0; 684 685 #if !M0036_RC_IMPROVEMENT686 m_lastPicture = NULL;687 list<TEncRCPic*>::reverse_iterator it;688 for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )689 {690 if ( (*it)->getFrameLevel() == m_frameLevel )691 {692 m_lastPicture = (*it);693 break;694 }695 }696 #endif697 613 } 698 614 … … 709 625 710 626 711 #if RATE_CONTROL_INTRA712 627 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType) 713 #else714 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )715 #endif716 628 { 717 629 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 718 630 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 719 631 Double bpp = (Double)m_targetBits/(Double)m_numberOfPixel; 720 #if RATE_CONTROL_INTRA721 632 Double estLambda; 722 633 if (eSliceType == I_SLICE) … … 728 639 estLambda = alpha * pow( bpp, beta ); 729 640 } 730 #else731 Double estLambda = alpha * pow( bpp, beta );732 #endif733 641 734 642 Double lastLevelLambda = -1.0; … … 778 686 m_estPicLambda = estLambda; 779 687 780 #if M0036_RC_IMPROVEMENT781 688 Double totalWeight = 0.0; 782 689 // initial BU bit allocation weight 783 690 for ( Int i=0; i<m_numberOfLCU; i++ ) 784 691 { 785 #if RC_FIX786 692 Double alphaLCU, betaLCU; 787 693 if ( m_encRCSeq->getUseLCUSeparateModel() ) … … 795 701 betaLCU = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 796 702 } 797 #else798 Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;799 Double betaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;800 #endif801 703 802 704 m_LCUs[i].m_bitWeight = m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU ); … … 813 715 m_LCUs[i].m_bitWeight = BUTargetBits; 814 716 } 815 #endif816 717 817 718 return estLambda; … … 856 757 } 857 758 858 #if RATE_CONTROL_INTRA859 759 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 860 #else861 Double TEncRCPic::getLCUTargetBpp()862 #endif863 760 { 864 761 Int LCUIdx = getLCUCoded(); 865 762 Double bpp = -1.0; 866 763 Int avgBits = 0; 867 #if !M0036_RC_IMPROVEMENT 868 Double totalMAD = -1.0; 869 Double MAD = -1.0; 870 #endif 871 872 #if RATE_CONTROL_INTRA 873 if (eSliceType == I_SLICE){ 764 765 if (eSliceType == I_SLICE) 766 { 874 767 Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1; 875 768 Int bitrateWindow = min(4,noOfLCUsLeft); … … 889 782 else 890 783 { 891 #endif892 #if M0036_RC_IMPROVEMENT893 784 Double totalWeight = 0; 894 785 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ ) … … 898 789 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() ); 899 790 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 ); 900 #else 901 if ( m_lastPicture == NULL ) 902 { 903 avgBits = Int( m_bitsLeft / m_LCULeft ); 904 } 905 else 906 { 907 MAD = m_lastPicture->getLCU(LCUIdx).m_MAD; 908 totalMAD = m_lastPicture->getTotalMAD(); 909 for ( Int i=0; i<LCUIdx; i++ ) 910 { 911 totalMAD -= m_lastPicture->getLCU(i).m_MAD; 912 } 913 914 if ( totalMAD > 0.1 ) 915 { 916 avgBits = Int( m_bitsLeft * MAD / totalMAD ); 917 } 918 else 919 { 920 avgBits = Int( m_bitsLeft / m_LCULeft ); 921 } 922 } 923 #endif 924 #if RATE_CONTROL_INTRA 925 } 926 #endif 791 } 927 792 928 793 if ( avgBits < 1 ) … … 1050 915 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1051 916 1052 #if M0036_RC_IMPROVEMENT1053 917 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1054 918 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1055 #else1056 alpha = Clip3( 0.05, 20.0, alpha );1057 beta = Clip3( -3.0, -0.1, beta );1058 #endif1059 919 1060 920 TRCParameter rcPara; … … 1069 929 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1070 930 double lnbpp = log( bpp ); 1071 #if M0036_RC_IMPROVEMENT1072 931 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1073 #else1074 lnbpp = Clip3( -5.0, 1.0, lnbpp );1075 #endif1076 932 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1077 933 1078 #if M0036_RC_IMPROVEMENT1079 934 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1080 935 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1081 #else1082 alpha = Clip3( 0.05, 20.0, alpha );1083 beta = Clip3( -3.0, -0.1, beta );1084 #endif1085 936 TRCParameter rcPara; 1086 937 rcPara.m_alpha = alpha; … … 1090 941 } 1091 942 1092 #if !M0036_RC_IMPROVEMENT1093 Double TEncRCPic::getEffectivePercentage()1094 {1095 Int effectivePiexels = 0;1096 Int totalPixels = 0;1097 1098 for ( Int i=0; i<m_numberOfLCU; i++ )1099 {1100 totalPixels += m_LCUs[i].m_numberOfPixel;1101 if ( m_LCUs[i].m_QP > 0 )1102 {1103 effectivePiexels += m_LCUs[i].m_numberOfPixel;1104 }1105 }1106 1107 Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;1108 return effectivePixelPercentage;1109 }1110 #endif1111 1112 943 Double TEncRCPic::calAverageQP() 1113 944 { … … 1164 995 } 1165 996 1166 #if M0036_RC_IMPROVEMENT1167 #if RATE_CONTROL_INTRA1168 997 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType) 1169 #else1170 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )1171 #endif1172 #else1173 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )1174 #endif1175 998 { 1176 999 m_picActualHeaderBits = actualHeaderBits; … … 1185 1008 } 1186 1009 m_picLambda = averageLambda; 1187 #if !M0036_RC_IMPROVEMENT1188 for ( Int i=0; i<m_numberOfLCU; i++ )1189 {1190 m_totalMAD += m_LCUs[i].m_MAD;1191 }1192 #endif1193 1010 1194 1011 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 1195 1012 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 1196 #if RATE_CONTROL_INTRA1197 1013 if (eSliceType == I_SLICE) 1198 1014 { … … 1201 1017 else 1202 1018 { 1203 #endif1204 1019 // update parameters 1205 1020 Double picActualBits = ( Double )m_picActualBits; … … 1208 1023 Double inputLambda = m_picLambda; 1209 1024 1210 #if M0036_RC_IMPROVEMENT1211 1025 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 ) 1212 #else1213 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )1214 #endif1215 1026 { 1216 1027 alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 ); 1217 1028 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1218 1029 1219 #if M0036_RC_IMPROVEMENT1220 1030 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1221 1031 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1222 #else1223 alpha = Clip3( 0.05, 20.0, alpha );1224 beta = Clip3( -3.0, -0.1, beta );1225 #endif1226 1032 TRCParameter rcPara; 1227 1033 rcPara.m_alpha = alpha; … … 1235 1041 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1236 1042 double lnbpp = log( picActualBpp ); 1237 #if M0036_RC_IMPROVEMENT1238 1043 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1239 #else1240 lnbpp = Clip3( -5.0, 1.0, lnbpp );1241 #endif1242 1044 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1243 1045 1244 #if M0036_RC_IMPROVEMENT1245 1046 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1246 1047 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1247 #else 1248 alpha = Clip3( 0.05, 20.0, alpha ); 1249 beta = Clip3( -3.0, -0.1, beta ); 1250 #endif 1251 #if RATE_CONTROL_INTRA 1252 } 1253 #endif 1048 } 1254 1049 1255 1050 TRCParameter rcPara; … … 1259 1054 m_encRCSeq->setPicPara( m_frameLevel, rcPara ); 1260 1055 1261 #if M0036_RC_IMPROVEMENT1262 1056 if ( m_frameLevel == 1 ) 1263 1057 { … … 1266 1060 m_encRCSeq->setLastLambda( updateLastLambda ); 1267 1061 } 1268 #endif 1269 } 1270 1271 #if RATE_CONTROL_INTRA 1062 } 1063 1272 1064 Int TEncRCPic::getRefineBitsForIntra( Int orgBits ) 1273 1065 { … … 1358 1150 return estLambda; 1359 1151 } 1360 #endif1361 1152 1362 1153 TEncRateCtrl::TEncRateCtrl() … … 1392 1183 } 1393 1184 1394 #if M0036_RC_IMPROVEMENT1395 1185 Void 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] ) 1396 #else1397 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] )1398 #endif1399 1186 { 1400 1187 destroy(); … … 1411 1198 1412 1199 Int numberOfLevel = 1; 1413 #if M0036_RC_IMPROVEMENT1414 1200 Int adaptiveBit = 0; 1415 1201 if ( keepHierBits > 0 ) 1416 #else1417 if ( keepHierBits )1418 #endif1419 1202 { 1420 1203 numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1; … … 1439 1222 } 1440 1223 1441 #if M0036_RC_IMPROVEMENT1442 1224 if ( keepHierBits > 0 ) 1443 #else1444 if ( keepHierBits )1445 #endif1446 1225 { 1447 1226 Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) ); … … 1476 1255 bitsRatio[3] = 14; 1477 1256 } 1478 #if M0036_RC_IMPROVEMENT1479 1257 if ( keepHierBits == 2 ) 1480 1258 { 1481 1259 adaptiveBit = 1; 1482 1260 } 1483 #endif1484 1261 } 1485 1262 else if ( GOPSize == 8 && !isLowdelay ) … … 1529 1306 bitsRatio[7] = 1; 1530 1307 } 1531 #if M0036_RC_IMPROVEMENT1532 1308 if ( keepHierBits == 2 ) 1533 1309 { 1534 1310 adaptiveBit = 2; 1535 1311 } 1536 #endif1537 1312 } 1538 1313 else 1539 1314 { 1540 #if M0036_RC_IMPROVEMENT1541 1315 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" ); 1542 #else1543 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );1544 #endif1545 1316 } 1546 1317 } … … 1555 1326 } 1556 1327 } 1557 #if M0036_RC_IMPROVEMENT1558 1328 if ( keepHierBits > 0 ) 1559 #else1560 if ( keepHierBits )1561 #endif1562 1329 { 1563 1330 if ( GOPSize == 4 && isLowdelay ) … … 1594 1361 1595 1362 m_encRCSeq = new TEncRCSeq; 1596 #if M0036_RC_IMPROVEMENT1597 1363 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit ); 1598 #else1599 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );1600 #endif1601 1364 m_encRCSeq->initBitsRatio( bitsRatio ); 1602 1365 m_encRCSeq->initGOPID2Level( GOPID2Level ); … … 1629 1392 } 1630 1393 1631 #else1632 1633 #define ADJUSTMENT_FACTOR 0.601634 #define HIGH_QSTEP_THRESHOLD 9.52381635 #define HIGH_QSTEP_ALPHA 4.93711636 #define HIGH_QSTEP_BETA 0.09221637 #define LOW_QSTEP_ALPHA 16.74291638 #define LOW_QSTEP_BETA -1.14941639 1640 #define MAD_PRED_Y1 1.01641 #define MAD_PRED_Y2 0.01642 1643 enum MAD_HISOTRY {1644 MAD_PPPrevious = 0,1645 MAD_PPrevious = 1,1646 MAD_Previous = 21647 };1648 1649 Void MADLinearModel::initMADLinearModel()1650 {1651 m_activeOn = false;1652 m_paramY1 = 1.0;1653 m_paramY2 = 0.0;1654 m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;1655 }1656 1657 Double MADLinearModel::getMAD()1658 {1659 Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;1660 1661 if(costPredMAD < 0)1662 {1663 costPredMAD = m_costMADs[MAD_Previous];1664 m_paramY1 = MAD_PRED_Y1;1665 m_paramY2 = MAD_PRED_Y2;1666 }1667 return costPredMAD;1668 }1669 1670 Void MADLinearModel::updateMADLiearModel()1671 {1672 Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));1673 Double dNewY2 = (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));1674 1675 m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;1676 m_paramY2 = 0.20*m_paramY2+ 0.10*dNewY2;1677 }1678 1679 Void MADLinearModel::updateMADHistory(Double dMAD)1680 {1681 m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];1682 m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];1683 m_costMADs[MAD_Previous ] = dMAD;1684 m_activeOn = (m_costMADs[MAD_Previous ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);1685 }1686 1687 1688 Void PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()1689 {1690 m_paramHighX1 = HIGH_QSTEP_ALPHA;1691 m_paramHighX2 = HIGH_QSTEP_BETA;1692 m_paramLowX1 = LOW_QSTEP_ALPHA;1693 m_paramLowX2 = LOW_QSTEP_BETA;1694 }1695 1696 Int PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)1697 {1698 Double qStep;1699 Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));1700 1701 if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)1702 {1703 qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));1704 }1705 else1706 {1707 qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));1708 }1709 1710 return xConvertQStep2QP(qStep);1711 }1712 1713 Void PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)1714 {1715 Double qStep = xConvertQP2QStep(qp);1716 Double invqStep = (1/qStep);1717 Double paramNewX1, paramNewX2;1718 1719 if(qStep >= HIGH_QSTEP_THRESHOLD)1720 {1721 paramNewX2 = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));1722 paramNewX1 = (23.3772-200*paramNewX2);1723 m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;1724 m_paramHighX2 = 0.70*HIGH_QSTEP_BETA + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;1725 }1726 else1727 {1728 paramNewX2 = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));1729 paramNewX1 = (5.8091-9.5455*paramNewX2);1730 m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;1731 m_paramLowX2 = 0.90*LOW_QSTEP_BETA + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;1732 }1733 }1734 1735 Bool PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )1736 {1737 Double qStep = xConvertQP2QStep(qpReference);1738 1739 if (qStep > xConvertQP2QStep(MAX_QP)1740 ||qStep < xConvertQP2QStep(MIN_QP) )1741 {1742 return false;1743 }1744 1745 return true;1746 }1747 1748 Double PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )1749 {1750 Int i;1751 Double qStep;1752 static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };1753 1754 qStep = mapQP2QSTEP[qp % 6];1755 for( i=0; i<(qp/6); i++)1756 {1757 qStep *= 2;1758 }1759 1760 return qStep;1761 }1762 1763 Int PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )1764 {1765 Int per = 0, rem = 0;1766 1767 if( qStep < xConvertQP2QStep(MIN_QP))1768 {1769 return MIN_QP;1770 }1771 else if (qStep > xConvertQP2QStep(MAX_QP) )1772 {1773 return MAX_QP;1774 }1775 1776 while( qStep > xConvertQP2QStep(5) )1777 {1778 qStep /= 2.0;1779 per++;1780 }1781 1782 if (qStep <= 0.625)1783 {1784 rem = 0;1785 }1786 else if (qStep <= 0.703)1787 {1788 rem = 1;1789 }1790 else if (qStep <= 0.797)1791 {1792 rem = 2;1793 }1794 else if (qStep <= 0.891)1795 {1796 rem = 3;1797 }1798 else if (qStep <= 1.000)1799 {1800 rem = 4;1801 }1802 else1803 {1804 rem = 5;1805 }1806 return (per * 6 + rem);1807 }1808 1809 1810 Void TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)1811 {1812 Int leftInHeight, leftInWidth;1813 1814 m_sourceWidthInLCU = (sourceWidth / maxCUWidth ) + (( sourceWidth % maxCUWidth ) ? 1 : 0);1815 m_sourceHeightInLCU = (sourceHeight / maxCUHeight) + (( sourceHeight % maxCUHeight) ? 1 : 0);1816 m_isLowdelay = (sizeIntraPeriod == -1) ? true : false;1817 m_prevBitrate = ( targetKbps << 10 ); // in units of 1,024 bps1818 m_currBitrate = ( targetKbps << 10 );1819 m_frameRate = frameRate;1820 m_refFrameNum = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);1821 m_nonRefFrameNum = sizeGOP-m_refFrameNum;1822 m_sizeGOP = sizeGOP;1823 m_numOfPixels = ((sourceWidth*sourceHeight*3)>>1);1824 m_indexGOP = 0;1825 m_indexFrame = 0;1826 m_indexLCU = 0;1827 m_indexUnit = 0;1828 m_indexRefFrame = 0;1829 m_indexNonRefFrame = 0;1830 m_occupancyVB = 0;1831 m_initialOVB = 0;1832 m_targetBufLevel = 0;1833 m_initialTBL = 0;1834 m_occupancyVBInFrame = 0;1835 m_remainingBitsInGOP = (m_currBitrate*sizeGOP/m_frameRate);1836 m_remainingBitsInFrame = 0;1837 m_numUnitInFrame = m_sourceWidthInLCU*m_sourceHeightInLCU;1838 m_cMADLinearModel. initMADLinearModel();1839 m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();1840 1841 m_costRefAvgWeighting = 0.0;1842 m_costNonRefAvgWeighting = 0.0;1843 m_costAvgbpp = 0.0;1844 m_activeUnitLevelOn = false;1845 1846 m_pcFrameData = new FrameData [sizeGOP+1]; initFrameData(qp);1847 m_pcLCUData = new LCUData [m_numUnitInFrame]; initUnitData (qp);1848 1849 for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight)1850 {1851 leftInHeight = sourceHeight - i;1852 leftInHeight = min(leftInHeight, maxCUHeight);1853 for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)1854 {1855 leftInWidth = sourceWidth - j;1856 leftInWidth = min(leftInWidth, maxCUWidth);1857 m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;1858 m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;1859 m_pcLCUData[addressUnit].m_pixels = ((leftInHeight*leftInWidth*3)>>1);1860 }1861 }1862 }1863 1864 Void TEncRateCtrl::destroy()1865 {1866 if(m_pcFrameData)1867 {1868 delete [] m_pcFrameData;1869 m_pcFrameData = NULL;1870 }1871 if(m_pcLCUData)1872 {1873 delete [] m_pcLCUData;1874 m_pcLCUData = NULL;1875 }1876 }1877 1878 Void TEncRateCtrl::initFrameData (Int qp)1879 {1880 for(Int i = 0 ; i <= m_sizeGOP; i++)1881 {1882 m_pcFrameData[i].m_isReferenced = false;1883 m_pcFrameData[i].m_costMAD = 0.0;1884 m_pcFrameData[i].m_bits = 0;1885 m_pcFrameData[i].m_qp = qp;1886 }1887 }1888 1889 Void TEncRateCtrl::initUnitData (Int qp)1890 {1891 for(Int i = 1 ; i < m_numUnitInFrame; i++)1892 {1893 m_pcLCUData[i].m_qp = qp;1894 m_pcLCUData[i].m_bits = 0;1895 m_pcLCUData[i].m_pixels = 0;1896 m_pcLCUData[i].m_widthInPixel = 0;1897 m_pcLCUData[i].m_heightInPixel = 0;1898 m_pcLCUData[i].m_costMAD = 0.0;1899 }1900 }1901 1902 Int TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)1903 {1904 Int numofReferenced = 0;1905 Int finalQP = 0;1906 FrameData* pcFrameData;1907 1908 m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);1909 pcFrameData = &m_pcFrameData[m_indexPOCInGOP];1910 1911 if(m_indexFrame != 0)1912 {1913 if(isReferenced)1914 {1915 Double gamma = m_isLowdelay ? 0.5 : 0.25;1916 Double beta = m_isLowdelay ? 0.9 : 0.6;1917 Int numRemainingRefFrames = m_refFrameNum - m_indexRefFrame;1918 Int numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;1919 1920 Double targetBitsOccupancy = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));1921 Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));1922 1923 m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);1924 1925 if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)1926 {1927 finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;1928 }1929 else1930 {1931 Double costPredMAD = m_cMADLinearModel.getMAD();1932 Int qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;1933 Int qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;1934 finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);1935 finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));1936 m_activeUnitLevelOn = true;1937 m_remainingBitsInFrame = m_targetBits;1938 m_costAvgbpp = (m_targetBits/(Double)m_numOfPixels);1939 }1940 1941 m_indexRefFrame++;1942 }1943 else1944 {1945 Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;1946 Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;1947 1948 if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp1949 ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)1950 {1951 finalQP = (fwdQP+bwdQP);1952 }1953 else if(bwdQP != fwdQP)1954 {1955 finalQP = ((bwdQP+fwdQP+2)>>1);1956 }1957 else1958 {1959 finalQP = bwdQP+2;1960 }1961 m_indexNonRefFrame++;1962 }1963 }1964 else1965 {1966 Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;1967 Int lastQPplus2 = m_pcFrameData[0].m_qp + 2;1968 1969 for(Int idx = 1; idx <= m_sizeGOP; idx++)1970 {1971 if(m_pcFrameData[idx].m_isReferenced)1972 {1973 finalQP += m_pcFrameData[idx].m_qp;1974 numofReferenced++;1975 }1976 }1977 1978 finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);1979 finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));1980 1981 Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;1982 Int bufLevel = m_occupancyVB + m_initialOVB;1983 1984 if(abs(bufLevel) > costAvgFrameBits)1985 {1986 if(bufLevel < 0)1987 {1988 finalQP -= 2;1989 }1990 else1991 {1992 finalQP += 2;1993 }1994 }1995 m_indexRefFrame++;1996 }1997 finalQP = max(MIN_QP, min(MAX_QP, finalQP));1998 1999 for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)2000 {2001 m_pcLCUData[indexLCU].m_qp = finalQP;2002 }2003 2004 pcFrameData->m_isReferenced = isReferenced;2005 pcFrameData->m_qp = finalQP;2006 2007 return finalQP;2008 }2009 2010 Bool TEncRateCtrl::calculateUnitQP ()2011 {2012 if(!m_activeUnitLevelOn || m_indexLCU == 0)2013 {2014 return false;2015 }2016 Int upperQPBound, lowerQPBound, finalQP;2017 Int colQP = m_pcLCUData[m_indexLCU].m_qp;2018 Double colMAD = m_pcLCUData[m_indexLCU].m_costMAD;2019 Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;2020 2021 2022 Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));2023 Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));2024 Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);2025 2026 2027 if( m_indexLCU >= m_sourceWidthInLCU)2028 {2029 upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;2030 lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;2031 }2032 else2033 {2034 upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;2035 lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;2036 }2037 2038 if(targetBits < 0)2039 {2040 finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;2041 }2042 else2043 {2044 finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);2045 }2046 2047 finalQP = max(lowerQPBound, min(upperQPBound, finalQP));2048 m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));2049 2050 return true;2051 }2052 2053 Void TEncRateCtrl::updateRCGOPStatus()2054 {2055 m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;2056 2057 FrameData cFrameData = m_pcFrameData[m_sizeGOP];2058 initFrameData();2059 2060 m_pcFrameData[0] = cFrameData;2061 m_indexGOP++;2062 m_indexFrame = 0;2063 m_indexRefFrame = 0;2064 m_indexNonRefFrame = 0;2065 }2066 2067 Void TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)2068 {2069 FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];2070 Int occupancyBits;2071 Double adjustmentBits;2072 2073 m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;2074 occupancyBits = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));2075 2076 if( (occupancyBits < 0) && (m_initialOVB > 0) )2077 {2078 adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );2079 2080 if(m_initialOVB < 0)2081 {2082 adjustmentBits = m_initialOVB;2083 occupancyBits += (Int)adjustmentBits;2084 m_initialOVB = 0;2085 }2086 }2087 else if( (occupancyBits > 0) && (m_initialOVB < 0) )2088 {2089 adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );2090 2091 if(occupancyBits < 0)2092 {2093 adjustmentBits = occupancyBits;2094 m_initialOVB += (Int)adjustmentBits;2095 occupancyBits = 0;2096 }2097 }2098 2099 if(m_indexGOP == 0)2100 {2101 m_initialOVB = occupancyBits;2102 }2103 else2104 {2105 m_occupancyVB= m_occupancyVB + occupancyBits;2106 }2107 2108 if(pcFrameData->m_isReferenced)2109 {2110 m_costRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);2111 2112 if(m_indexFrame == 0)2113 {2114 m_initialTBL = m_targetBufLevel = (frameBits - (m_currBitrate/m_frameRate));2115 }2116 else2117 {2118 Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;2119 m_targetBufLevel = m_targetBufLevel2120 - (m_initialTBL/(m_refFrameNum-1))2121 + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance))))2122 - (m_currBitrate/m_frameRate);2123 }2124 2125 if(m_cMADLinearModel.IsUpdateAvailable())2126 {2127 m_cMADLinearModel.updateMADLiearModel();2128 }2129 2130 if(eSliceType != I_SLICE &&2131 m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))2132 {2133 m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);2134 }2135 }2136 else2137 {2138 m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);2139 }2140 2141 m_indexFrame++;2142 m_indexLCU = 0;2143 m_indexUnit = 0;2144 m_occupancyVBInFrame = 0;2145 m_remainingBitsInFrame = 0;2146 m_codedPixels = 0;2147 m_activeUnitLevelOn = false;2148 m_costAvgbpp = 0.0;2149 }2150 Void TEncRateCtrl::updataRCUnitStatus ()2151 {2152 if(!m_activeUnitLevelOn || m_indexLCU == 0)2153 {2154 return;2155 }2156 2157 m_codedPixels += m_pcLCUData[m_indexLCU-1].m_pixels;2158 m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;2159 m_occupancyVBInFrame = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);2160 2161 if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )2162 {2163 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);2164 }2165 2166 m_indexUnit++;2167 }2168 2169 Void TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)2170 {2171 Double costMAD = 0.0;2172 2173 for(Int i = 0; i < m_numUnitInFrame; i++)2174 {2175 costMAD += m_pcLCUData[i].m_costMAD;2176 }2177 2178 m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);2179 m_pcFrameData[m_indexPOCInGOP].m_bits = (Int)actualFrameBits;2180 2181 if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)2182 {2183 m_indexPrevPOCInGOP = m_indexPOCInGOP;2184 m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);2185 }2186 }2187 2188 Void TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)2189 {2190 Int x, y;2191 Double costMAD = 0.0;2192 2193 Pel* pOrg = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);2194 Pel* pRec = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);2195 Int stride = pcCU->getPic()->getStride();2196 2197 Int width = m_pcLCUData[m_indexLCU].m_widthInPixel;2198 Int height = m_pcLCUData[m_indexLCU].m_heightInPixel;2199 2200 for( y = 0; y < height; y++ )2201 {2202 for( x = 0; x < width; x++ )2203 {2204 costMAD += abs( pOrg[x] - pRec[x] );2205 }2206 pOrg += stride;2207 pRec += stride;2208 }2209 m_pcLCUData[m_indexLCU ].m_qp = qp;2210 m_pcLCUData[m_indexLCU ].m_costMAD = (costMAD /(Double)(width*height));2211 m_pcLCUData[m_indexLCU++].m_bits = (Int)actualLCUBits;2212 }2213 2214 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)2215 {2216 Double adjustment = ADJUSTMENT_FACTOR*reductionBits;2217 reductionBits -= (Int)adjustment;2218 compensationBits += (Int)adjustment;2219 2220 return adjustment;2221 }2222 2223 #endif2224 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncRateCtrl.h
r313 r532 55 55 //! \{ 56 56 57 #if RATE_CONTROL_LAMBDA_DOMAIN58 57 #include "../TLibEncoder/TEncCfg.h" 59 58 #include <list> … … 65 64 const Double g_RCWeightPicTargetBitInGOP = 0.9; 66 65 const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP; 67 #if M0036_RC_IMPROVEMENT68 66 const Int g_RCIterationNum = 20; 69 67 const Double g_RCWeightHistoryLambda = 0.5; … … 74 72 const Double g_RCBetaMinValue = -3.0; 75 73 const Double g_RCBetaMaxValue = -0.1; 76 #endif 77 78 #if RATE_CONTROL_INTRA 74 79 75 #define ALPHA 6.7542; 80 76 #define BETA1 1.2517 81 77 #define BETA2 1.7860 82 #endif83 78 84 79 struct TRCLCU … … 88 83 Int m_targetBits; 89 84 Double m_lambda; 90 #if M0036_RC_IMPROVEMENT91 85 Double m_bitWeight; 92 #else93 Double m_MAD;94 #endif95 86 Int m_numberOfPixel; 96 #if RATE_CONTROL_INTRA97 87 Double m_costIntra; 98 88 Int m_targetBitsLeft; 99 #endif100 89 }; 101 90 … … 113 102 114 103 public: 115 #if M0036_RC_IMPROVEMENT116 104 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit ); 117 #else118 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );119 #endif120 105 Void destroy(); 121 106 Void initBitsRatio( Int bitsRatio[] ); … … 124 109 Void initLCUPara( TRCParameter** LCUPara = NULL ); // NULL to initial with default value 125 110 Void updateAfterPic ( Int bits ); 126 #if !RATE_CONTROL_INTRA127 Int getRefineBitsForIntra( Int orgBits );128 #endif129 #if M0036_RC_IMPROVEMENT130 111 Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB ); 131 #endif132 112 133 113 public: … … 167 147 Double getBetaUpdate() { return m_betaUpdate; } 168 148 169 #if M0036_RC_IMPROVEMENT170 149 Int getAdaptiveBits() { return m_adaptiveBit; } 171 150 Double getLastLambda() { return m_lastLambda; } 172 151 Void setLastLambda( Double lamdba ) { m_lastLambda = lamdba; } 173 #endif174 152 175 153 private: … … 200 178 Bool m_useLCUSeparateModel; 201 179 202 #if M0036_RC_IMPROVEMENT203 180 Int m_adaptiveBit; 204 181 Double m_lastLambda; 205 #endif206 182 }; 207 183 … … 219 195 private: 220 196 Int xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize ); 221 #if M0036_RC_IMPROVEMENT222 197 Void xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 223 198 Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 224 #endif225 199 226 200 public: … … 251 225 Void destroy(); 252 226 253 #if !RATE_CONTROL_INTRA254 Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );255 #endif256 227 Int estimatePicQP ( Double lambda, list<TEncRCPic*>& listPreviousPictures ); 257 #if RATE_CONTROL_INTRA258 228 Int getRefineBitsForIntra(Int orgBits); 259 229 Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel); … … 264 234 Double getLCUTargetBpp(SliceType eSliceType); 265 235 Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP); 266 #else267 Double getLCUTargetBpp();268 #endif269 236 Double getLCUEstLambda( Double bpp ); 270 237 Int getLCUEstQP( Double lambda, Int clipPicQP ); 271 238 272 239 Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true ); 273 #if M0036_RC_IMPROVEMENT274 #if RATE_CONTROL_INTRA275 240 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType); 276 #else277 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );278 #endif279 #else280 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );281 #endif282 241 283 242 Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures ); 284 #if !M0036_RC_IMPROVEMENT285 Double getEffectivePercentage();286 #endif287 243 Double calAverageQP(); 288 244 Double calAverageLambda(); … … 300 256 Int getNumberOfLCU() { return m_numberOfLCU; } 301 257 Int getTargetBits() { return m_targetBits; } 302 #if !RATE_CONTROL_INTRA303 Void setTargetBits( Int bits ) { m_targetBits = bits; }304 #endif305 258 Int getEstHeaderBits() { return m_estHeaderBits; } 306 259 Int getLCULeft() { return m_LCULeft; } … … 312 265 TRCLCU& getLCU( Int LCUIdx ) { return m_LCUs[LCUIdx]; } 313 266 Int getPicActualHeaderBits() { return m_picActualHeaderBits; } 314 #if !M0036_RC_IMPROVEMENT315 Double getTotalMAD() { return m_totalMAD; }316 Void setTotalMAD( Double MAD ) { m_totalMAD = MAD; }317 #endif318 #if RATE_CONTROL_INTRA319 267 Void setTargetBits( Int bits ) { m_targetBits = bits; m_bitsLeft = bits;} 320 268 Void setTotalIntraCost(Double cost) { m_totalCostIntra = cost; } 321 269 Void getLCUInitTargetBits(); 322 #endif323 270 324 271 Int getPicActualBits() { return m_picActualBits; } … … 348 295 TRCLCU* m_LCUs; 349 296 Int m_picActualHeaderBits; // only SH and potential APS 350 #if !M0036_RC_IMPROVEMENT351 Double m_totalMAD;352 #endif353 #if RATE_CONTROL_INTRA354 297 Double m_totalCostIntra; 355 298 Double m_remainingCostIntra; 356 #endif357 299 Int m_picActualBits; // the whole picture, including header 358 300 Int m_picQP; // in integer form 359 301 Double m_picLambda; 360 #if !M0036_RC_IMPROVEMENT361 TEncRCPic* m_lastPicture;362 #endif363 302 }; 364 303 … … 370 309 371 310 public: 372 #if M0036_RC_IMPROVEMENT373 311 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] ); 374 #else375 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] );376 #endif377 312 Void destroy(); 378 313 Void initRCPic( Int frameLevel ); … … 396 331 }; 397 332 398 #else399 400 // ====================================================================================================================401 // Class definition402 // ====================================================================================================================403 #define MAX_DELTA_QP 2404 #define MAX_CUDQP_DEPTH 0405 406 typedef struct FrameData407 {408 Bool m_isReferenced;409 Int m_qp;410 Int m_bits;411 Double m_costMAD;412 }FrameData;413 414 typedef struct LCUData415 {416 Int m_qp; ///< coded QP417 Int m_bits; ///< actually generated bits418 Int m_pixels; ///< number of pixels for a unit419 Int m_widthInPixel; ///< number of pixels for width420 Int m_heightInPixel; ///< number of pixels for height421 Double m_costMAD; ///< texture complexity for a unit422 }LCUData;423 424 class MADLinearModel425 {426 private:427 Bool m_activeOn;428 Double m_paramY1;429 Double m_paramY2;430 Double m_costMADs[3];431 432 public:433 MADLinearModel () {};434 ~MADLinearModel() {};435 436 Void initMADLinearModel ();437 Double getMAD ();438 Void updateMADLiearModel ();439 Void updateMADHistory (Double costMAD);440 Bool IsUpdateAvailable () { return m_activeOn; }441 };442 443 class PixelBaseURQQuadraticModel444 {445 private:446 Double m_paramHighX1;447 Double m_paramHighX2;448 Double m_paramLowX1;449 Double m_paramLowX2;450 public:451 PixelBaseURQQuadraticModel () {};452 ~PixelBaseURQQuadraticModel() {};453 454 Void initPixelBaseQuadraticModel ();455 Int getQP (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD);456 Void updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD);457 Bool checkUpdateAvailable (Int qpReference );458 Double xConvertQP2QStep (Int qp );459 Int xConvertQStep2QP (Double qStep );460 };461 462 class TEncRateCtrl463 {464 private:465 Bool m_isLowdelay;466 Int m_prevBitrate;467 Int m_currBitrate;468 Int m_frameRate;469 Int m_refFrameNum;470 Int m_nonRefFrameNum;471 Int m_numOfPixels;472 Int m_sourceWidthInLCU;473 Int m_sourceHeightInLCU;474 Int m_sizeGOP;475 Int m_indexGOP;476 Int m_indexFrame;477 Int m_indexLCU;478 Int m_indexUnit;479 Int m_indexRefFrame;480 Int m_indexNonRefFrame;481 Int m_indexPOCInGOP;482 Int m_indexPrevPOCInGOP;483 Int m_occupancyVB;484 Int m_initialOVB;485 Int m_targetBufLevel;486 Int m_initialTBL;487 Int m_remainingBitsInGOP;488 Int m_remainingBitsInFrame;489 Int m_occupancyVBInFrame;490 Int m_targetBits;491 Int m_numUnitInFrame;492 Int m_codedPixels;493 Bool m_activeUnitLevelOn;494 Double m_costNonRefAvgWeighting;495 Double m_costRefAvgWeighting;496 Double m_costAvgbpp;497 498 FrameData* m_pcFrameData;499 LCUData* m_pcLCUData;500 501 MADLinearModel m_cMADLinearModel;502 PixelBaseURQQuadraticModel m_cPixelURQQuadraticModel;503 504 public:505 TEncRateCtrl () {};506 virtual ~TEncRateCtrl() {};507 508 Void create (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight);509 Void destroy ();510 511 Void initFrameData (Int qp = 0);512 Void initUnitData (Int qp = 0);513 Int getFrameQP (Bool isReferenced, Int POC);514 Bool calculateUnitQP ();515 Int getUnitQP () { return m_pcLCUData[m_indexLCU].m_qp; }516 Void updateRCGOPStatus ();517 Void updataRCFrameStatus (Int frameBits, SliceType eSliceType);518 Void updataRCUnitStatus ();519 Void updateLCUData (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);520 Void updateFrameData (UInt64 actualFrameBits);521 Double xAdjustmentBits (Int& reductionBits, Int& compensationBits);522 Int getGOPId () { return m_indexFrame; }523 };524 333 #endif 525 334 526 #endif 527 528 335 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r494 r532 45 45 //! \{ 46 46 47 48 #if HM_CLEANUP_SAO 49 50 /** rounding with IBDI 51 * \param x 52 */ 53 inline Double xRoundIbdi2(Int bitDepth, Double x) 54 { 55 return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8)))); 56 } 57 58 inline Double xRoundIbdi(Int bitDepth, Double x) 59 { 60 return (bitDepth > 8 ? xRoundIbdi2(bitDepth, (x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ; 61 } 62 63 64 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 65 { 66 m_pppcRDSbacCoder = NULL; 67 m_pcRDGoOnSbacCoder = NULL; 68 m_pppcBinCoderCABAC = NULL; 69 m_statData = NULL; 70 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 71 m_preDBFstatData = NULL; 72 #endif 73 } 74 75 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset() 76 { 77 destroyEncData(); 78 } 79 80 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 81 Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed) 82 #else 83 Void TEncSampleAdaptiveOffset::createEncData() 84 #endif 85 { 86 87 //cabac coder for RDO 88 m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS]; 89 m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS]; 90 91 for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++) 92 { 93 m_pppcRDSbacCoder[cs] = new TEncSbac; 94 m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter; 95 m_pppcRDSbacCoder [cs]->init( m_pppcBinCoderCABAC [cs] ); 96 } 97 98 99 //statistics 100 m_statData = new SAOStatData**[m_numCTUsPic]; 101 for(Int i=0; i< m_numCTUsPic; i++) 102 { 103 m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 104 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 105 { 106 m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 107 } 108 } 109 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 110 if(isPreDBFSamplesUsed) 111 { 112 m_preDBFstatData = new SAOStatData**[m_numCTUsPic]; 113 for(Int i=0; i< m_numCTUsPic; i++) 114 { 115 m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 116 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 117 { 118 m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 119 } 120 } 121 122 } 123 #endif 124 125 #if SAO_ENCODING_CHOICE 126 ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate)); 127 #endif 128 129 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 130 { 131 m_skipLinesR[SAO_Y ][typeIdc]= 5; 132 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 133 134 m_skipLinesB[SAO_Y ][typeIdc]= 4; 135 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 136 137 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 138 if(isPreDBFSamplesUsed) 139 { 140 switch(typeIdc) 141 { 142 case SAO_TYPE_EO_0: 143 { 144 m_skipLinesR[SAO_Y ][typeIdc]= 5; 145 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 146 147 m_skipLinesB[SAO_Y ][typeIdc]= 3; 148 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 149 } 150 break; 151 case SAO_TYPE_EO_90: 152 { 153 m_skipLinesR[SAO_Y ][typeIdc]= 4; 154 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 155 156 m_skipLinesB[SAO_Y ][typeIdc]= 4; 157 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 158 } 159 break; 160 case SAO_TYPE_EO_135: 161 case SAO_TYPE_EO_45: 162 { 163 m_skipLinesR[SAO_Y ][typeIdc]= 5; 164 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 165 166 m_skipLinesB[SAO_Y ][typeIdc]= 4; 167 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 168 } 169 break; 170 case SAO_TYPE_BO: 171 { 172 m_skipLinesR[SAO_Y ][typeIdc]= 4; 173 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 174 175 m_skipLinesB[SAO_Y ][typeIdc]= 3; 176 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 177 } 178 break; 179 default: 180 { 181 printf("Not a supported type"); 182 assert(0); 183 exit(-1); 184 } 185 } 186 } 187 #endif 188 } 189 190 } 191 192 Void TEncSampleAdaptiveOffset::destroyEncData() 193 { 194 if(m_pppcRDSbacCoder != NULL) 195 { 196 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 197 { 198 delete m_pppcRDSbacCoder[cs]; 199 } 200 delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL; 201 } 202 203 if(m_pppcBinCoderCABAC != NULL) 204 { 205 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 206 { 207 delete m_pppcBinCoderCABAC[cs]; 208 } 209 delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL; 210 } 211 212 if(m_statData != NULL) 213 { 214 for(Int i=0; i< m_numCTUsPic; i++) 215 { 216 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 217 { 218 delete[] m_statData[i][compIdx]; 219 } 220 delete[] m_statData[i]; 221 } 222 delete[] m_statData; m_statData = NULL; 223 } 224 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 225 if(m_preDBFstatData != NULL) 226 { 227 for(Int i=0; i< m_numCTUsPic; i++) 228 { 229 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 230 { 231 delete[] m_preDBFstatData[i][compIdx]; 232 } 233 delete[] m_preDBFstatData[i]; 234 } 235 delete[] m_preDBFstatData; m_preDBFstatData = NULL; 236 } 237 238 #endif 239 } 240 241 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 242 { 243 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 244 m_pcRDGoOnSbacCoder->setSlice(pcSlice); 245 m_pcRDGoOnSbacCoder->resetEntropy(); 246 m_pcRDGoOnSbacCoder->resetBits(); 247 248 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]); 249 } 250 251 252 253 Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 254 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 255 , Bool isPreDBFSamplesUsed 256 #endif 257 ) 258 { 259 TComPicYuv* orgYuv= pPic->getPicYuvOrg(); 260 TComPicYuv* resYuv= pPic->getPicYuvRec(); 261 m_labmda[SAO_Y]= lambdas[0]; m_labmda[SAO_Cb]= lambdas[1]; m_labmda[SAO_Cr]= lambdas[2]; 262 TComPicYuv* srcYuv = m_tempPicYuv; 263 resYuv->copyToPic(srcYuv); 264 srcYuv->setBorderExtension(false); 265 srcYuv->extendPicBorder(); 266 267 //collect statistics 268 getStatistics(m_statData, orgYuv, srcYuv, pPic); 269 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 270 if(isPreDBFSamplesUsed) 271 { 272 addPreDBFStatistics(m_statData); 273 } 274 #endif 275 //slice on/off 276 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 277 278 //block on/off 279 SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters 280 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam()); 281 delete[] reconParams; 282 283 } 284 285 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 286 Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic) 287 { 288 getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true); 289 } 290 291 Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats) 292 { 293 for(Int n=0; n< m_numCTUsPic; n++) 294 { 295 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 296 { 297 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 298 { 299 blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc]; 300 } 301 } 302 } 303 } 304 305 #endif 306 307 Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic 308 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 309 , Bool isCalculatePreDeblockSamples 310 #endif 311 ) 312 { 313 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 314 315 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 316 { 317 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 318 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 319 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 320 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 321 322 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 323 324 //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities. 325 //For simplicity, here only picture boundaries are considered. 326 327 isRightAvail = (xPos + m_maxCUWidth < m_picWidth ); 328 isBelowAvail = (yPos + m_maxCUHeight < m_picHeight); 329 isBelowRightAvail = (isRightAvail && isBelowAvail); 330 isBelowLeftAvail = ((xPos > 0) && (isBelowAvail)); 331 isAboveRightAvail = ((yPos > 0) && (isRightAvail)); 332 333 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 334 { 335 Bool isLuma = (compIdx == SAO_Y); 336 Int formatShift= isLuma?0:1; 337 338 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 339 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 340 341 Int orgStride = isLuma?orgYuv->getStride():orgYuv->getCStride(); 342 Pel* orgBlk = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift); 343 344 getBlkStats(compIdx, blkStats[ctu][compIdx] 345 , srcBlk, orgBlk, srcStride, orgStride, (width >> formatShift), (height >> formatShift) 346 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail 347 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 348 , isCalculatePreDeblockSamples 349 #endif 350 ); 351 352 } 353 } 354 } 355 356 Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer) 357 { 358 //decide sliceEnabled[compIdx] 359 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 360 { 361 // reset flags & counters 362 sliceEnabled[compIdx] = true; 363 364 #if SAO_ENCODING_CHOICE 365 #if SAO_ENCODING_CHOICE_CHROMA 366 // decide slice-level on/off based on previous results 367 if( (picTempLayer > 0) 368 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) ) 369 { 370 sliceEnabled[compIdx] = false; 371 } 372 #else 373 // decide slice-level on/off based on previous results 374 if( (picTempLayer > 0) 375 && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) ) 376 { 377 sliceEnabled[compIdx] = false; 378 } 379 #endif 380 #endif 381 } 382 } 383 384 Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 385 { 386 Int64 dist=0; 387 Int inputBitDepth = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ; 388 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8); 389 390 switch(typeIdc) 391 { 392 case SAO_TYPE_EO_0: 393 case SAO_TYPE_EO_90: 394 case SAO_TYPE_EO_135: 395 case SAO_TYPE_EO_45: 396 { 397 for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++) 398 { 399 dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift); 400 } 401 } 402 break; 403 case SAO_TYPE_BO: 404 { 405 for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++) 406 { 407 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 408 dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift); 409 } 410 } 411 break; 412 default: 413 { 414 printf("Not a supported type"); 415 assert(0); 416 exit(-1); 417 } 418 } 419 420 return dist; 421 } 422 423 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift) 424 { 425 return (( count*offset*offset-diffSum*offset*2 ) >> shift); 426 } 427 428 429 inline 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 ) 430 { 431 Int iterOffset, tempOffset; 432 Int64 tempDist, tempRate; 433 Double tempCost, tempMinCost; 434 Int offsetOutput = 0; 435 iterOffset = offsetInput; 436 // 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. 437 tempMinCost = lambda; 438 while (iterOffset != 0) 439 { 440 // Calculate the bits required for signaling the offset 441 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 442 if (abs((Int)iterOffset)==offsetTh) //inclusive 443 { 444 tempRate --; 445 } 446 // Do the dequantization before distortion calculation 447 tempOffset = iterOffset << bitIncrease; 448 tempDist = estSaoDist( count, tempOffset, diffSum, shift); 449 tempCost = ((Double)tempDist + lambda * (Double) tempRate); 450 if(tempCost < tempMinCost) 451 { 452 tempMinCost = tempCost; 453 offsetOutput = iterOffset; 454 bestDist = tempDist; 455 bestCost = tempCost; 456 } 457 iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1); 458 } 459 return offsetOutput; 460 } 461 462 463 Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 464 { 465 Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC; 466 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 467 Int offsetTh = g_saoMaxOffsetQVal[compIdx]; //inclusive 468 469 ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 470 471 //derive initial offsets 472 Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES); 473 for(Int classIdx=0; classIdx< numClasses; classIdx++) 474 { 475 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 476 { 477 continue; //offset will be zero 478 } 479 480 if(statData.count[classIdx] == 0) 481 { 482 continue; //offset will be zero 483 } 484 485 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 486 / 487 (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx]) 488 ); 489 quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]); 490 } 491 492 // adjust offsets 493 switch(typeIdc) 494 { 495 case SAO_TYPE_EO_0: 496 case SAO_TYPE_EO_90: 497 case SAO_TYPE_EO_135: 498 case SAO_TYPE_EO_45: 499 { 500 Int64 classDist; 501 Double classCost; 502 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 503 { 504 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 505 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 506 if(classIdx==SAO_CLASS_EO_HALF_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 507 if(classIdx==SAO_CLASS_EO_FULL_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 508 509 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 510 { 511 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh ); 512 } 513 } 514 515 typeAuxInfo =0; 516 } 517 break; 518 case SAO_TYPE_BO: 519 { 520 Int64 distBOClasses[NUM_SAO_BO_CLASSES]; 521 Double costBOClasses[NUM_SAO_BO_CLASSES]; 522 ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES); 523 for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++) 524 { 525 costBOClasses[classIdx]= m_labmda[compIdx]; 526 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 527 { 528 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh ); 529 } 530 } 531 532 //decide the starting band index 533 Double minCost = MAX_DOUBLE, cost; 534 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 535 { 536 cost = costBOClasses[band ]; 537 cost += costBOClasses[band+1]; 538 cost += costBOClasses[band+2]; 539 cost += costBOClasses[band+3]; 540 541 if(cost < minCost) 542 { 543 minCost = cost; 544 typeAuxInfo = band; 545 } 546 } 547 //clear those unused classes 548 Int clearQuantOffset[NUM_SAO_BO_CLASSES]; 549 ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES); 550 for(Int i=0; i< 4; i++) 551 { 552 Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES; 553 clearQuantOffset[band] = quantOffsets[band]; 554 } 555 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 556 } 557 break; 558 default: 559 { 560 printf("Not a supported type"); 561 assert(0); 562 exit(-1); 563 } 564 565 } 566 567 568 } 569 570 571 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 572 { 573 Double minCost, cost; 574 Int rate, minRate; 575 Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS]; 576 SAOOffset testOffset[NUM_SAO_COMPONENTS]; 577 Int compIdx; 578 Int invQuantOffset[MAX_NUM_SAO_CLASSES]; 579 580 modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0; 581 582 //pre-encode merge flags 583 modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF; 584 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 585 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true); 586 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 587 588 //------ luma --------// 589 compIdx = SAO_Y; 590 //"off" case as initial cost 591 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 592 m_pcRDGoOnSbacCoder->resetBits(); 593 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]); 594 minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 595 modeDist[compIdx] = 0; 596 minCost= m_labmda[compIdx]*((Double)minRate); 597 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 598 if(sliceEnabled[compIdx]) 599 { 600 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 601 { 602 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 603 testOffset[compIdx].typeIdc = typeIdc; 604 605 //derive coded offset 606 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 607 608 //inversed quantized offsets 609 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 610 611 //get distortion 612 dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 613 614 //get rate 615 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 616 m_pcRDGoOnSbacCoder->resetBits(); 617 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 618 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 619 cost = (Double)dist[compIdx] + m_labmda[compIdx]*((Double)rate); 620 if(cost < minCost) 621 { 622 minCost = cost; 623 minRate = rate; 624 modeDist[compIdx] = dist[compIdx]; 625 modeParam[compIdx]= testOffset[compIdx]; 626 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 627 } 628 } 629 } 630 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 631 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 632 633 //------ chroma --------// 634 assert(m_labmda[SAO_Cb] == m_labmda[SAO_Cr]); 635 Double chromaLambda = m_labmda[SAO_Cb]; 636 //"off" case as initial cost 637 m_pcRDGoOnSbacCoder->resetBits(); 638 modeParam[SAO_Cb].modeIdc = SAO_MODE_OFF; 639 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, modeParam[SAO_Cb], sliceEnabled[SAO_Cb]); 640 modeParam[SAO_Cr].modeIdc = SAO_MODE_OFF; 641 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, modeParam[SAO_Cr], sliceEnabled[SAO_Cr]); 642 minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 643 modeDist[SAO_Cb] = modeDist[SAO_Cr]= 0; 644 minCost= chromaLambda*((Double)minRate); 645 646 //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function 647 648 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 649 { 650 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 651 { 652 if(!sliceEnabled[compIdx]) 653 { 654 testOffset[compIdx].modeIdc = SAO_MODE_OFF; 655 dist[compIdx]= 0; 656 continue; 657 } 658 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 659 testOffset[compIdx].typeIdc = typeIdc; 660 661 //derive offset & get distortion 662 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 663 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 664 dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 665 } 666 667 //get rate 668 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 669 m_pcRDGoOnSbacCoder->resetBits(); 670 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, testOffset[SAO_Cb], sliceEnabled[SAO_Cb]); 671 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, testOffset[SAO_Cr], sliceEnabled[SAO_Cr]); 672 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 673 674 cost = (Double)(dist[SAO_Cb]+ dist[SAO_Cr]) + chromaLambda*((Double)rate); 675 if(cost < minCost) 676 { 677 minCost = cost; 678 minRate = rate; 679 modeDist[SAO_Cb] = dist[SAO_Cb]; 680 modeDist[SAO_Cr] = dist[SAO_Cr]; 681 modeParam[SAO_Cb]= testOffset[SAO_Cb]; 682 modeParam[SAO_Cr]= testOffset[SAO_Cr]; 683 } 684 } 685 686 687 //----- re-gen rate & normalized cost----// 688 modeNormCost = (Double)modeDist[SAO_Y]/m_labmda[SAO_Y]; 689 modeNormCost += (Double)(modeDist[SAO_Cb]+ modeDist[SAO_Cr])/chromaLambda; 690 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 691 m_pcRDGoOnSbacCoder->resetBits(); 692 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 693 modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 694 695 } 696 697 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 698 { 699 Int mergeListSize = (Int)mergeList.size(); 700 modeNormCost = MAX_DOUBLE; 701 702 Double cost; 703 SAOBlkParam testBlkParam; 704 705 for(Int mergeType=0; mergeType< mergeListSize; mergeType++) 706 { 707 if(mergeList[mergeType] == NULL) 708 { 709 continue; 710 } 711 712 testBlkParam = *(mergeList[mergeType]); 713 //normalized distortion 714 Double normDist=0; 715 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 716 { 717 testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE; 718 testBlkParam[compIdx].typeIdc = mergeType; 719 720 SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx]; 721 722 if( mergedOffsetParam.modeIdc != SAO_MODE_OFF) 723 { 724 //offsets have been reconstructed. Don't call inversed quantization function. 725 normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc])) 726 /m_labmda[compIdx] 727 ); 728 } 729 730 } 731 732 //rate 733 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 734 m_pcRDGoOnSbacCoder->resetBits(); 735 m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 736 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 737 738 cost = normDist+(Double)rate; 739 740 if(cost < modeNormCost) 741 { 742 modeNormCost = cost; 743 modeParam = testBlkParam; 744 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 745 } 746 } 747 748 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 749 750 751 } 752 753 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams) 754 { 755 Bool isAllBlksDisabled = false; 756 if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr]) 757 { 758 isAllBlksDisabled = true; 759 } 760 761 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]); 762 763 SAOBlkParam modeParam; 764 Double minCost, modeCost; 765 766 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 767 { 768 if(isAllBlksDisabled) 769 { 770 codedParams[ctu].reset(); 771 continue; 772 } 773 774 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]); 775 776 //get merge list 777 std::vector<SAOBlkParam*> mergeList; 778 getMergeList(pic, ctu, reconParams, mergeList); 779 780 minCost = MAX_DOUBLE; 781 for(Int mode=0; mode < NUM_SAO_MODES; mode++) 782 { 783 switch(mode) 784 { 785 case SAO_MODE_OFF: 786 { 787 continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case. 788 } 789 break; 790 case SAO_MODE_NEW: 791 { 792 deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 793 794 } 795 break; 796 case SAO_MODE_MERGE: 797 { 798 deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 799 } 800 break; 801 default: 802 { 803 printf("Not a supported SAO mode\n"); 804 assert(0); 805 exit(-1); 806 } 807 } 808 809 if(modeCost < minCost) 810 { 811 minCost = modeCost; 812 codedParams[ctu] = modeParam; 813 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 814 815 } 816 } //mode 817 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 818 819 //apply reconstructed offsets 820 reconParams[ctu] = codedParams[ctu]; 821 reconstructBlkSAOParam(reconParams[ctu], mergeList); 822 offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic); 823 } //ctu 824 825 #if SAO_ENCODING_CHOICE 826 Int picTempLayer = pic->getSlice(0)->getDepth(); 827 Int numLcusForSAOOff[NUM_SAO_COMPONENTS]; 828 numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0; 829 830 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 831 { 832 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 833 { 834 if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF) 835 { 836 numLcusForSAOOff[compIdx]++; 837 } 838 } 839 } 840 #if SAO_ENCODING_CHOICE_CHROMA 841 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 842 { 843 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic; 844 } 845 #else 846 if (picTempLayer == 0) 847 { 848 m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3); 849 } 850 #endif 851 #endif 852 } 853 854 855 Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 856 , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height 857 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 858 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 859 , Bool isCalculatePreDeblockSamples 860 #endif 861 ) 862 { 863 if(m_lineBufWidth != m_maxCUWidth) 864 { 865 m_lineBufWidth = m_maxCUWidth; 866 867 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 868 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 869 870 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 871 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 872 } 873 874 Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX; 875 Char signLeft, signRight, signDown; 876 Int64 *diff, *count; 877 Pel *srcLine, *orgLine; 878 Int* skipLinesR = m_skipLinesR[compIdx]; 879 Int* skipLinesB = m_skipLinesB[compIdx]; 880 881 for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++) 882 { 883 SAOStatData& statsData= statsDataTypes[typeIdx]; 884 statsData.reset(); 885 886 srcLine = srcBlk; 887 orgLine = orgBlk; 888 diff = statsData.diff; 889 count = statsData.count; 890 switch(typeIdx) 891 { 892 case SAO_TYPE_EO_0: 893 { 894 diff +=2; 895 count+=2; 896 endY = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height; 897 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 898 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 899 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 900 ; 901 #else 902 startX = isLeftAvail ? 0 : 1; 903 #endif 904 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 905 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 906 : (isRightAvail ? width : (width - 1)) 907 ; 908 #else 909 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 910 #endif 911 for (y=0; y<endY; y++) 912 { 913 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 914 for (x=startX; x<endX; x++) 915 { 916 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 917 edgeType = signRight + signLeft; 918 signLeft = -signRight; 919 920 diff [edgeType] += (orgLine[x] - srcLine[x]); 921 count[edgeType] ++; 922 } 923 srcLine += srcStride; 924 orgLine += orgStride; 925 } 926 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 927 if(isCalculatePreDeblockSamples) 928 { 929 if(isBelowAvail) 930 { 931 startX = isLeftAvail ? 0 : 1; 932 endX = isRightAvail ? width : (width -1); 933 934 for(y=0; y<skipLinesB[typeIdx]; y++) 935 { 936 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 937 for (x=startX; x<endX; x++) 938 { 939 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 940 edgeType = signRight + signLeft; 941 signLeft = -signRight; 942 943 diff [edgeType] += (orgLine[x] - srcLine[x]); 944 count[edgeType] ++; 945 } 946 srcLine += srcStride; 947 orgLine += orgStride; 948 } 949 } 950 } 951 #endif 952 } 953 break; 954 case SAO_TYPE_EO_90: 955 { 956 diff +=2; 957 count+=2; 958 Char *signUpLine = m_signLineBuf1; 959 960 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 961 startX = (!isCalculatePreDeblockSamples) ? 0 962 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 963 ; 964 #endif 965 startY = isAboveAvail ? 0 : 1; 966 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 967 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 968 : width 969 ; 970 #else 971 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : width ; 972 #endif 973 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 974 if (!isAboveAvail) 975 { 976 srcLine += srcStride; 977 orgLine += orgStride; 978 } 979 980 Pel* srcLineAbove = srcLine - srcStride; 981 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 982 for (x=startX; x<endX; x++) 983 #else 984 for (x=0; x< endX; x++) 985 #endif 986 { 987 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]]; 988 } 989 990 Pel* srcLineBelow; 991 for (y=startY; y<endY; y++) 992 { 993 srcLineBelow = srcLine + srcStride; 994 995 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 996 for (x=startX; x<endX; x++) 997 #else 998 for (x=0; x<endX; x++) 999 #endif 1000 { 1001 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 1002 edgeType = signDown + signUpLine[x]; 1003 signUpLine[x]= -signDown; 1004 1005 diff [edgeType] += (orgLine[x] - srcLine[x]); 1006 count[edgeType] ++; 1007 } 1008 srcLine += srcStride; 1009 orgLine += orgStride; 1010 } 1011 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1012 if(isCalculatePreDeblockSamples) 1013 { 1014 if(isBelowAvail) 1015 { 1016 startX = 0; 1017 endX = width; 1018 1019 for(y=0; y<skipLinesB[typeIdx]; y++) 1020 { 1021 srcLineBelow = srcLine + srcStride; 1022 srcLineAbove = srcLine - srcStride; 1023 1024 for (x=startX; x<endX; x++) 1025 { 1026 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]]; 1027 diff [edgeType] += (orgLine[x] - srcLine[x]); 1028 count[edgeType] ++; 1029 } 1030 srcLine += srcStride; 1031 orgLine += orgStride; 1032 } 1033 } 1034 } 1035 #endif 1036 1037 } 1038 break; 1039 case SAO_TYPE_EO_135: 1040 { 1041 diff +=2; 1042 count+=2; 1043 Char *signUpLine, *signDownLine, *signTmpLine; 1044 1045 signUpLine = m_signLineBuf1; 1046 signDownLine= m_signLineBuf2; 1047 1048 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1049 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1050 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1051 ; 1052 #else 1053 startX = isLeftAvail ? 0 : 1 ; 1054 #endif 1055 1056 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1057 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1)) 1058 : (isRightAvail ? width : (width - 1)) 1059 ; 1060 #else 1061 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 1062 #endif 1063 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1064 1065 //prepare 2nd line's upper sign 1066 Pel* srcLineBelow = srcLine + srcStride; 1067 for (x=startX; x<endX+1; x++) 1068 { 1069 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]]; 1070 } 1071 1072 //1st line 1073 Pel* srcLineAbove = srcLine - srcStride; 1074 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1075 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0 : 1) : startX; 1076 firstLineEndX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? endX : 1) : endX; 1077 #else 1078 firstLineStartX = isAboveLeftAvail ? 0 : 1; 1079 firstLineEndX = isAboveAvail ? endX : 1; 1080 #endif 1081 for(x=firstLineStartX; x<firstLineEndX; x++) 1082 { 1083 edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1]; 1084 diff [edgeType] += (orgLine[x] - srcLine[x]); 1085 count[edgeType] ++; 1086 } 1087 srcLine += srcStride; 1088 orgLine += orgStride; 1089 1090 1091 //middle lines 1092 for (y=1; y<endY; y++) 1093 { 1094 srcLineBelow = srcLine + srcStride; 1095 1096 for (x=startX; x<endX; x++) 1097 { 1098 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ; 1099 edgeType = signDown + signUpLine[x]; 1100 diff [edgeType] += (orgLine[x] - srcLine[x]); 1101 count[edgeType] ++; 1102 1103 signDownLine[x+1] = -signDown; 1104 } 1105 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]]; 1106 1107 signTmpLine = signUpLine; 1108 signUpLine = signDownLine; 1109 signDownLine = signTmpLine; 1110 1111 srcLine += srcStride; 1112 orgLine += orgStride; 1113 } 1114 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1115 if(isCalculatePreDeblockSamples) 1116 { 1117 if(isBelowAvail) 1118 { 1119 startX = isLeftAvail ? 0 : 1 ; 1120 endX = isRightAvail ? width : (width -1); 1121 1122 for(y=0; y<skipLinesB[typeIdx]; y++) 1123 { 1124 srcLineBelow = srcLine + srcStride; 1125 srcLineAbove = srcLine - srcStride; 1126 1127 for (x=startX; x< endX; x++) 1128 { 1129 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]]; 1130 diff [edgeType] += (orgLine[x] - srcLine[x]); 1131 count[edgeType] ++; 1132 } 1133 srcLine += srcStride; 1134 orgLine += orgStride; 1135 } 1136 } 1137 } 1138 #endif 1139 } 1140 break; 1141 case SAO_TYPE_EO_45: 1142 { 1143 diff +=2; 1144 count+=2; 1145 Char *signUpLine = m_signLineBuf1+1; 1146 1147 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1148 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1149 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1150 ; 1151 #else 1152 startX = isLeftAvail ? 0 : 1; 1153 #endif 1154 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1155 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1156 : (isRightAvail ? width : (width - 1)) 1157 ; 1158 #else 1159 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1); 1160 #endif 1161 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1162 1163 //prepare 2nd line upper sign 1164 Pel* srcLineBelow = srcLine + srcStride; 1165 for (x=startX-1; x<endX; x++) 1166 { 1167 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]]; 1168 } 1169 1170 1171 //first line 1172 Pel* srcLineAbove = srcLine - srcStride; 1173 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1174 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX) 1175 : startX 1176 ; 1177 firstLineEndX = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX) 1178 : endX 1179 ; 1180 #else 1181 firstLineStartX = isAboveAvail ? startX : endX; 1182 firstLineEndX = (!isRightAvail && isAboveRightAvail) ? width : endX; 1183 #endif 1184 for(x=firstLineStartX; x<firstLineEndX; x++) 1185 { 1186 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1]; 1187 diff [edgeType] += (orgLine[x] - srcLine[x]); 1188 count[edgeType] ++; 1189 } 1190 1191 srcLine += srcStride; 1192 orgLine += orgStride; 1193 1194 //middle lines 1195 for (y=1; y<endY; y++) 1196 { 1197 srcLineBelow = srcLine + srcStride; 1198 1199 for(x=startX; x<endX; x++) 1200 { 1201 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ; 1202 edgeType = signDown + signUpLine[x]; 1203 1204 diff [edgeType] += (orgLine[x] - srcLine[x]); 1205 count[edgeType] ++; 1206 1207 signUpLine[x-1] = -signDown; 1208 } 1209 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]]; 1210 srcLine += srcStride; 1211 orgLine += orgStride; 1212 } 1213 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1214 if(isCalculatePreDeblockSamples) 1215 { 1216 if(isBelowAvail) 1217 { 1218 startX = isLeftAvail ? 0 : 1 ; 1219 endX = isRightAvail ? width : (width -1); 1220 1221 for(y=0; y<skipLinesB[typeIdx]; y++) 1222 { 1223 srcLineBelow = srcLine + srcStride; 1224 srcLineAbove = srcLine - srcStride; 1225 1226 for (x=startX; x<endX; x++) 1227 { 1228 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]]; 1229 diff [edgeType] += (orgLine[x] - srcLine[x]); 1230 count[edgeType] ++; 1231 } 1232 srcLine += srcStride; 1233 orgLine += orgStride; 1234 } 1235 } 1236 } 1237 #endif 1238 } 1239 break; 1240 case SAO_TYPE_BO: 1241 { 1242 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1243 startX = (!isCalculatePreDeblockSamples)?0 1244 :( isRightAvail?(width- skipLinesR[typeIdx]):width) 1245 ; 1246 endX = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width ) 1247 :width 1248 ; 1249 #else 1250 endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width; 1251 #endif 1252 endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height; 1253 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2; 1254 for (y=0; y< endY; y++) 1255 { 1256 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1257 for (x=startX; x< endX; x++) 1258 #else 1259 for (x=0; x< endX; x++) 1260 #endif 1261 { 1262 1263 Int bandIdx= srcLine[x] >> shiftBits; 1264 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1265 count[bandIdx] ++; 1266 } 1267 srcLine += srcStride; 1268 orgLine += orgStride; 1269 } 1270 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1271 if(isCalculatePreDeblockSamples) 1272 { 1273 if(isBelowAvail) 1274 { 1275 startX = 0; 1276 endX = width; 1277 1278 for(y= 0; y< skipLinesB[typeIdx]; y++) 1279 { 1280 for (x=startX; x< endX; x++) 1281 { 1282 Int bandIdx= srcLine[x] >> shiftBits; 1283 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1284 count[bandIdx] ++; 1285 } 1286 srcLine += srcStride; 1287 orgLine += orgStride; 1288 1289 } 1290 1291 } 1292 } 1293 #endif 1294 } 1295 break; 1296 default: 1297 { 1298 printf("Not a supported SAO types\n"); 1299 assert(0); 1300 exit(-1); 1301 } 1302 } 1303 } 1304 } 1305 1306 #else 1307 1308 1309 47 1310 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 48 1311 { … … 1661 2924 } 1662 2925 1663 #if SAO_CHROMA_LAMBDA1664 2926 /** Sample adaptive offset process 1665 2927 * \param pcSaoParam … … 1671 2933 #else 1672 2934 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma) 1673 #endif1674 #else1675 /** Sample adaptive offset process1676 * \param dLambda1677 */1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)1679 2935 #endif 1680 2936 { … … 2501 3757 } 2502 3758 3759 #endif 3760 2503 3761 //! \} -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
r313 r532 53 53 // Class definition 54 54 // ==================================================================================================================== 55 56 #if HM_CLEANUP_SAO 57 enum SAOCabacStateLablesRDO //CABAC state labels 58 { 59 SAO_CABACSTATE_PIC_INIT =0, 60 SAO_CABACSTATE_BLK_CUR, 61 SAO_CABACSTATE_BLK_NEXT, 62 SAO_CABACSTATE_BLK_MID, 63 SAO_CABACSTATE_BLK_TEMP, 64 NUM_SAO_CABACSTATE_LABELS 65 }; 66 67 struct SAOStatData //data structure for SAO statistics 68 { 69 Int64 diff[MAX_NUM_SAO_CLASSES]; 70 Int64 count[MAX_NUM_SAO_CLASSES]; 71 72 SAOStatData(){} 73 ~SAOStatData(){} 74 Void reset() 75 { 76 ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 77 ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 78 } 79 const SAOStatData& operator=(const SAOStatData& src) 80 { 81 ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 82 ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 83 return *this; 84 } 85 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 86 const SAOStatData& operator+= (const SAOStatData& src) 87 { 88 for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++) 89 { 90 diff[i] += src.diff[i]; 91 count[i] += src.count[i]; 92 } 93 return *this; 94 } 95 #endif 96 }; 97 98 class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset 99 { 100 public: 101 TEncSampleAdaptiveOffset(); 102 virtual ~TEncSampleAdaptiveOffset(); 103 104 //interface 105 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 106 Void createEncData(Bool isPreDBFSamplesUsed); 107 #else 108 Void createEncData(); 109 #endif 110 Void destroyEncData(); 111 Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ; 112 Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 113 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 114 , Bool isPreDBFSamplesUsed 115 #endif 116 ); 117 public: //methods 118 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 119 Void getPreDBFStatistics(TComPic* pPic); 120 #endif 121 private: //methods 122 Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic 123 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 124 , Bool isCalculatePreDeblockSamples = false 125 #endif 126 ); 127 Void decidePicParams(Bool* sliceEnabled, Int picTempLayer); 128 Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams); 129 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 130 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 131 , Bool isCalculatePreDeblockSamples 132 #endif 133 ); 134 Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 135 Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 136 Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData); 137 Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo); 138 inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift); 139 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 ); 140 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 141 Void addPreDBFStatistics(SAOStatData*** blkStats); 142 #endif 143 private: //members 144 //for RDO 145 TEncSbac** m_pppcRDSbacCoder; 146 TEncSbac* m_pcRDGoOnSbacCoder; 147 TEncBinCABACCounter** m_pppcBinCoderCABAC; 148 Double m_labmda[NUM_SAO_COMPONENTS]; 149 150 //statistics 151 SAOStatData*** m_statData; //[ctu][comp][classes] 152 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 153 SAOStatData*** m_preDBFstatData; 154 #endif 155 #if SAO_ENCODING_CHOICE 156 Double m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER]; 157 #endif 158 Int m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 159 Int m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 160 }; 161 #else 162 55 163 56 164 class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset … … 95 203 Void endSaoEnc(); 96 204 Void resetStats(); 97 #if SAO_CHROMA_LAMBDA98 205 #if SAO_ENCODING_CHOICE 99 206 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth); 100 207 #else 101 208 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma); 102 #endif103 #else104 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);105 209 #endif 106 210 … … 131 235 Int getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; } 132 236 }; 133 237 #endif 134 238 //! \} 135 239 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSbac.cpp
r494 r532 416 416 { 417 417 PartSize eSize = pcCU->getPartitionSize( uiAbsPartIdx ); 418 419 418 if ( pcCU->isIntra( uiAbsPartIdx ) ) 420 419 { … … 1394 1393 { 1395 1394 m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) ); 1395 #if HM_CLEANUP_SAO 1396 m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 ); 1397 #else 1396 1398 m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 ); 1399 #endif 1397 1400 } 1398 1401 } … … 1597 1600 } 1598 1601 1602 #if HM_CLEANUP_SAO 1603 Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled) 1604 { 1605 UInt uiSymbol; 1606 if(!sliceEnabled) 1607 { 1608 assert(ctbParam.modeIdc == SAO_MODE_OFF); 1609 return; 1610 } 1611 1612 //type 1613 if(compIdx == SAO_Y || compIdx == SAO_Cb) 1614 { 1615 //sao_type_idx_luma or sao_type_idx_chroma 1616 if(ctbParam.modeIdc == SAO_MODE_OFF) 1617 { 1618 uiSymbol =0; 1619 } 1620 else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO 1621 { 1622 uiSymbol = 1; 1623 } 1624 else 1625 { 1626 assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO 1627 uiSymbol = 2; 1628 } 1629 codeSaoTypeIdx(uiSymbol); 1630 } 1631 1632 if(ctbParam.modeIdc == SAO_MODE_NEW) 1633 { 1634 Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES; 1635 Int offset[4]; 1636 Int k=0; 1637 for(Int i=0; i< numClasses; i++) 1638 { 1639 if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN) 1640 { 1641 continue; 1642 } 1643 Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?( (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES ):i; 1644 offset[k] = ctbParam.offset[classIdx]; 1645 k++; 1646 } 1647 1648 for(Int i=0; i< 4; i++) 1649 { 1650 codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]), g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs 1651 } 1652 1653 1654 if(ctbParam.typeIdc == SAO_TYPE_BO) 1655 { 1656 for(Int i=0; i< 4; i++) 1657 { 1658 if(offset[i] != 0) 1659 { 1660 codeSAOSign((offset[i]< 0)?1:0); 1661 } 1662 } 1663 1664 codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position 1665 } 1666 else //EO 1667 { 1668 if(compIdx == SAO_Y || compIdx == SAO_Cb) 1669 { 1670 assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0); 1671 codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma 1672 } 1673 } 1674 1675 } 1676 } 1677 1678 1679 Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam 1680 , Bool* sliceEnabled 1681 , Bool leftMergeAvail 1682 , Bool aboveMergeAvail 1683 , Bool onlyEstMergeInfo // = false 1684 ) 1685 { 1686 1687 Bool isLeftMerge = false; 1688 Bool isAboveMerge= false; 1689 1690 if(leftMergeAvail) 1691 { 1692 isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT)); 1693 codeSaoMerge( isLeftMerge?1:0 ); //sao_merge_left_flag 1694 } 1695 1696 if( aboveMergeAvail && !isLeftMerge) 1697 { 1698 isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE)); 1699 codeSaoMerge( isAboveMerge?1:0 ); //sao_merge_left_flag 1700 } 1701 1702 if(onlyEstMergeInfo) 1703 { 1704 return; //only for RDO 1705 } 1706 1707 if(!isLeftMerge && !isAboveMerge) //not merge mode 1708 { 1709 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 1710 { 1711 codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]); 1712 } 1713 } 1714 } 1715 #endif 1716 1599 1717 //! \} -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSbac.h
r345 r532 103 103 Void codeSAOSign ( UInt uiCode); //<! code SAO offset sign 104 104 Void codeScalingList ( TComScalingList* /*scalingList*/ ){ assert (0); return;}; 105 106 #if HM_CLEANUP_SAO 107 Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled); 108 Void codeSAOBlkParam(SAOBlkParam& saoBlkParam 109 , Bool* sliceEnabled 110 , Bool leftMergeAvail 111 , Bool aboveMergeAvail 112 , Bool onlyEstMergeInfo = false 113 ); 114 #endif 105 115 106 116 private: -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp
r494 r532 720 720 Pel* piRefPos; 721 721 Int iRefStride = m_filteredBlock[0][0].getStride(); 722 #if NS_HAD723 m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );724 #else725 722 m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() ); 726 #endif727 723 728 724 const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ); … … 737 733 piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr(); 738 734 if ( horVal == 2 && ( verVal & 1 ) == 0 ) 735 { 739 736 piRefPos += 1; 737 } 740 738 if ( ( horVal & 1 ) == 0 && verVal == 2 ) 739 { 741 740 piRefPos += iRefStride; 741 } 742 742 cMvTest = pcMvRefine[i]; 743 743 cMvTest += rcMvFrac; … … 774 774 UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth; 775 775 776 { 777 if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 ) 778 { 779 assert( uiSubdiv ); 780 } 781 else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) 782 { 783 assert( uiSubdiv ); 784 } 785 else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) 786 { 787 assert( !uiSubdiv ); 788 } 789 else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 790 { 791 assert( !uiSubdiv ); 792 } 793 else 794 { 795 assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); 796 if( bLuma ) 797 { 798 m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); 799 } 776 if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 ) 777 { 778 assert( uiSubdiv ); 779 } 780 else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ) 781 { 782 assert( uiSubdiv ); 783 } 784 else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) 785 { 786 assert( !uiSubdiv ); 787 } 788 else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 789 { 790 assert( !uiSubdiv ); 791 } 792 else 793 { 794 assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); 795 if( bLuma ) 796 { 797 m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize ); 800 798 } 801 799 } … … 806 804 { 807 805 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) ) 806 { 808 807 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); 808 } 809 809 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) ) 810 { 810 811 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); 812 } 811 813 } 812 814 } … … 822 824 } 823 825 824 { 825 //===== Cbfs ===== 826 if( bLuma ) 827 { 828 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 829 } 826 //===== Cbfs ===== 827 if( bLuma ) 828 { 829 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 830 830 } 831 831 } … … 944 944 } 945 945 } 946 947 946 if( bChroma ) 948 947 { … … 1306 1305 1307 1306 #if RDOQ_CHROMA_LAMBDA 1308 m_pcTrQuant->selectLambda (TEXT_CHROMA);1307 m_pcTrQuant->selectLambda(eText); 1309 1308 #endif 1310 1309 m_pcTrQuant->transformNxN ( pcCU, piResi, uiStride, pcCoeff, … … 1358 1357 1359 1358 //===== update distortion ===== 1360 #if WEIGHTED_CHROMA_DISTORTION1361 1359 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText ); 1362 #else1363 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );1364 #endif1365 1360 } 1366 1361 … … 2539 2534 2540 2535 for( Int j=0; j < numCand; j++) 2541 2542 2536 { 2543 2537 Bool mostProbableModeIncluded = false; … … 3039 3033 pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(), 3040 3034 m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(), 3041 #if NS_HAD3042 iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );3043 #else3044 3035 iWidth, iHeight, m_pcEncCfg->getUseHADME() ); 3045 #endif3046 3036 ruiErr = cDistParam.DistFunc( &cDistParam ); 3047 3037 } … … 3246 3236 3247 3237 UInt uiCostTempL0[MAX_NUM_REF]; 3248 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT; 3238 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) 3239 { 3240 uiCostTempL0[iNumRef] = MAX_UINT; 3241 } 3249 3242 UInt uiBitsTempL0[MAX_NUM_REF]; 3250 3243 … … 3716 3709 { 3717 3710 uiLastMode = 2; 3718 { 3719 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3720 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3721 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3722 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3723 } 3724 { 3725 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; 3726 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3727 } 3728 { 3729 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; 3730 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3731 } 3711 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3712 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3713 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3714 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3715 3716 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; 3717 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3718 3719 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; 3720 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3732 3721 3733 3722 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); … … 3743 3732 { 3744 3733 uiLastMode = 0; 3745 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3746 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3747 { 3748 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 3749 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3750 } 3734 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3735 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3736 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 3737 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3751 3738 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 3752 3739 … … 3759 3746 { 3760 3747 uiLastMode = 1; 3761 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3762 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3763 { 3764 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 3765 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3766 } 3748 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3749 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3750 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 3751 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 3767 3752 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 3768 3753 … … 3816 3801 pcCU->setMergeIndexSubParts( uiMRGIndex, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 3817 3802 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 3818 { 3819 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3820 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3821 } 3803 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3804 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3822 3805 3823 3806 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); … … 3834 3817 pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 3835 3818 pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 3836 { 3837 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3838 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3839 } 3819 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 3820 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 3840 3821 } 3841 3822 } … … 3944 3925 3945 3926 if (iNum == 1) 3927 { 3946 3928 return 0; 3929 } 3947 3930 3948 3931 UInt uiLength = 1; … … 4123 4106 pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), 4124 4107 pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), 4125 #if NS_HAD4126 iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );4127 #else4128 4108 iSizeX, iSizeY, m_pcEncCfg->getUseHADME() ); 4129 #endif4130 4109 ruiDist = cDistParam.DistFunc( &cDistParam ); 4131 4110 uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] ); 4132 4111 #else 4133 #if WEIGHTED_CHROMA_DISTORTION4134 4112 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD ); 4135 #else4136 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );4137 #endif4138 4113 uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD ); 4139 4114 #endif … … 4228 4203 m_pcRdCost->getMotionCost( 1, 0 ); 4229 4204 m_pcRdCost->setCostScale ( 1 ); 4230 4231 { 4205 4232 4206 #if REF_IDX_ME_ZEROMV 4233 4234 4235 4236 4237 4238 4239 4240 4207 if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId())) //ILR reference pic 4208 { 4209 xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi ); 4210 } 4211 else //non ILR reference pic 4212 { 4213 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi ); 4214 } 4241 4215 #else 4242 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost 4243 ,bBi 4244 ); 4245 #endif 4246 } 4247 4248 4249 4216 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi ); 4217 #endif 4218 4250 4219 m_pcRdCost->setCostScale( 0 ); 4251 4220 rcMv <<= 2; … … 4601 4570 pcYuvPred->copyToPartYuv( rpcYuvRec, 0 ); 4602 4571 4603 #if WEIGHTED_CHROMA_DISTORTION4604 4572 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4605 4573 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) 4606 4574 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); 4607 #else4608 uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )4609 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )4610 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );4611 #endif4612 4575 4613 4576 if( m_bUseSBACRD ) 4577 { 4614 4578 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]); 4579 } 4615 4580 4616 4581 m_pcEntropyCoder->resetBits(); … … 4628 4593 4629 4594 if( m_bUseSBACRD ) 4595 { 4630 4596 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]); 4597 } 4631 4598 4632 4599 pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) ); … … 4799 4766 4800 4767 // update with clipped distortion and cost (qp estimation loop uses unclipped values) 4801 #if WEIGHTED_CHROMA_DISTORTION4802 4768 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 4803 4769 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) 4804 4770 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); 4805 #else4806 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )4807 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )4808 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );4809 #endif4810 4771 dCostBest = m_pcRdCost->calcRdCost( uiBitsBest, uiDistortionBest ); 4811 4772 … … 4832 4793 Bool bCheckFull; 4833 4794 if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) ) 4795 { 4834 4796 bCheckFull = false; 4797 } 4835 4798 else 4799 { 4836 4800 bCheckFull = ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ); 4801 } 4837 4802 4838 4803 const Bool bCheckSplit = ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); … … 4932 4897 4933 4898 #if RDOQ_CHROMA_LAMBDA 4934 m_pcTrQuant->selectLambda(TEXT_CHROMA );4899 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 4935 4900 #endif 4936 4901 … … 4943 4908 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 4944 4909 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 4910 4911 #if RDOQ_CHROMA_LAMBDA 4912 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 4913 #endif 4914 4945 4915 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 4946 4916 #if ADAPTIVE_QP_SELECTION … … 4955 4925 m_pcEntropyCoder->resetBits(); 4956 4926 4957 { 4958 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 4959 } 4960 4927 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 4928 4961 4929 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); 4962 4930 const UInt uiSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits(); … … 4966 4934 if( bCodeChroma ) 4967 4935 { 4968 { 4969 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 4970 } 4936 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 4971 4937 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); 4972 4938 uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY; 4973 4939 4974 { 4975 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 4976 } 4940 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 4977 4941 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); 4978 4942 uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU ); … … 5003 4967 assert(scalingListType < 6); 5004 4968 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 4969 5005 4970 const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), 5006 4971 pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); … … 5059 5024 { 5060 5025 uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 5061 #if WEIGHTED_CHROMA_DISTORTION5062 5026 , TEXT_CHROMA_U 5063 #endif5064 5027 ); // initialized with zero residual destortion 5065 5028 if ( puiZeroDist ) … … 5080 5043 const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 5081 5044 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 5082 #if WEIGHTED_CHROMA_DISTORTION5083 5045 , TEXT_CHROMA_U 5084 #endif5085 5046 ); 5086 5047 … … 5118 5079 { 5119 5080 m_pcEntropyCoder->resetBits(); 5120 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode C);5081 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode ); 5121 5082 const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); 5122 5083 minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU ); … … 5134 5095 5135 5096 uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 5136 #if WEIGHTED_CHROMA_DISTORTION5137 5097 , TEXT_CHROMA_V 5138 #endif5139 5098 ); // initialized with zero residual destortion 5140 5099 if ( puiZeroDist ) … … 5154 5113 const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 5155 5114 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 5156 #if WEIGHTED_CHROMA_DISTORTION5157 5115 , TEXT_CHROMA_V 5158 #endif5159 5116 ); 5160 5117 if (pcCU->isLosslessCoded(0)) … … 5191 5148 { 5192 5149 m_pcEntropyCoder->resetBits(); 5193 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode C);5150 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode ); 5194 5151 const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits(); 5195 5152 minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV ); … … 5352 5309 5353 5310 #if RDOQ_CHROMA_LAMBDA 5354 m_pcTrQuant->selectLambda(TEXT_CHROMA );5311 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 5355 5312 #endif 5356 5313 … … 5362 5319 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 5363 5320 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 5321 #if RDOQ_CHROMA_LAMBDA 5322 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 5323 #endif 5364 5324 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 5365 5325 #if ADAPTIVE_QP_SELECTION … … 5391 5351 uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 5392 5352 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 5393 #if WEIGHTED_CHROMA_DISTORTION5394 5353 , TEXT_CHROMA_U 5395 #endif5396 5354 ); 5397 5355 … … 5435 5393 uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 5436 5394 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 5437 #if WEIGHTED_CHROMA_DISTORTION5438 5395 , TEXT_CHROMA_V 5439 #endif5440 5396 ); 5441 5397 … … 5474 5430 m_pcEntropyCoder->resetBits(); 5475 5431 5476 { 5477 if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 5478 { 5479 m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize ); 5480 } 5481 } 5482 5483 { 5484 if( bCodeChroma ) 5485 { 5486 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 5487 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 5488 } 5489 5490 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 5491 } 5432 if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 5433 { 5434 m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize ); 5435 } 5436 5437 if( bCodeChroma ) 5438 { 5439 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 5440 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 5441 } 5442 5443 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 5492 5444 5493 5445 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); … … 5546 5498 m_pcEntropyCoder->resetBits(); 5547 5499 5548 { 5549 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true, TEXT_LUMA ); 5550 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA ); 5551 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U ); 5552 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V ); 5553 } 5554 5500 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true, TEXT_LUMA ); 5501 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA ); 5502 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U ); 5503 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V ); 5504 5555 5505 uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits(); 5556 5506 dSubdivCost = m_pcRdCost->calcRdCost( uiSubdivBits, uiSubdivDist ); … … 5602 5552 const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; 5603 5553 5604 { 5605 if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 5606 { 5607 m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize ); 5608 } 5609 } 5610 5611 { 5612 assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA ); 5554 if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 5555 { 5556 m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize ); 5557 } 5558 5559 assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA ); 5613 5560 if( bSubdivAndCbf ) 5614 5561 { … … 5631 5578 } 5632 5579 } 5633 }5634 5580 5635 5581 if( !bSubdiv ) … … 5655 5601 if( bSubdivAndCbf ) 5656 5602 { 5657 { 5658 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 5659 } 5603 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 5660 5604 } 5661 5605 else … … 5725 5669 if( bCodeChroma ) 5726 5670 { 5727 { 5728 m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC ); 5729 } 5671 m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC ); 5730 5672 } 5731 5673 } … … 5847 5789 m_pcEntropyCoder->encodePartSize( pcCU, 0, pcCU->getDepth(0), true ); 5848 5790 m_pcEntropyCoder->encodePredInfo( pcCU, 0, true ); 5849 5850 5791 Bool bDummy = false; 5851 5792 m_pcEntropyCoder->encodeCoeff ( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0), bDummy ); -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSearch.h
r494 r532 194 194 UInt uiPreCalcDistC ); 195 195 196 196 197 /// encoder estimation - inter prediction (non-skip) 197 198 Void predInterSearch ( TComDataCU* pcCU, -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp
r524 r532 295 295 dQP += pdQPs[ rpcSlice->getPOC() ]; 296 296 } 297 #if !RATE_CONTROL_LAMBDA_DOMAIN298 if ( m_pcCfg->getUseRateCtrl())299 {300 dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());301 }302 #endif303 297 // ------------------------------------------------------------------------------------------------------------------ 304 298 // Lambda computation … … 386 380 // store lambda 387 381 m_pcRdCost ->setLambda( dLambda ); 388 #if WEIGHTED_CHROMA_DISTORTION389 382 // for RDO 390 383 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 391 Double weight = 1.0;384 Double weight[2] = { 1.0, 1.0 }; 392 385 Int qpc; 393 386 Int chromaQPOffset; … … 395 388 chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb(); 396 389 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 397 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset398 m_pcRdCost->setCbDistortionWeight(weight );390 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 391 m_pcRdCost->setCbDistortionWeight(weight[0]); 399 392 400 393 chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr(); 401 394 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 402 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 403 #if JCTVC_M0259_LAMBDAREFINEMENT 404 if( rpcSlice->getLayerId() > 0 && m_ppcTEncTop[layerId]->getNumActiveRefLayers() && m_pcCfg->getGOPSize() >= 8 && rpcSlice->isIntra() == false && depth == 0 ) 405 { 406 dLambda *= 1.1; 407 weight *= 1.15; 408 } 409 #endif 410 m_pcRdCost->setCrDistortionWeight(weight); 411 #endif 412 395 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 396 m_pcRdCost->setCrDistortionWeight(weight[1]); 397 398 const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])}; 399 413 400 #if RDOQ_CHROMA_LAMBDA 414 401 // for RDOQ 415 m_pcTrQuant->setLambda ( dLambda, dLambda / weight);402 m_pcTrQuant->setLambdas( lambdaArray ); 416 403 #else 417 404 m_pcTrQuant->setLambda( dLambda ); 418 405 #endif 419 406 420 #if SAO_CHROMA_LAMBDA421 407 // For SAO 422 rpcSlice ->setLambda( dLambda, dLambda / weight ); 423 #else 424 rpcSlice ->setLambda( dLambda ); 425 #endif 408 rpcSlice->setLambdas( lambdaArray ); 426 409 427 410 #if HB_LAMBDA_FOR_LDC … … 500 483 501 484 pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId ); 502 503 485 if(eSliceType==I_SLICE) 504 486 { … … 552 534 } 553 535 554 #if RATE_CONTROL_LAMBDA_DOMAIN555 536 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda ) 556 537 { … … 561 542 slice->setSliceQpBase ( sliceQP ); 562 543 m_pcRdCost ->setLambda( lambda ); 563 #if WEIGHTED_CHROMA_DISTORTION564 544 // for RDO 565 545 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 566 Double weight ;546 Double weight[2] = { 1.0, 1.0 }; 567 547 Int qpc; 568 548 Int chromaQPOffset; … … 570 550 chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb(); 571 551 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 572 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset573 m_pcRdCost->setCbDistortionWeight(weight );552 weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 553 m_pcRdCost->setCbDistortionWeight(weight[0]); 574 554 575 555 chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr(); 576 556 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 577 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 578 m_pcRdCost->setCrDistortionWeight(weight); 579 #endif 557 weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 558 m_pcRdCost->setCrDistortionWeight(weight[1]); 559 560 const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])}; 580 561 581 562 #if RDOQ_CHROMA_LAMBDA 582 563 // for RDOQ 583 m_pcTrQuant->setLambda ( lambda, lambda / weight);564 m_pcTrQuant->setLambdas( lambdaArray ); 584 565 #else 585 566 m_pcTrQuant->setLambda( lambda ); 586 567 #endif 587 568 588 #if SAO_CHROMA_LAMBDA589 569 // For SAO 590 slice ->setLambda( lambda, lambda / weight ); 591 #else 592 slice ->setLambda( lambda ); 593 #endif 570 slice->setLambdas( lambdaArray ); 594 571 } 595 #else596 /**597 - lambda re-computation based on rate control QP598 */599 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)600 {601 Int qp;602 Double recalQP= (Double)changeQP;603 Double origQP = (Double)recalQP;604 Double lambda;605 606 // pre-compute lambda and QP values for all possible QP candidates607 for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )608 {609 // compute QP value610 recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);611 612 // compute lambda value613 Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );614 Int SHIFT_QP = 12;615 Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );616 #if FULL_NBIT617 Int bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);618 #else619 Int bitdepth_luma_qp_scale = 0;620 #endif621 Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;622 #if FULL_NBIT623 Double qp_temp_orig = (Double) recalQP - SHIFT_QP;624 #endif625 // Case #1: I or P-slices (key-frame)626 Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;627 if ( eSliceType==I_SLICE )628 {629 dQPFactor=0.57*dLambda_scale;630 }631 lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );632 633 if ( depth>0 )634 {635 #if FULL_NBIT636 lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )637 #else638 lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )639 #endif640 }641 642 // if hadamard is used in ME process643 if ( !m_pcCfg->getUseHADME() )644 {645 lambda *= 0.95;646 }647 648 #if REPN_FORMAT_IN_VPS649 qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );650 #else651 qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );652 #endif653 654 m_pdRdPicLambda[deltqQpIdx] = lambda;655 m_pdRdPicQp [deltqQpIdx] = recalQP;656 m_piRdPicQp [deltqQpIdx] = qp;657 }658 659 // obtain dQP = 0 case660 lambda = m_pdRdPicLambda[0];661 recalQP = m_pdRdPicQp [0];662 qp = m_piRdPicQp [0];663 664 if( pcSlice->getSliceType( ) != I_SLICE )665 {666 lambda *= m_pcCfg->getLambdaModifier( depth );667 }668 669 // store lambda670 m_pcRdCost ->setLambda( lambda );671 #if WEIGHTED_CHROMA_DISTORTION672 // for RDO673 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.674 Double weight = 1.0;675 Int qpc;676 Int chromaQPOffset;677 678 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();679 qpc = Clip3( 0, 57, qp + chromaQPOffset);680 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset681 m_pcRdCost->setCbDistortionWeight(weight);682 683 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();684 qpc = Clip3( 0, 57, qp + chromaQPOffset);685 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset686 m_pcRdCost->setCrDistortionWeight(weight);687 #endif688 689 #if RDOQ_CHROMA_LAMBDA690 // for RDOQ691 m_pcTrQuant->setLambda( lambda, lambda / weight );692 #else693 m_pcTrQuant->setLambda( lambda );694 #endif695 696 #if SAO_CHROMA_LAMBDA697 // For SAO698 pcSlice ->setLambda( lambda, lambda / weight );699 #else700 pcSlice ->setLambda( lambda );701 #endif702 }703 #endif704 572 // ==================================================================================================================== 705 573 // Public member functions … … 741 609 } 742 610 743 #if RATE_CONTROL_LAMBDA_DOMAIN744 611 if ( m_pcCfg->getUseRateCtrl() ) 745 612 { … … 747 614 assert(0); 748 615 } 749 #endif750 616 751 617 TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx()); … … 779 645 #endif 780 646 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 781 #if WEIGHTED_CHROMA_DISTORTION782 647 // for RDO 783 648 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 784 649 Int iQP = m_piRdPicQp [uiQpIdx]; 785 Double weight = 1.0;650 Double weight[2] = { 1.0, 1.0 }; 786 651 Int qpc; 787 652 Int chromaQPOffset; … … 789 654 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 790 655 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 791 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset792 m_pcRdCost->setCbDistortionWeight(weight );656 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 657 m_pcRdCost->setCbDistortionWeight(weight[0]); 793 658 794 659 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 795 660 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 796 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset797 m_pcRdCost->setCrDistortionWeight(weight );798 #endif 799 661 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 662 m_pcRdCost->setCrDistortionWeight(weight[1]); 663 664 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])}; 800 665 #if RDOQ_CHROMA_LAMBDA 801 666 // for RDOQ 802 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight);667 m_pcTrQuant->setLambdas( lambdaArray ); 803 668 #else 804 669 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 805 670 #endif 806 #if SAO_CHROMA_LAMBDA807 671 // For SAO 808 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 809 #else 810 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 811 #endif 672 pcSlice->setLambdas( lambdaArray ); 812 673 813 674 // try compress … … 836 697 #endif 837 698 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 838 #if WEIGHTED_CHROMA_DISTORTION839 699 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 840 700 Int iQP = m_piRdPicQp [uiQpIdxBest]; 841 Double weight = 1.0;701 Double weight[2] = { 1.0, 1.0 }; 842 702 Int qpc; 843 703 Int chromaQPOffset; … … 845 705 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 846 706 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 847 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset848 m_pcRdCost->setCbDistortionWeight(weight );707 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 708 m_pcRdCost->setCbDistortionWeight(weight[0]); 849 709 850 710 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 851 711 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 852 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset853 m_pcRdCost->setCrDistortionWeight(weight );854 #endif 855 712 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 713 m_pcRdCost->setCrDistortionWeight(weight[1]); 714 715 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])}; 856 716 #if RDOQ_CHROMA_LAMBDA 857 717 // for RDOQ 858 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight);718 m_pcTrQuant->setLambdas( lambdaArray ); 859 719 #else 860 720 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 861 721 #endif 862 #if SAO_CHROMA_LAMBDA863 722 // For SAO 864 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 865 #else 866 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 867 #endif 723 pcSlice->setLambdas( lambdaArray ); 868 724 } 869 725 870 726 /** \param rpcPic picture class 871 727 */ 872 #if RATE_CONTROL_INTRA873 728 Void TEncSlice::calCostSliceI(TComPic*& rpcPic) 874 729 { … … 909 764 m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice); 910 765 } 911 #endif912 766 913 767 Void TEncSlice::compressSlice( TComPic*& rpcPic ) … … 1037 891 UInt uiTileStartLCU = 0; 1038 892 UInt uiTileLCUX = 0; 1039 1040 893 Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag(); 1041 894 uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU()); … … 1086 939 pcCU->initCU( rpcPic, uiCUAddr ); 1087 940 1088 #if !RATE_CONTROL_LAMBDA_DOMAIN1089 if(m_pcCfg->getUseRateCtrl())1090 {1091 if(m_pcRateCtrl->calculateUnitQP())1092 {1093 xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );1094 }1095 }1096 #endif1097 941 // inherit from TR if necessary, select substream to use. 1098 942 if( m_pcCfg->getUseSBACRD() ) … … 1169 1013 ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true); 1170 1014 1171 #if RATE_CONTROL_LAMBDA_DOMAIN1172 1015 Double oldLambda = m_pcRdCost->getLambda(); 1173 1016 if ( m_pcCfg->getUseRateCtrl() ) … … 1177 1020 Double bpp = -1.0; 1178 1021 1179 #if M0036_RC_IMPROVEMENT1180 1022 if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() ) 1181 #else1182 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )1183 #endif1184 1023 { 1185 1024 estQP = pcSlice->getSliceQp(); … … 1187 1026 else 1188 1027 { 1189 #if RATE_CONTROL_INTRA1190 1028 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType()); 1191 1029 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE) … … 1198 1036 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() ); 1199 1037 } 1200 #else1201 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();1202 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );1203 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );1204 #endif1205 1038 1206 1039 #if REPN_FORMAT_IN_VPS … … 1211 1044 1212 1045 m_pcRdCost->setLambda(estLambda); 1213 #if M0036_RC_IMPROVEMENT1214 1046 #if RDOQ_CHROMA_LAMBDA 1215 1047 // set lambda for RDOQ 1216 1048 Double weight=m_pcRdCost->getChromaWeight(); 1217 m_pcTrQuant->setLambda( estLambda, estLambda / weight ); 1049 const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) }; 1050 m_pcTrQuant->setLambdas( lambdaArray ); 1218 1051 #else 1219 1052 m_pcTrQuant->setLambda( estLambda ); 1220 #endif1221 1053 #endif 1222 1054 } … … 1225 1057 pcCU->getSlice()->setSliceQpBase( estQP ); 1226 1058 } 1227 #endif1228 1059 1229 1060 // run CU encoder 1230 1061 m_pcCuEncoder->compressCU( pcCU ); 1231 1232 #if !TICKET_1090_FIX1233 #if RATE_CONTROL_LAMBDA_DOMAIN1234 if ( m_pcCfg->getUseRateCtrl() )1235 {1236 #if !M0036_RC_IMPROVEMENT1237 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD();1238 #if REPN_FORMAT_IN_VPS1239 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1240 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1241 #else1242 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1243 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1244 #endif1245 Double MAD = (Double)SAD / (Double)(height * width);1246 MAD = MAD * MAD;1247 ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;1248 #endif1249 1250 Int actualQP = g_RCInvalidQPValue;1251 Double actualLambda = m_pcRdCost->getLambda();1252 Int actualBits = pcCU->getTotalBits();1253 Int numberOfEffectivePixels = 0;1254 for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )1255 {1256 if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )1257 {1258 numberOfEffectivePixels = numberOfEffectivePixels + 16;1259 break;1260 }1261 }1262 1263 if ( numberOfEffectivePixels == 0 )1264 {1265 actualQP = g_RCInvalidQPValue;1266 }1267 else1268 {1269 actualQP = pcCU->getQP( 0 );1270 }1271 m_pcRdCost->setLambda(oldLambda);1272 #if RATE_CONTROL_INTRA1273 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,1274 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );1275 #else1276 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1277 #endif1278 }1279 #endif1280 #endif1281 1062 1282 1063 // restore entropy coder to an initial stage … … 1312 1093 } 1313 1094 1314 #if TICKET_1090_FIX1315 #if RATE_CONTROL_LAMBDA_DOMAIN1316 1095 if ( m_pcCfg->getUseRateCtrl() ) 1317 1096 { 1318 #if !M0036_RC_IMPROVEMENT1319 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD();1320 #if REPN_FORMAT_IN_VPS1321 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1322 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1323 #else1324 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1325 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1326 #endif1327 Double MAD = (Double)SAD / (Double)(height * width);1328 MAD = MAD * MAD;1329 ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;1330 #endif1331 1097 1332 1098 Int actualQP = g_RCInvalidQPValue; … … 1353 1119 m_pcRdCost->setLambda(oldLambda); 1354 1120 1355 #if RATE_CONTROL_INTRA1356 1121 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 1357 1122 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() ); 1358 #else 1359 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() ); 1360 #endif 1361 } 1362 #endif 1363 #endif 1123 } 1364 1124 } 1365 1125 // other case: encodeCU is not called … … 1383 1143 m_dPicRdCost += pcCU->getTotalCost(); 1384 1144 m_uiPicDist += pcCU->getTotalDistortion(); 1385 #if !RATE_CONTROL_LAMBDA_DOMAIN1386 if(m_pcCfg->getUseRateCtrl())1387 {1388 m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));1389 m_pcRateCtrl->updataRCUnitStatus();1390 }1391 #endif1392 1145 } 1393 1146 if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled) … … 1404 1157 } 1405 1158 xRestoreWPparam( pcSlice ); 1406 #if !RATE_CONTROL_LAMBDA_DOMAIN1407 if(m_pcCfg->getUseRateCtrl())1408 {1409 m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);1410 }1411 #endif1412 1159 } 1413 1160 … … 1609 1356 1610 1357 TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr ); 1358 #if HM_CLEANUP_SAO 1359 if ( pcSlice->getSPS()->getUseSAO() ) 1360 { 1361 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 1362 { 1363 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr]; 1364 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1365 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 1366 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 1367 1368 Bool leftMergeAvail = false; 1369 Bool aboveMergeAvail= false; 1370 //merge left condition 1371 Int rx = (uiCUAddr % uiWidthInLCUs); 1372 if(rx > 0) 1373 { 1374 leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1); 1375 } 1376 1377 //merge up condition 1378 Int ry = (uiCUAddr / uiWidthInLCUs); 1379 if(ry > 0) 1380 { 1381 aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs); 1382 } 1383 1384 m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail); 1385 } 1386 } 1387 #else 1611 1388 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 1612 1389 { … … 1691 1468 } 1692 1469 } 1470 #endif 1471 1693 1472 #if ENC_DEC_TRACE 1694 1473 g_bJustDoIt = g_bEncDecTraceEnable; -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncSlice.h
r494 r532 131 131 #endif 132 132 133 #if RATE_CONTROL_LAMBDA_DOMAIN134 133 Void resetQP ( TComPic* pic, Int sliceQP, Double lambda ); 135 #else136 Void xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);137 #endif138 134 // compress and encode slice 139 135 Void precompressSlice ( TComPic*& rpcPic ); ///< precompress slice for multi-loop opt. 140 136 Void compressSlice ( TComPic*& rpcPic ); ///< analysis stage of slice 141 #if RATE_CONTROL_INTRA142 137 Void calCostSliceI ( TComPic*& rpcPic ); 143 #endif144 138 Void encodeSlice ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams ); 145 139 -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
r531 r532 129 129 if (m_bUseSAO) 130 130 { 131 #if HM_CLEANUP_SAO 132 #if AUXILIARY_PICTURES 133 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 134 #else 135 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 136 #endif 137 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 138 m_cEncSAO.createEncData(getSaoLcuBoundary()); 139 #else 140 m_cEncSAO.createEncData(); 141 #endif 142 #else 131 143 m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); 132 144 m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); … … 134 146 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); 135 147 m_cEncSAO.createEncBuffer(); 148 #endif 136 149 } 137 150 #if ADAPTIVE_QP_SELECTION … … 143 156 m_cLoopFilter. create( g_uiMaxCUDepth ); 144 157 145 #if RATE_CONTROL_LAMBDA_DOMAIN146 158 if ( m_RCEnableRateControl ) 147 159 { … … 149 161 g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList ); 150 162 } 151 #else152 m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);153 #endif154 163 // if SBAC-based RD optimization is used 155 164 if( m_bUseSBACRD ) … … 250 259 if (m_cSPS.getUseSAO()) 251 260 { 261 #if HM_CLEANUP_SAO 262 m_cEncSAO.destroyEncData(); 263 m_cEncSAO.destroy(); 264 #else 252 265 m_cEncSAO.destroy(); 253 266 m_cEncSAO.destroyEncBuffer(); 267 #endif 254 268 } 255 269 m_cLoopFilter. destroy(); … … 401 415 { 402 416 // compress GOP 403 #if RATE_CONTROL_LAMBDA_DOMAIN404 417 #if !RC_SHVC_HARMONIZATION 405 418 if ( m_RCEnableRateControl ) … … 408 421 } 409 422 #endif 410 #endif411 423 412 424 // compress GOP 413 425 m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false); 414 426 415 #if RATE_CONTROL_LAMBDA_DOMAIN416 427 #if !RC_SHVC_HARMONIZATION 417 428 if ( m_RCEnableRateControl ) … … 419 430 m_cRateCtrl.destroyRCGOP(); 420 431 } 421 #endif422 432 #endif 423 433 … … 463 473 } 464 474 465 #if RATE_CONTROL_LAMBDA_DOMAIN466 475 if ( m_RCEnableRateControl ) 467 476 { 468 477 m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); 469 478 } 470 #endif471 479 472 480 // compress GOP … … 474 482 m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false); 475 483 476 #if RATE_CONTROL_LAMBDA_DOMAIN477 484 if ( m_RCEnableRateControl ) 478 485 { 479 486 m_cRateCtrl.destroyRCGOP(); 480 487 } 481 #endif482 488 483 489 iNumEncoded = m_iNumPicRcvd; … … 519 525 TComPic *pcTopField; 520 526 xGetNewPicBuffer( pcTopField ); 527 #if !HM_CLEANUP_SAO 521 528 pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO); 529 #endif 522 530 pcTopField->setReconMark (false); 523 531 … … 540 548 Pel * pcTopFieldU = pcTopField->getPicYuvOrg()->getCbAddr(); 541 549 Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); 542 550 543 551 // compute image characteristics 544 552 if ( getUseAdaptiveQP() ) 545 553 { 546 554 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); 547 } 548 555 } 556 549 557 /* -- Defield -- */ 550 558 … … 560 568 TComPic* pcBottomField; 561 569 xGetNewPicBuffer( pcBottomField ); 570 #if !HM_CLEANUP_SAO 562 571 pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO); 572 #endif 563 573 pcBottomField->setReconMark (false); 564 574 … … 581 591 Pel * pcBottomFieldU = pcBottomField->getPicYuvOrg()->getCbAddr(); 582 592 Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); 583 584 // Compute image characteristics593 594 // compute image characteristics 585 595 if ( getUseAdaptiveQP() ) 586 596 { 587 597 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); 588 } 589 598 } 599 590 600 /* -- Defield -- */ 591 601 … … 642 652 TComPic *pcTopField; 643 653 xGetNewPicBuffer( pcTopField ); 654 #if !HM_CLEANUP_SAO 644 655 pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO); 656 #endif 645 657 pcTopField->setReconMark (false); 646 658 … … 694 706 TComPic* pcBottomField; 695 707 xGetNewPicBuffer( pcBottomField ); 708 #if !HM_CLEANUP_SAO 696 709 pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO); 710 #endif 697 711 pcBottomField->setReconMark (false); 698 712 699 TComPicYuv* rpcPicYuvRec = new TComPicYuv;713 TComPicYuv* rpcPicYuvRec; 700 714 if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) 701 715 { … … 704 718 else 705 719 { 720 rpcPicYuvRec = new TComPicYuv; 706 721 rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 707 722 } … … 897 912 #endif 898 913 } 899 914 #if !HM_CLEANUP_SAO 900 915 if (getUseSAO()) 901 916 { 902 917 rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO); 903 918 } 919 #endif 904 920 m_cListPic.pushBack( rpcPic ); 905 921 } … … 1147 1163 } 1148 1164 1149 #if RATE_CONTROL_LAMBDA_DOMAIN1150 1165 if ( m_RCEnableRateControl ) 1151 1166 { … … 1154 1169 m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); 1155 1170 } 1156 #endif1157 1171 1158 1172 m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); -
branches/SHM-4.1-dev/source/Lib/TLibEncoder/TEncTop.h
r531 r532 83 83 // encoder search 84 84 TEncSearch m_cSearch; ///< encoder search class 85 TEncEntropy* m_pcEntropyCoder; ///< entropy encoder85 //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder 86 86 TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder 87 87 // coding tool
Note: See TracChangeset for help on using the changeset viewer.