Changeset 837 in 3DVCSoftware for branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder
- Timestamp:
- 8 Feb 2014, 00:23:11 (11 years ago)
- Location:
- branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder
- Files:
-
- 41 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/AnnexBwrite.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/NALwrite.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/NALwrite.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/SEIwrite.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 307 307 if( !hrd->getSubPicCpbParamsPresentFlag() ) 308 308 { 309 WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" ); 309 WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "irap_cpb_params_present_flag" ); 310 } 311 if( sei.m_rapCpbParamsPresentFlag ) 312 { 313 WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" ); 314 WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1() + 1, "dpb_delay_offset" ); 310 315 } 311 316 WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag"); 312 317 WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" ); 313 if( sei.m_rapCpbParamsPresentFlag )314 {315 WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );316 WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1() + 1, "dpb_delay_offset" );317 }318 318 for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) 319 319 { -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/SEIwrite.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/SyntaxElementWriter.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/SyntaxElementWriter.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncAnalyze.cpp
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncAnalyze.h
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncBinCoder.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncBinCoderCABACCounter.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCavlc.cpp
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 256 256 if( pcPPS->getScalingListPresentFlag() ) 257 257 { 258 #if SCALING_LIST_OUTPUT_RESULT259 printf("PPS\n");260 #endif261 258 codeScalingList( m_pcSlice->getScalingList() ); 262 259 } … … 742 739 if(pcSPS->getScalingListPresentFlag()) 743 740 { 744 #if SCALING_LIST_OUTPUT_RESULT745 printf("SPS\n");746 #endif747 741 codeScalingList( m_pcSlice->getScalingList() ); 748 742 } … … 1688 1682 TComReferencePictureSet* rps = pcSlice->getRPS(); 1689 1683 1690 #if FIX10711691 1684 // check for bitstream restriction stating that: 1692 1685 // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0. … … 1699 1692 } 1700 1693 } 1701 #endif1702 1694 1703 1695 if(pcSlice->getRPSidx() < 0) … … 1833 1825 { 1834 1826 WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" ); 1835 { 1836 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1837 WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" ); 1838 } 1827 WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" ); 1839 1828 } 1840 1829 } … … 2429 2418 Bool scalingListPredModeFlag; 2430 2419 2431 #if SCALING_LIST_OUTPUT_RESULT2432 Int startBit;2433 Int startTotalBit;2434 startBit = m_pcBitIf->getNumberOfWrittenBits();2435 startTotalBit = m_pcBitIf->getNumberOfWrittenBits();2436 #endif2437 2438 2420 //for each size 2439 2421 for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++) … … 2441 2423 for(listId = 0; listId < g_scalingListNum[sizeId]; listId++) 2442 2424 { 2443 #if SCALING_LIST_OUTPUT_RESULT2444 startBit = m_pcBitIf->getNumberOfWrittenBits();2445 #endif2446 2425 scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId ); 2447 2426 WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" ); … … 2454 2433 xCodeScalingList(scalingList, sizeId, listId); 2455 2434 } 2456 #if SCALING_LIST_OUTPUT_RESULT 2457 printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit); 2458 #endif 2459 } 2460 } 2461 #if SCALING_LIST_OUTPUT_RESULT 2462 printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit); 2463 #endif 2435 } 2436 } 2464 2437 return; 2465 2438 } -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCavlc.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 120 120 121 121 Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList ); 122 Void codeSAOSign ( UInt code ) { printf("Not supported\n"); assert (0); }123 Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}124 Void codeSaoMerge ( UInt uiCode ){printf("Not supported\n"); assert (0);}125 Void codeSaoTypeIdx ( UInt uiCode ){printf("Not supported\n"); assert (0);}126 Void codeSaoUflc ( UInt uiLength, UInt uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}127 128 122 Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx ); 129 123 Void codeSkipFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCfg.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 177 177 Int m_maxNumOffsetsPerPic; 178 178 Bool m_saoLcuBoundary; 179 Bool m_saoLcuBasedOptimization;180 181 //====== Lossless ========182 Bool m_useLossless;183 179 //====== Motion search ======== 184 180 Int m_iFastSearch; // 0:Full search 1:Diamond 2:PMVFAST … … 201 197 202 198 //====== Tool list ======== 203 Bool m_bUseSBACRD;204 199 Bool m_bUseASR; 205 200 Bool m_bUseHADME; … … 292 287 Int m_TMVPModeId; 293 288 Int m_signHideFlag; 294 #if RATE_CONTROL_LAMBDA_DOMAIN295 289 Bool m_RCEnableRateControl; 296 290 Int m_RCTargetBitrate; 297 #if M0036_RC_IMPROVEMENT298 291 Int m_RCKeepHierarchicalBit; 299 #else300 Bool m_RCKeepHierarchicalBit;301 #endif302 292 Bool m_RCLCULevelRC; 303 293 Bool m_RCUseLCUSeparateModel; … … 324 314 #endif 325 315 Bool m_TransquantBypassEnableFlag; ///< transquant_bypass_enable_flag setting in PPS. 326 Bool m_CUTransquantBypassFlag Value; ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.316 Bool m_CUTransquantBypassFlagForce; ///< if transquant_bypass_enable_flag, then, if true, all CU transquant bypass flags will be set to true. 327 317 #if H_MV 328 318 TComVPS* m_cVPS; ///< pointer to VPS, same for all layers … … 573 563 Void setQPAdaptationRange ( Int i ) { m_iQPAdaptationRange = i; } 574 564 575 //====== Lossless ========576 Void setUseLossless (Bool b ) { m_useLossless = b; }577 565 //====== Sequence ======== 578 566 Int getFrameRate () { return m_iFrameRate; } … … 617 605 Bool getUseAdaptiveQP () { return m_bUseAdaptiveQP; } 618 606 Int getQPAdaptationRange () { return m_iQPAdaptationRange; } 619 //====== Lossless ========620 Bool getUseLossless () { return m_useLossless; }621 607 622 608 //==== Tool list ======== 623 Void setUseSBACRD ( Bool b ) { m_bUseSBACRD = b; }624 609 Void setUseASR ( Bool b ) { m_bUseASR = b; } 625 610 Void setUseHADME ( Bool b ) { m_bUseHADME = b; } … … 640 625 Void setdQPs ( Int* p ) { m_aidQP = p; } 641 626 Void setDeltaQpRD ( UInt u ) {m_uiDeltaQpRD = u; } 642 Bool getUseSBACRD () { return m_bUseSBACRD; }643 627 Bool getUseASR () { return m_bUseASR; } 644 628 Bool getUseHADME () { return m_bUseHADME; } … … 684 668 Void setSaoLcuBoundary (Bool val) { m_saoLcuBoundary = val; } 685 669 Bool getSaoLcuBoundary () { return m_saoLcuBoundary; } 686 Void setSaoLcuBasedOptimization (Bool val) { m_saoLcuBasedOptimization = val; }687 Bool getSaoLcuBasedOptimization () { return m_saoLcuBasedOptimization; }688 670 Void setLFCrossTileBoundaryFlag ( Bool val ) { m_loopFilterAcrossTilesEnabledFlag = val; } 689 671 Bool getLFCrossTileBoundaryFlag () { return m_loopFilterAcrossTilesEnabledFlag; } … … 825 807 Void setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; } 826 808 Int getSignHideFlag() { return m_signHideFlag; } 827 #if RATE_CONTROL_LAMBDA_DOMAIN828 809 Bool getUseRateCtrl () { return m_RCEnableRateControl; } 829 810 Void setUseRateCtrl ( Bool b ) { m_RCEnableRateControl = b; } 830 811 Int getTargetBitrate () { return m_RCTargetBitrate; } 831 812 Void setTargetBitrate ( Int bitrate ) { m_RCTargetBitrate = bitrate; } 832 #if M0036_RC_IMPROVEMENT833 813 Int getKeepHierBit () { return m_RCKeepHierarchicalBit; } 834 814 Void setKeepHierBit ( Int i ) { m_RCKeepHierarchicalBit = i; } 835 #else836 Bool getKeepHierBit () { return m_RCKeepHierarchicalBit; }837 Void setKeepHierBit ( Bool b ) { m_RCKeepHierarchicalBit = b; }838 #endif839 815 Bool getLCULevelRC () { return m_RCLCULevelRC; } 840 816 Void setLCULevelRC ( Bool b ) { m_RCLCULevelRC = b; } … … 873 849 Bool getTransquantBypassEnableFlag() { return m_TransquantBypassEnableFlag; } 874 850 Void setTransquantBypassEnableFlag(Bool flag) { m_TransquantBypassEnableFlag = flag; } 875 Bool getCUTransquantBypassFlag Value() { return m_CUTransquantBypassFlagValue; }876 Void setCUTransquantBypassFlag Value(Bool flag) { m_CUTransquantBypassFlagValue = flag; }851 Bool getCUTransquantBypassFlagForceValue() { return m_CUTransquantBypassFlagForce; } 852 Void setCUTransquantBypassFlagForceValue(Bool flag) { m_CUTransquantBypassFlagForce = flag; } 877 853 #if H_MV 878 854 Void setVPS ( TComVPS *p ) { m_cVPS = p; } -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCu.cpp
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 109 109 110 110 m_bEncodeDQP = false; 111 #if RATE_CONTROL_LAMBDA_DOMAIN 112 #if !M0036_RC_IMPROVEMENT 113 m_LCUPredictionSAD = 0; 114 m_addSADDepth = 0; 115 m_temporalSAD = 0; 116 #endif 117 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 118 m_LCUPredictionSAD = 0; 119 m_addSADDepth = 0; 120 m_temporalSAD = 0; 121 m_spatialSAD = 0; 122 #endif 123 #endif 124 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 111 #if KWU_RC_MADPRED_E0227 125 112 m_LCUPredictionSAD = 0; 126 113 m_addSADDepth = 0; … … 273 260 m_pcRDGoOnSbacCoder = pcEncTop->getRDGoOnSbacCoder(); 274 261 275 m_bUseSBACRD = pcEncTop->getUseSBACRD();276 262 m_pcRateCtrl = pcEncTop->getRateCtrl(); 277 263 } … … 289 275 m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); 290 276 291 #if RATE_CONTROL_LAMBDA_DOMAIN292 #if !M0036_RC_IMPROVEMENT293 m_addSADDepth = 0;294 m_LCUPredictionSAD = 0;295 m_temporalSAD = 0;296 #endif297 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227298 m_LCUPredictionSAD = 0;299 m_addSADDepth = 0;300 m_temporalSAD = 0;301 m_spatialSAD = 0;302 #endif303 #endif304 277 #if KWU_RC_MADPRED_E0227 305 278 m_LCUPredictionSAD = 0; … … 482 455 Int iMaxQP; 483 456 Bool isAddLowestQP = false; 484 Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();485 457 486 458 if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) … … 489 461 iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); 490 462 iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); 491 if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )492 {493 isAddLowestQP = true;494 iMinQP = iMinQP - 1;495 }496 463 } 497 464 else … … 501 468 } 502 469 503 #if RATE_CONTROL_LAMBDA_DOMAIN504 470 if ( m_pcEncCfg->getUseRateCtrl() ) 505 471 { … … 507 473 iMaxQP = m_pcRateCtrl->getRCQP(); 508 474 } 509 #else 510 if(m_pcEncCfg->getUseRateCtrl()) 511 { 512 Int qp = m_pcRateCtrl->getUnitQP(); 513 iMinQP = Clip3( MIN_QP, MAX_QP, qp); 514 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 515 } 516 #endif 475 // transquant-bypass (TQB) processing loop variable initialisation --- 476 477 const Int lowestQP = iMinQP; // For TQB, use this QP which is the lowest non TQB QP tested (rather than QP'=0) - that way delta QPs are smaller, and TQB can be tested at all CU levels. 478 479 if ( (rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) ) 480 { 481 isAddLowestQP = true; // mark that the first iteration is to cost TQB mode. 482 iMinQP = iMinQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs 483 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) 484 { 485 iMaxQP = iMinQP; 486 } 487 } 488 517 489 #if H_3D_IC 518 490 Bool bICEnabled = rpcTempCU->getSlice()->getViewIndex() && ( rpcTempCU->getSlice()->getSliceType() == P_SLICE || rpcTempCU->getSlice()->getSliceType() == B_SLICE ) && !rpcTempCU->getSlice()->getIsDepth(); … … 534 506 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 535 507 { 536 if (isAddLowestQP && (iQP == iMinQP)) 508 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); 509 510 if (bIsLosslessMode) 537 511 { 538 512 iQP = lowestQP; 539 513 } 540 // variables for fast encoder decision 514 541 515 #if H_3D_QTLPC 542 516 bTrySplit = true; 543 517 #endif 544 518 545 rpcTempCU->initEstData( uiDepth, iQP );519 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 546 520 #if H_3D_QTLPC 547 521 //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU … … 647 621 #endif 648 622 #if H_3D_FAST_TEXTURE_ENCODING 649 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N650 #else 651 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP);//by Competition for inter_2Nx2N623 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N 624 #else 625 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bIsLosslessMode ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode );//by Competition for inter_2Nx2N 652 626 #endif 653 627 #if H_3D_VSP … … 663 637 bFMD = bIVFMerge && rpcBestCU->isSkipped(0); 664 638 #endif 665 rpcTempCU->initEstData( uiDepth, iQP );639 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 666 640 #if H_3D_VSP 667 641 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 675 649 #endif 676 650 #if H_3D_FAST_TEXTURE_ENCODING 677 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP );678 #else 679 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP );651 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 652 #else 653 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 680 654 #endif 681 655 #if H_3D_VSP … … 687 661 { 688 662 xCheckRDCostInterDBBP( rpcBestCU, rpcTempCU, false ); 689 rpcTempCU->initEstData( uiDepth, iQP );663 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 690 664 #if H_3D_VSP 691 665 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 710 684 } 711 685 #endif 712 if ( isAddLowestQP && (iQP == lowestQP))686 if ( bIsLosslessMode ) 713 687 { 714 688 iQP = iMinQP; … … 716 690 } 717 691 718 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT692 #if KWU_RC_MADPRED_E0227 719 693 if ( uiDepth <= m_addSADDepth ) 720 694 { … … 723 697 } 724 698 #endif 725 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227726 if ( uiDepth <= m_addSADDepth )727 {728 m_LCUPredictionSAD += m_temporalSAD;729 m_addSADDepth = uiDepth;730 }731 #endif732 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227733 if ( uiDepth <= m_addSADDepth )734 {735 m_LCUPredictionSAD += m_temporalSAD;736 m_addSADDepth = uiDepth;737 }738 #endif739 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ740 if(m_pcEncCfg->getUseRateCtrl())741 {742 Int qp = m_pcRateCtrl->getUnitQP();743 iMinQP = Clip3( MIN_QP, MAX_QP, qp);744 iMaxQP = Clip3( MIN_QP, MAX_QP, qp);745 }746 #endif747 748 699 #if H_3D_DIM_ENC 749 700 if( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) … … 757 708 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 758 709 { 759 if (isAddLowestQP && (iQP == iMinQP)) 710 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP); 711 712 if (bIsLosslessMode) 760 713 { 761 714 iQP = lowestQP; 762 715 } 763 rpcTempCU->initEstData( uiDepth, iQP );716 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 764 717 765 718 // do inter modes, NxN, 2NxN, and Nx2N … … 780 733 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); 781 734 #endif 782 rpcTempCU->initEstData( uiDepth, iQP );735 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 783 736 #if H_3D_VSP 784 737 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 799 752 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N ); 800 753 #endif 801 rpcTempCU->initEstData( uiDepth, iQP );754 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 802 755 #if H_3D_VSP 803 756 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 819 772 xCheckRDCostInter ( rpcBestCU, rpcTempCU, SIZE_2NxN ); 820 773 #endif 821 rpcTempCU->initEstData( uiDepth, iQP );774 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 822 775 #if H_3D_VSP 823 776 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 858 811 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 859 812 #endif 860 rpcTempCU->initEstData( uiDepth, iQP );813 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 861 814 #if H_3D_VSP 862 815 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 878 831 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 879 832 #endif 880 rpcTempCU->initEstData( uiDepth, iQP );833 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 881 834 #if H_3D_VSP 882 835 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 902 855 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); 903 856 #endif 904 rpcTempCU->initEstData( uiDepth, iQP );857 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 905 858 #if H_3D_VSP 906 859 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 922 875 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); 923 876 #endif 924 rpcTempCU->initEstData( uiDepth, iQP );877 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 925 878 #if H_3D_VSP 926 879 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 948 901 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 949 902 #endif 950 rpcTempCU->initEstData( uiDepth, iQP );903 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 951 904 #if H_3D_VSP 952 905 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 968 921 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 969 922 #endif 970 rpcTempCU->initEstData( uiDepth, iQP );923 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 971 924 #if H_3D_VSP 972 925 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 988 941 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); 989 942 #endif 990 rpcTempCU->initEstData( uiDepth, iQP );943 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 991 944 #if H_3D_VSP 992 945 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1008 961 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); 1009 962 #endif 1010 rpcTempCU->initEstData( uiDepth, iQP );963 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1011 964 #if H_3D_VSP 1012 965 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1022 975 #endif 1023 976 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 1024 rpcTempCU->initEstData( uiDepth, iQP );977 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1025 978 #if H_3D_VSP 1026 979 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); 1027 980 #endif 1028 981 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 1029 rpcTempCU->initEstData( uiDepth, iQP );982 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1030 983 #if H_3D_VSP 1031 984 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1037 990 #endif 1038 991 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 1039 rpcTempCU->initEstData( uiDepth, iQP );992 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1040 993 #if H_3D_VSP 1041 994 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); 1042 995 #endif 1043 996 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 1044 rpcTempCU->initEstData( uiDepth, iQP );997 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1045 998 #if H_3D_VSP 1046 999 rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth); … … 1072 1025 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 1073 1026 1074 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT &&KWU_RC_MADPRED_E02271027 #if KWU_RC_MADPRED_E0227 1075 1028 if ( uiDepth <= m_addSADDepth ) 1076 1029 { … … 1079 1032 } 1080 1033 #endif 1081 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 1082 if ( uiDepth <= m_addSADDepth ) 1083 { 1084 m_LCUPredictionSAD += m_spatialSAD; 1085 m_addSADDepth = uiDepth; 1086 } 1087 #endif 1088 1089 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227 1090 if ( uiDepth <= m_addSADDepth ) 1091 { 1092 m_LCUPredictionSAD += m_spatialSAD; 1093 m_addSADDepth = uiDepth; 1094 } 1095 #endif 1096 rpcTempCU->initEstData( uiDepth, iQP ); 1034 1035 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1097 1036 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 1098 1037 { … … 1104 1043 { 1105 1044 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); 1106 rpcTempCU->initEstData( uiDepth, iQP );1045 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1107 1046 } 1108 1047 #if H_3D_QTLPC … … 1126 1065 { 1127 1066 xCheckIntraPCM (rpcBestCU, rpcTempCU); 1128 rpcTempCU->initEstData( uiDepth, iQP );1067 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1129 1068 } 1130 1069 } … … 1132 1071 } 1133 1072 #endif 1134 if ( isAddLowestQP && (iQP == lowestQP))1073 if (bIsLosslessMode) 1135 1074 { 1136 1075 iQP = iMinQP; … … 1142 1081 m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth, true ); 1143 1082 rpcBestCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits 1144 if(m_pcEncCfg->getUseSBACRD())1145 {1146 1083 rpcBestCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1147 }1148 1149 #if H_3D_VSO // M81150 if ( m_pcRdCost->getUseVSO() )1151 rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCostVSO( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );1152 else1153 #endif1154 1084 rpcBestCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() ); 1155 1085 … … 1173 1103 { 1174 1104 bBoundary = true; 1175 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT1176 m_addSADDepth++;1177 #endif1178 1105 } 1179 1106 … … 1188 1115 iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP ); 1189 1116 iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP ); 1190 if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )1191 {1192 isAddLowestQP = true;1193 iMinQP = iMinQP - 1;1194 }1195 1117 } 1196 1118 else if( (g_uiMaxCUWidth>>uiDepth) > rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() ) … … 1214 1136 iMaxQP = iStartQP; 1215 1137 } 1216 #if RATE_CONTROL_LAMBDA_DOMAIN1217 1138 if ( m_pcEncCfg->getUseRateCtrl() ) 1218 1139 { … … 1220 1141 iMaxQP = m_pcRateCtrl->getRCQP(); 1221 1142 } 1222 #else 1223 if(m_pcEncCfg->getUseRateCtrl()) 1224 { 1225 Int qp = m_pcRateCtrl->getUnitQP(); 1226 iMinQP = Clip3( MIN_QP, MAX_QP, qp); 1227 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 1228 } 1229 #endif 1143 1144 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() ) 1145 { 1146 iMaxQP = iMinQP; // If all blocks are forced into using transquant bypass, do not loop here. 1147 } 1230 1148 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 1231 1149 { 1232 if (isAddLowestQP && (iQP == iMinQP)) 1233 { 1234 iQP = lowestQP; 1235 } 1236 rpcTempCU->initEstData( uiDepth, iQP ); 1150 const Bool bIsLosslessMode = false; // False at this level. Next level down may set it to true. 1151 rpcTempCU->initEstData( uiDepth, iQP, bIsLosslessMode ); 1237 1152 1238 1153 // further split … … 1267 1182 if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1268 1183 { 1269 if( m_bUseSBACRD )1270 {1271 1184 if ( 0 == uiPartUnitIdx) //initialize RD with previous depth buffer 1272 1185 { … … 1277 1190 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 1278 1191 } 1279 }1280 1192 1281 1193 #if AMP_ENC_SPEEDUP … … 1308 1220 1309 1221 rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // split bits 1310 if(m_pcEncCfg->getUseSBACRD())1311 {1312 1222 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1313 1223 } 1314 }1315 1316 1224 #if H_3D_VSO // M10 1317 1225 if ( m_pcRdCost->getUseVSO() ) … … 1349 1257 m_pcEntropyCoder->encodeQP( rpcTempCU, uiTargetPartIdx, false ); 1350 1258 rpcTempCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 1351 if(m_pcEncCfg->getUseSBACRD())1352 {1353 1259 rpcTempCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1354 }1355 1260 #if H_3D_VSO // M11 1356 1261 if ( m_pcRdCost->getUseLambdaScaleVSO()) … … 1371 1276 } 1372 1277 1373 if( m_bUseSBACRD )1374 {1375 1278 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 1376 }1377 1279 Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES 1378 1280 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); … … 1385 1287 xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction 1386 1288 } // with sub partitioned prediction. 1387 if (isAddLowestQP && (iQP == lowestQP)) 1388 { 1389 iQP = iMinQP; 1390 } 1391 } 1392 1289 } 1393 1290 1394 1291 #if H_3D_VSO // M12 … … 1402 1299 } 1403 1300 #endif 1404 1405 1301 rpcBestCU->copyToPic(uiDepth); // Copy Best data to Picture for next partition prediction. 1406 1302 … … 1683 1579 } 1684 1580 1685 #if RATE_CONTROL_INTRA1686 1581 Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg) 1687 1582 { … … 1798 1693 return(iSumHad); 1799 1694 } 1800 #endif1801 1695 1802 1696 /** check RD costs for a CU block encoded with merge … … 1816 1710 #endif 1817 1711 Int numValidMergeCand = 0; 1712 const Bool bTransquantBypassFlag = rpcTempCU->getCUTransquantBypass(0); 1818 1713 1819 1714 for( UInt ui = 0; ui < rpcTempCU->getSlice()->getMaxNumMergeCand(); ++ui ) … … 1840 1735 #else 1841 1736 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1842 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );1843 1737 #endif 1844 1738 … … 1968 1862 // set MC parameters 1969 1863 rpcTempCU->setPredModeSubParts( MODE_INTER, 0, uhDepth ); // interprets depth relative to LCU level 1970 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );1864 rpcTempCU->setCUTransquantBypassSubParts( bTransquantBypassFlag, 0, uhDepth ); 1971 1865 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1972 1866 #if H_3D_IC … … 2160 2054 } 2161 2055 #endif 2162 rpcTempCU->initEstData( uhDepth, orgQP );2056 rpcTempCU->initEstData( uhDepth, orgQP, bTransquantBypassFlag ); 2163 2057 2164 2058 if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip ) … … 2274 2168 rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); 2275 2169 rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); 2276 rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );2277 2278 2170 #if MTK_DDD_G0063 2279 2171 rpcTempCU->setUseDDD( false, 0, uhDepth ); … … 2328 2220 #endif 2329 2221 2330 #if RATE_CONTROL_LAMBDA_DOMAIN && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)2222 #if KWU_RC_MADPRED_E0227 2331 2223 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) 2332 2224 { … … 2337 2229 } 2338 2230 #endif 2339 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E02272340 if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2341 {2342 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2343 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2344 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2345 m_temporalSAD = (Int)SAD;2346 }2347 #endif2348 2349 2231 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 2350 2351 2232 #if NTT_STORE_SPDV_VSP_G0148 // possible bug fix 2352 2233 if( rpcTempCU->getQtRootCbf(0)==0 ) … … 2657 2538 rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); 2658 2539 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 2659 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );2660 2540 2661 2541 Bool bSeparateLumaChroma = true; // choose estimation mode … … 2693 2573 setdQPFlag( bCodeDQP ); 2694 2574 2695 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);2575 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 2696 2576 2697 2577 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 2698 if(m_pcEncCfg->getUseSBACRD())2699 {2700 2578 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2701 }2702 2703 2579 #if H_3D_VSO // M6 2704 2580 if( m_pcRdCost->getUseLambdaScaleVSO()) … … 2708 2584 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 2709 2585 2710 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E02272711 UChar uhDepth = rpcTempCU->getDepth( 0 );2712 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2713 {2714 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2715 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2716 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2717 m_spatialSAD = (Int)SAD;2718 }2719 #endif2720 #if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E02272721 UChar uhDepth = rpcTempCU->getDepth( 0 );2722 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2723 {2724 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2725 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2726 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2727 m_spatialSAD = (Int)SAD;2728 }2729 #endif2730 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E02272731 UChar uhDepth = rpcTempCU->getDepth( 0 );2732 if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )2733 {2734 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),2735 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),2736 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );2737 m_spatialSAD = (Int)SAD;2738 }2739 #endif2740 2586 xCheckDQP( rpcTempCU ); 2741 2587 xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); … … 2760 2606 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 2761 2607 rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); 2762 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth );2763 2608 2764 2609 m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); 2765 2610 2766 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]);2611 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 2767 2612 2768 2613 m_pcEntropyCoder->resetBits(); … … 2779 2624 m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); 2780 2625 2781 if( m_bUseSBACRD )m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]);2626 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 2782 2627 2783 2628 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 2784 if(m_pcEncCfg->getUseSBACRD())2785 {2786 2629 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2787 }2788 2630 #if H_3D_VSO // M44 2789 2631 if ( m_pcRdCost->getUseVSO() ) … … 2825 2667 pcCU = NULL; 2826 2668 2827 if( m_bUseSBACRD )// store temp best CI for next CU coding2669 // store temp best CI for next CU coding 2828 2670 m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); 2829 2671 } … … 2842 2684 m_pcEntropyCoder->encodeQP( pcCU, 0, false ); 2843 2685 pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 2844 if(m_pcEncCfg->getUseSBACRD())2845 {2846 2686 pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 2847 }2848 2687 #if H_3D_VSO // M45 2849 2688 if ( m_pcRdCost->getUseVSO() ) -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncCu.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 104 104 TEncSbac*** m_pppcRDSbacCoder; 105 105 TEncSbac* m_pcRDGoOnSbacCoder; 106 Bool m_bUseSBACRD;107 106 TEncRateCtrl* m_pcRateCtrl; 108 #if RATE_CONTROL_LAMBDA_DOMAIN 109 #if !M0036_RC_IMPROVEMENT 110 UInt m_LCUPredictionSAD; 111 Int m_addSADDepth; 112 Int m_temporalSAD; 113 #endif 114 #if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227 107 #if KWU_RC_MADPRED_E0227 115 108 UInt m_LCUPredictionSAD; 116 109 Int m_addSADDepth; … … 118 111 Int m_spatialSAD; 119 112 #endif 120 #endif121 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227122 UInt m_LCUPredictionSAD;123 Int m_addSADDepth;124 Int m_temporalSAD;125 Int m_spatialSAD;126 #endif127 128 113 public: 129 114 /// copy parameters from encoder class … … 143 128 144 129 Void setBitCounter ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; } 145 #if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) ||KWU_RC_MADPRED_E0227130 #if KWU_RC_MADPRED_E0227 146 131 UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; } 147 132 #endif 148 #if RATE_CONTROL_INTRA149 133 Int updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height ); 150 #endif151 134 protected: 152 135 Void finishCU ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncEntropy.cpp
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 51 51 Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice ) 52 52 { 53 if (pcSlice->getSPS()->getUseSAO())54 {55 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();56 pcSlice->setSaoEnabledFlag (saoParam->bSaoFlag[0]);57 {58 pcSlice->setSaoEnabledFlagChroma (saoParam->bSaoFlag[1]);59 }60 }61 62 53 m_pcEntropyCoderIf->codeSliceHeader( pcSlice ); 63 54 return; … … 787 778 } 788 779 789 /** Encode SAO Offset790 * \param saoLcuParam SAO LCU paramters791 */792 Void TEncEntropy::encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx)793 {794 UInt uiSymbol;795 Int i;796 797 uiSymbol = saoLcuParam->typeIdx + 1;798 if (compIdx!=2)799 {800 m_pcEntropyCoderIf->codeSaoTypeIdx(uiSymbol);801 }802 if (uiSymbol)803 {804 if (saoLcuParam->typeIdx < 4 && compIdx != 2)805 {806 saoLcuParam->subTypeIdx = saoLcuParam->typeIdx;807 }808 Int bitDepth = compIdx ? g_bitDepthC : g_bitDepthY;809 Int offsetTh = 1 << min(bitDepth - 5,5);810 if( saoLcuParam->typeIdx == SAO_BO )811 {812 for( i=0; i< saoLcuParam->length; i++)813 {814 UInt absOffset = ( (saoLcuParam->offset[i] < 0) ? -saoLcuParam->offset[i] : saoLcuParam->offset[i]);815 m_pcEntropyCoderIf->codeSaoMaxUvlc(absOffset, offsetTh-1);816 }817 for( i=0; i< saoLcuParam->length; i++)818 {819 if (saoLcuParam->offset[i] != 0)820 {821 UInt sign = (saoLcuParam->offset[i] < 0) ? 1 : 0 ;822 m_pcEntropyCoderIf->codeSAOSign(sign);823 }824 }825 uiSymbol = (UInt) (saoLcuParam->subTypeIdx);826 m_pcEntropyCoderIf->codeSaoUflc(5, uiSymbol);827 }828 else if( saoLcuParam->typeIdx < 4 )829 {830 m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[0], offsetTh-1);831 m_pcEntropyCoderIf->codeSaoMaxUvlc( saoLcuParam->offset[1], offsetTh-1);832 m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[2], offsetTh-1);833 m_pcEntropyCoderIf->codeSaoMaxUvlc(-saoLcuParam->offset[3], offsetTh-1);834 if (compIdx!=2)835 {836 uiSymbol = (UInt) (saoLcuParam->subTypeIdx);837 m_pcEntropyCoderIf->codeSaoUflc(2, uiSymbol);838 }839 }840 }841 }842 843 /** Encode SAO unit interleaving844 * \param rx845 * \param ry846 * \param pSaoParam847 * \param pcCU848 * \param iCUAddrInSlice849 * \param iCUAddrUpInSlice850 * \param bLFCrossSliceBoundaryFlag851 */852 Void TEncEntropy::encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp)853 {854 if (saoFlag)855 {856 if (rx>0 && cuAddrInSlice!=0 && allowMergeLeft)857 {858 m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeLeftFlag);859 }860 else861 {862 saoLcuParam->mergeLeftFlag = 0;863 }864 if (saoLcuParam->mergeLeftFlag == 0)865 {866 if ( (ry > 0) && (cuAddrUpInSlice>=0) && allowMergeUp )867 {868 m_pcEntropyCoderIf->codeSaoMerge(saoLcuParam->mergeUpFlag);869 }870 else871 {872 saoLcuParam->mergeUpFlag = 0;873 }874 if (!saoLcuParam->mergeUpFlag)875 {876 encodeSaoOffset(saoLcuParam, compIdx);877 }878 }879 }880 }881 882 780 Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ) 883 781 { … … 900 798 } 901 799 902 #if H_3D_INTER_SDC903 #if QC_SDC_UNIFY_G0130904 Void TEncEntropy::encodeDeltaDC ( TComDataCU* pcCU, UInt absPartIdx )905 {906 m_pcEntropyCoderIf->codeDeltaDC( pcCU, absPartIdx );907 }908 909 Void TEncEntropy::encodeSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )910 {911 if( ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) ) ||912 ( pcCU->isIntra( uiAbsPartIdx ) && !pcCU->getSlice()->getVPS()->getVpsDepthModesFlag( pcCU->getSlice()->getLayerIdInVps() ) ) )913 {914 return;915 }916 917 #if SEC_INTER_SDC_G0101918 if( !pcCU->getSlice()->getIsDepth() || pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N || pcCU->isSkipped( uiAbsPartIdx ) )919 #else920 if( !pcCU->getSlice()->getIsDepth() || ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) != SIZE_2Nx2N ) || pcCU->isSkipped( uiAbsPartIdx ) )921 #endif922 {923 return;924 }925 926 #if SEC_INTER_SDC_G0101927 assert( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );928 #else929 assert( ( pcCU->isIntra( uiAbsPartIdx ) && pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) || ( !pcCU->isIntra( uiAbsPartIdx ) && !pcCU->isSkipped( uiAbsPartIdx ) ) );930 #endif931 932 if( bRD )933 {934 uiAbsPartIdx = 0;935 }936 937 m_pcEntropyCoderIf->codeSDCFlag( pcCU, uiAbsPartIdx );938 }939 #else940 Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )941 {942 if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )943 {944 return;945 }946 947 if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || pcCU->isSkipped( uiAbsPartIdx ) )948 {949 return;950 }951 952 if( bRD )953 {954 uiAbsPartIdx = 0;955 }956 957 m_pcEntropyCoderIf->codeInterSDCFlag( pcCU, uiAbsPartIdx );958 }959 960 Void TEncEntropy::encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )961 {962 if( !pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )963 {964 return;965 }966 967 if( !pcCU->getSlice()->getIsDepth() || pcCU->isIntra( uiAbsPartIdx ) || !pcCU->getInterSDCFlag( uiAbsPartIdx ) )968 {969 return;970 }971 972 if( bRD )973 {974 uiAbsPartIdx = 0;975 }976 977 // number of segments depends on prediction mode for INTRA978 UInt uiNumSegments = ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_2Nx2N ) ? 1 : ( pcCU->getPartitionSize( uiAbsPartIdx ) == SIZE_NxN ? 4 : 2 );979 980 // encode residual data for each segment981 for( UInt uiSeg = 0; uiSeg < uiNumSegments; uiSeg++ )982 {983 m_pcEntropyCoderIf->codeInterSDCResidualData( pcCU, uiAbsPartIdx, uiSeg );984 }985 }986 #endif987 #endif988 #if H_3D_DBBP989 Void TEncEntropy::encodeDBBPFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )990 {991 if( bRD )992 {993 uiAbsPartIdx = 0;994 }995 m_pcEntropyCoderIf->codeDBBPFlag( pcCU, uiAbsPartIdx );996 }997 #endif998 999 800 //! \} -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncEntropy.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 127 127 virtual Void codeCoeffNxN ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0; 128 128 virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0; 129 virtual Void codeSAOSign ( UInt code ) = 0;130 virtual Void codeSaoMaxUvlc ( UInt code, UInt maxSymbol ) = 0;131 virtual Void codeSaoMerge ( UInt uiCode ) = 0;132 virtual Void codeSaoTypeIdx ( UInt uiCode) = 0;133 virtual Void codeSaoUflc ( UInt uiLength, UInt uiCode ) = 0;134 129 virtual Void estBit (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0; 135 130 … … 232 227 233 228 Void estimateBit ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType); 234 Void encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);235 Void encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);236 229 static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize ); 237 230 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncGOP.cpp
r773 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 105 105 #endif 106 106 #endif 107 #if FIX1172 108 m_associatedIRAPType = NAL_UNIT_CODED_SLICE_IDR_N_LP; 109 m_associatedIRAPPOC = 0; 110 #endif 107 111 return; 108 112 } … … 472 476 } 473 477 474 if( getNalUnitType(pocCurr, m_iLastIDR ) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP )478 if( getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR, isField) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) 475 479 { 476 480 m_iLastIDR = pocCurr; … … 551 555 #if H_MV 552 556 // Set the nal unit type 553 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR ));557 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); 554 558 if( pcSlice->getSliceType() == B_SLICE ) 555 559 { … … 559 563 } 560 564 } 565 566 // To be checked! 567 if( pcSlice->getSliceType() == B_SLICE ) 568 { 569 if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'I' ) 570 { 571 pcSlice->setSliceType( I_SLICE ); 572 } 573 } 561 574 #else 562 575 if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') … … 564 577 pcSlice->setSliceType(P_SLICE); 565 578 } 579 if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='I') 580 { 581 pcSlice->setSliceType(I_SLICE); 582 } 583 566 584 // Set the nal unit type 567 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR ));585 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR, isField)); 568 586 #endif 569 587 if(pcSlice->getTemporalLayerNonReferenceFlag()) … … 589 607 m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); 590 608 pcSlice->getRPS()->setNumberOfLongtermPictures(0); 591 592 #if FIX1071 609 #if FIX1172 610 if ( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP 611 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL 612 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP 613 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL 614 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP 615 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // IRAP picture 616 { 617 m_associatedIRAPType = pcSlice->getNalUnitType(); 618 m_associatedIRAPPOC = pocCurr; 619 } 620 pcSlice->setAssociatedIRAPType(m_associatedIRAPType); 621 pcSlice->setAssociatedIRAPPOC(m_associatedIRAPPOC); 622 #endif 623 593 624 if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP())) 594 625 { 595 626 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP()); 596 627 } 597 #else598 if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)599 {600 pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());601 }602 #endif603 628 pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); 604 629 605 if(pcSlice->getTLayer() > 0) 630 if(pcSlice->getTLayer() > 0 631 && !( pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N // Check if not a leading picture 632 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R 633 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N 634 || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R ) 635 ) 606 636 { 607 637 if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) … … 613 643 else 614 644 { 615 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_T LA_R);645 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R); 616 646 } 617 647 } … … 907 937 pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); 908 938 909 #if RATE_CONTROL_LAMBDA_DOMAIN910 939 Double lambda = 0.0; 911 940 Int actualHeadBits = 0; … … 944 973 else if ( frameLevel == 0 ) // intra case, but use the model 945 974 { 946 #if RATE_CONTROL_INTRA947 975 m_pcSliceEncoder->calCostSliceI(pcPic); 948 #endif949 976 if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case 950 977 { 951 978 Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); 952 #if RATE_CONTROL_INTRA953 979 bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits ); 954 #else955 bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );956 #endif957 980 if ( bits < 200 ) 958 981 { … … 963 986 964 987 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 965 #if RATE_CONTROL_INTRA966 988 m_pcRateCtrl->getRCPic()->getLCUInitTargetBits(); 967 989 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 968 #else969 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );970 #endif971 990 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 972 991 } … … 984 1003 #endif 985 1004 list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); 986 #if RATE_CONTROL_INTRA987 1005 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType()); 988 #else989 lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );990 #endif991 1006 sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); 992 1007 #if KWU_RC_MADPRED_E0227 … … 1000 1015 m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); 1001 1016 } 1002 #endif1003 1017 1004 1018 UInt uiNumSlices = 1; … … 1203 1217 1204 1218 // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas 1205 if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) 1206 { 1207 m_pcSAO->resetStats(); 1208 m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); 1219 if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() ) 1220 { 1221 m_pcSAO->getPreDBFStatistics(pcPic); 1209 1222 } 1210 1223 … … 1218 1231 m_pcLoopFilter->loopFilterPic( pcPic ); 1219 1232 1220 pcSlice = pcPic->getSlice(0);1221 if(pcSlice->getSPS()->getUseSAO())1222 {1223 std::vector<Bool> LFCrossSliceBoundaryFlag;1224 for(Int s=0; s< uiNumSlices; s++)1225 {1226 LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) );1227 }1228 m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1);1229 pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary);1230 }1231 1232 1233 pcSlice = pcPic->getSlice(0);1234 1235 if(pcSlice->getSPS()->getUseSAO())1236 {1237 m_pcSAO->createPicSaoInfo(pcPic);1238 }1239 1240 1233 /////////////////////////////////////////////////////////////////////////////////////////////////// File writing 1241 1234 // Set entropy coder … … 1254 1247 writeRBSPTrailingBits(nalu.m_Bitstream); 1255 1248 accessUnit.push_back(new NALUnitEBSP(nalu)); 1256 #if RATE_CONTROL_LAMBDA_DOMAIN1257 1249 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1258 #endif1259 1250 1260 1251 #if H_MV … … 1296 1287 writeRBSPTrailingBits(nalu.m_Bitstream); 1297 1288 accessUnit.push_back(new NALUnitEBSP(nalu)); 1298 #if RATE_CONTROL_LAMBDA_DOMAIN1299 1289 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1300 #endif1301 1290 1302 1291 #if H_MV … … 1313 1302 writeRBSPTrailingBits(nalu.m_Bitstream); 1314 1303 accessUnit.push_back(new NALUnitEBSP(nalu)); 1315 #if RATE_CONTROL_LAMBDA_DOMAIN1316 1304 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1317 #endif 1305 1318 1306 #if PPS_FIX_DEPTH 1319 1307 } … … 1343 1331 { 1344 1332 SOPcurrPOC += deltaPOC; 1345 SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR );1333 SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR, isField); 1346 1334 SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; 1347 1335 SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); … … 1621 1609 } 1622 1610 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 1623 #if RATE_CONTROL_LAMBDA_DOMAIN1624 1611 tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); 1625 #endif1626 1612 m_pcEntropyCoder->encodeSliceHeader(pcSlice); 1627 #if RATE_CONTROL_LAMBDA_DOMAIN1628 1613 actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); 1629 #endif1630 1614 1631 1615 // is it needed? … … 1748 1732 xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); 1749 1733 accessUnit.push_back(new NALUnitEBSP(nalu)); 1750 #if RATE_CONTROL_LAMBDA_DOMAIN1751 1734 actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; 1752 #endif1753 1735 bNALUAlignedWrittenToList = true; 1754 1736 uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment … … 1794 1776 m_pcEntropyCoder->resetEntropy(); 1795 1777 m_pcEntropyCoder->setBitstream( m_pcBitCounter ); 1796 m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); 1797 SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); 1798 1799 #if SAO_CHROMA_LAMBDA 1800 #if SAO_ENCODING_CHOICE 1801 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); 1802 #else 1803 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); 1804 #endif 1805 #else 1806 m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); 1807 #endif 1808 m_pcSAO->endSaoEnc(); 1778 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1779 m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice); 1780 m_pcSAO->SAOProcess(pcPic 1781 , sliceEnabled 1782 , pcPic->getSlice(0)->getLambdas() 1783 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1784 , m_pcCfg->getSaoLcuBoundary() 1785 #endif 1786 ); 1809 1787 m_pcSAO->PCMLFDisableProcess(pcPic); 1810 } 1811 #if SAO_RDO 1812 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); 1813 #endif 1814 processingState = ENCODE_SLICE; 1815 1788 1789 //assign SAO slice header 1816 1790 for(Int s=0; s< uiNumSlices; s++) 1817 1791 { 1818 if (pcSlice->getSPS()->getUseSAO())1819 {1820 pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false);1792 pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]); 1793 assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]); 1794 pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]); 1821 1795 } 1822 1796 } 1797 processingState = ENCODE_SLICE; 1823 1798 } 1824 1799 break; … … 1831 1806 } 1832 1807 } // end iteration over slices 1833 1834 if(pcSlice->getSPS()->getUseSAO())1835 {1836 if(pcSlice->getSPS()->getUseSAO())1837 {1838 m_pcSAO->destroyPicSaoInfo();1839 }1840 pcPic->destroyNonDBFilterInfo();1841 }1842 1808 #if H_3D 1843 1809 pcPic->compressMotion(2); … … 1919 1885 1920 1886 //In case of field coding, compute the interlaced PSNR for both fields 1921 if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) )1887 if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)) && (pcPic->getPOC()%m_iGopSize != 1)) 1922 1888 { 1923 1889 //get complementary top field … … 1931 1897 xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime ); 1932 1898 } 1899 else if (isField && pcPic->getPOC()!= 0 && (pcPic->getPOC()%m_iGopSize == 0)) 1900 { 1901 //get complementary bottom field 1902 TComPic* pcPicBottom; 1903 TComList<TComPic*>::iterator iterPic = rcListPic.begin(); 1904 while ((*iterPic)->getPOC() != pcPic->getPOC()+1) 1905 { 1906 iterPic ++; 1907 } 1908 pcPicBottom = *(iterPic); 1909 xCalculateInterlacedAddPSNR(pcPic, pcPicBottom, pcPic->getPicYuvRec(), pcPicBottom->getPicYuvRec(), accessUnit, dEncTime ); 1910 } 1933 1911 1934 1912 if (digestStr) … … 1947 1925 } 1948 1926 } 1949 #if RATE_CONTROL_LAMBDA_DOMAIN1950 1927 if ( m_pcCfg->getUseRateCtrl() ) 1951 1928 { 1952 #if !M0036_RC_IMPROVEMENT1953 Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();1954 #endif1955 1929 Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); 1956 1930 Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); … … 1959 1933 avgLambda = lambda; 1960 1934 } 1961 #if M0036_RC_IMPROVEMENT1962 #if RATE_CONTROL_INTRA1963 1935 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType()); 1964 #else1965 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );1966 #endif1967 #else1968 m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );1969 #endif1970 1936 m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); 1971 1937 … … 1980 1946 } 1981 1947 } 1982 #else1983 if(m_pcCfg->getUseRateCtrl())1984 {1985 UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];1986 m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());1987 }1988 #endif1989 1948 1990 1949 if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && … … 2173 2132 delete[] pcSubstreamsOut; 2174 2133 } 2175 #if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN2176 if(m_pcCfg->getUseRateCtrl())2177 {2178 m_pcRateCtrl->updateRCGOPStatus();2179 }2180 #endif2181 2134 delete pcBitstreamRedirect; 2182 2135 … … 2262 2215 m_pcEntropyCoder->resetEntropy (); 2263 2216 m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); 2264 pcSlice = pcPic->getSlice(0);2265 if(pcSlice->getSPS()->getUseSAO())2266 {2267 std::vector<Bool> LFCrossSliceBoundaryFlag(1, true);2268 std::vector<Int> sliceStartAddress;2269 sliceStartAddress.push_back(0);2270 sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU());2271 pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag);2272 }2273 2274 if( pcSlice->getSPS()->getUseSAO())2275 {2276 pcPic->destroyNonDBFilterInfo();2277 }2278 2279 2217 m_pcEntropyCoder->resetEntropy (); 2280 2218 ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); … … 2454 2392 case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; 2455 2393 case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; 2456 case NAL_UNIT_CODED_SLICE_T LA_R: return "TLA_R";2394 case NAL_UNIT_CODED_SLICE_TSA_R: return "TSA_R"; 2457 2395 case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; 2458 2396 case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; … … 2702 2640 for (Int x = 0; x < width; x++) 2703 2641 { 2704 dst[x] = isTff ? (UChar) top[x] : (UChar)bottom[x];2705 dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar)top[x];2642 dst[x] = isTff ? top[x] : bottom[x]; 2643 dst[stride+x] = isTff ? bottom[x] : top[x]; 2706 2644 } 2707 2645 top += stride; … … 2862 2800 * This function checks the configuration and returns the appropriate nal_unit_type for the picture. 2863 2801 */ 2864 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR )2802 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR, Bool isField) 2865 2803 { 2866 2804 if (pocCurr == 0) … … 2868 2806 return NAL_UNIT_CODED_SLICE_IDR_W_RADL; 2869 2807 } 2870 if ( pocCurr% m_pcCfg->getIntraPeriod() == 0)2808 if ((pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0) 2871 2809 { 2872 2810 if (m_pcCfg->getDecodingRefreshType() == 1) -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncGOP.h
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 125 125 std::vector<Int> m_storedStartCUAddrForEncodingSlice; 126 126 std::vector<Int> m_storedStartCUAddrForEncodingSliceSegment; 127 #if FIX1172 128 NalUnitType m_associatedIRAPType; 129 Int m_associatedIRAPPOC; 130 #endif 127 131 128 132 std::vector<Int> m_vRVM_RP; … … 181 185 182 186 TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } 183 NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );187 NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); 184 188 Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); 185 189 protected: … … 187 191 188 192 protected: 193 189 194 Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField ); 190 191 195 Void xInitGOP ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ); 192 196 Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncPic.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncPic.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncPreanalyzer.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncPreanalyzer.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncRateCtrl.cpp
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 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 540 482 #if KWU_RC_MADPRED_E0227 541 483 m_lastIVPicture = NULL; … … 543 485 544 486 m_picActualHeaderBits = 0; 545 #if !M0036_RC_IMPROVEMENT546 m_totalMAD = 0.0;547 #endif548 487 m_picActualBits = 0; 549 488 m_picQP = 0; … … 574 513 } 575 514 576 #if M0036_RC_IMPROVEMENT577 515 targetBits = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio ); 578 #else579 targetBits = Int( GOPbitsLeft * currPicRatio / totalPicRatio );580 #endif581 516 582 517 if ( targetBits < 100 ) … … 691 626 m_LCUs[LCUIdx].m_lambda = 0.0; 692 627 m_LCUs[LCUIdx].m_targetBits = 0; 693 #if M0036_RC_IMPROVEMENT694 628 m_LCUs[LCUIdx].m_bitWeight = 1.0; 695 #else696 m_LCUs[LCUIdx].m_MAD = 0.0;697 #endif698 629 Int currWidth = ( (i == picWidthInLCU -1) ? picWidth - LCUWidth *(picWidthInLCU -1) : LCUWidth ); 699 630 Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight ); … … 708 639 } 709 640 m_picActualHeaderBits = 0; 710 #if !M0036_RC_IMPROVEMENT711 m_totalMAD = 0.0;712 #endif713 641 m_picActualBits = 0; 714 642 m_picQP = 0; … … 723 651 724 652 725 #if !M0036_RC_IMPROVEMENT726 m_lastPicture = NULL;727 list<TEncRCPic*>::reverse_iterator it;728 for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )729 {730 if ( (*it)->getFrameLevel() == m_frameLevel )731 {732 m_lastPicture = (*it);733 break;734 }735 }736 #endif737 738 653 #if KWU_RC_MADPRED_E0227 739 654 list<TEncRCPic*>::reverse_iterator it; … … 775 690 776 691 777 #if RATE_CONTROL_INTRA778 692 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType) 779 #else780 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )781 #endif782 693 { 783 694 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 784 695 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 785 696 Double bpp = (Double)m_targetBits/(Double)m_numberOfPixel; 786 #if RATE_CONTROL_INTRA787 697 Double estLambda; 788 698 if (eSliceType == I_SLICE) … … 794 704 estLambda = alpha * pow( bpp, beta ); 795 705 } 796 #else797 Double estLambda = alpha * pow( bpp, beta );798 #endif799 706 800 707 Double lastLevelLambda = -1.0; … … 844 751 m_estPicLambda = estLambda; 845 752 846 #if M0036_RC_IMPROVEMENT847 753 Double totalWeight = 0.0; 848 754 // initial BU bit allocation weight 849 755 for ( Int i=0; i<m_numberOfLCU; i++ ) 850 756 { 851 #if RC_FIX852 757 Double alphaLCU, betaLCU; 853 758 if ( m_encRCSeq->getUseLCUSeparateModel() ) … … 861 766 betaLCU = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 862 767 } 863 #else864 Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;865 Double betaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;866 #endif867 768 868 769 m_LCUs[i].m_bitWeight = m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU ); … … 879 780 m_LCUs[i].m_bitWeight = BUTargetBits; 880 781 } 881 #endif882 782 883 783 return estLambda; … … 989 889 990 890 991 #if RATE_CONTROL_INTRA992 891 Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 993 #else 994 Double TEncRCPic::getLCUTargetBpp() 995 #endif 892 { 893 Int LCUIdx = getLCUCoded(); 894 Double bpp = -1.0; 895 Int avgBits = 0; 896 897 if (eSliceType == I_SLICE) 898 { 899 Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1; 900 Int bitrateWindow = min(4,noOfLCUsLeft); 901 Double MAD = getLCU(LCUIdx).m_costIntra; 902 903 if (m_remainingCostIntra > 0.1 ) 904 { 905 Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow; 906 avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra ); 907 } 908 else 909 { 910 avgBits = Int( m_bitsLeft / m_LCULeft ); 911 } 912 m_remainingCostIntra -= MAD; 913 } 914 else 915 { 916 Double totalWeight = 0; 917 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ ) 918 { 919 totalWeight += m_LCUs[i].m_bitWeight; 920 } 921 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() ); 922 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 ); 923 } 924 925 if ( avgBits < 1 ) 926 { 927 avgBits = 1; 928 } 929 930 bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel; 931 m_LCUs[ LCUIdx ].m_targetBits = avgBits; 932 933 return bpp; 934 } 935 936 937 #if KWU_RC_MADPRED_E0227 938 Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity ) 996 939 { 997 940 Int LCUIdx = getLCUCoded(); … … 1003 946 #endif 1004 947 1005 #if RATE_CONTROL_INTRA1006 if (eSliceType == I_SLICE){1007 Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;1008 Int bitrateWindow = min(4,noOfLCUsLeft);1009 Double MAD = getLCU(LCUIdx).m_costIntra;1010 1011 if (m_remainingCostIntra > 0.1 )1012 {1013 Double weightedBitsLeft = (m_bitsLeft*bitrateWindow+(m_bitsLeft-getLCU(LCUIdx).m_targetBitsLeft)*noOfLCUsLeft)/(Double)bitrateWindow;1014 avgBits = Int( MAD*weightedBitsLeft/m_remainingCostIntra );1015 }1016 else1017 {1018 avgBits = Int( m_bitsLeft / m_LCULeft );1019 }1020 m_remainingCostIntra -= MAD;1021 }1022 else1023 {1024 #endif1025 #if M0036_RC_IMPROVEMENT1026 Double totalWeight = 0;1027 for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )1028 {1029 totalWeight += m_LCUs[i].m_bitWeight;1030 }1031 Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );1032 avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );1033 #else1034 if ( m_lastPicture == NULL )1035 {1036 avgBits = Int( m_bitsLeft / m_LCULeft );1037 }1038 else1039 {1040 MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;1041 totalMAD = m_lastPicture->getTotalMAD();1042 for ( Int i=0; i<LCUIdx; i++ )1043 {1044 totalMAD -= m_lastPicture->getLCU(i).m_MAD;1045 }1046 1047 if ( totalMAD > 0.1 )1048 {1049 avgBits = Int( m_bitsLeft * MAD / totalMAD );1050 }1051 else1052 {1053 avgBits = Int( m_bitsLeft / m_LCULeft );1054 }1055 }1056 #endif1057 #if RATE_CONTROL_INTRA1058 }1059 #endif1060 1061 if ( avgBits < 1 )1062 {1063 avgBits = 1;1064 }1065 1066 bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;1067 m_LCUs[ LCUIdx ].m_targetBits = avgBits;1068 1069 return bpp;1070 }1071 1072 1073 #if KWU_RC_MADPRED_E02271074 Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )1075 {1076 Int LCUIdx = getLCUCoded();1077 Double bpp = -1.0;1078 Int avgBits = 0;1079 #if !M0036_RC_IMPROVEMENT1080 Double totalMAD = -1.0;1081 Double MAD = -1.0;1082 #endif1083 1084 948 Double totalMAD = -1.0; 1085 949 Double MAD = -1.0; … … 1300 1164 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1301 1165 1302 #if M0036_RC_IMPROVEMENT1303 1166 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1304 1167 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1305 #else1306 alpha = Clip3( 0.05, 20.0, alpha );1307 beta = Clip3( -3.0, -0.1, beta );1308 #endif1309 1168 1310 1169 TRCParameter rcPara; … … 1319 1178 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1320 1179 double lnbpp = log( bpp ); 1321 #if M0036_RC_IMPROVEMENT1322 1180 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1323 #else1324 lnbpp = Clip3( -5.0, 1.0, lnbpp );1325 #endif1326 1181 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1327 1182 1328 #if M0036_RC_IMPROVEMENT1329 1183 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1330 1184 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1331 #else1332 alpha = Clip3( 0.05, 20.0, alpha );1333 beta = Clip3( -3.0, -0.1, beta );1334 #endif1335 1185 TRCParameter rcPara; 1336 1186 rcPara.m_alpha = alpha; … … 1340 1190 } 1341 1191 1342 #if !M0036_RC_IMPROVEMENT1343 Double TEncRCPic::getEffectivePercentage()1344 {1345 Int effectivePiexels = 0;1346 Int totalPixels = 0;1347 1348 for ( Int i=0; i<m_numberOfLCU; i++ )1349 {1350 totalPixels += m_LCUs[i].m_numberOfPixel;1351 if ( m_LCUs[i].m_QP > 0 )1352 {1353 effectivePiexels += m_LCUs[i].m_numberOfPixel;1354 }1355 }1356 1357 Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;1358 return effectivePixelPercentage;1359 }1360 #endif1361 1362 1192 Double TEncRCPic::calAverageQP() 1363 1193 { … … 1414 1244 } 1415 1245 1416 #if M0036_RC_IMPROVEMENT1417 #if RATE_CONTROL_INTRA1418 1246 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType) 1419 #else1420 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )1421 #endif1422 #else1423 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )1424 #endif1425 1247 { 1426 1248 m_picActualHeaderBits = actualHeaderBits; … … 1435 1257 } 1436 1258 m_picLambda = averageLambda; 1437 #if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E02271438 1259 #if KWU_RC_MADPRED_E0227 1439 1260 m_totalMAD = 0; 1440 #endif1441 1261 for ( Int i=0; i<m_numberOfLCU; i++ ) 1442 1262 { … … 1447 1267 Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha; 1448 1268 Double beta = m_encRCSeq->getPicPara( m_frameLevel ).m_beta; 1449 #if RATE_CONTROL_INTRA1450 1269 if (eSliceType == I_SLICE) 1451 1270 { … … 1454 1273 else 1455 1274 { 1456 #endif1457 1275 // update parameters 1458 1276 Double picActualBits = ( Double )m_picActualBits; … … 1461 1279 Double inputLambda = m_picLambda; 1462 1280 1463 #if M0036_RC_IMPROVEMENT1464 1281 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 ) 1465 #else1466 if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )1467 #endif1468 1282 { 1469 1283 alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 ); 1470 1284 beta *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 ); 1471 1285 1472 #if M0036_RC_IMPROVEMENT1473 1286 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1474 1287 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1475 #else1476 alpha = Clip3( 0.05, 20.0, alpha );1477 beta = Clip3( -3.0, -0.1, beta );1478 #endif1479 1288 TRCParameter rcPara; 1480 1289 rcPara.m_alpha = alpha; … … 1488 1297 alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha; 1489 1298 double lnbpp = log( picActualBpp ); 1490 #if M0036_RC_IMPROVEMENT1491 1299 lnbpp = Clip3( -5.0, -0.1, lnbpp ); 1492 #else1493 lnbpp = Clip3( -5.0, 1.0, lnbpp );1494 #endif1495 1300 beta += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp; 1496 1301 1497 #if M0036_RC_IMPROVEMENT1498 1302 alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha ); 1499 1303 beta = Clip3( g_RCBetaMinValue, g_RCBetaMaxValue, beta ); 1500 #else 1501 alpha = Clip3( 0.05, 20.0, alpha ); 1502 beta = Clip3( -3.0, -0.1, beta ); 1503 #endif 1504 #if RATE_CONTROL_INTRA 1505 } 1506 #endif 1304 } 1507 1305 1508 1306 TRCParameter rcPara; … … 1512 1310 m_encRCSeq->setPicPara( m_frameLevel, rcPara ); 1513 1311 1514 #if M0036_RC_IMPROVEMENT1515 1312 if ( m_frameLevel == 1 ) 1516 1313 { … … 1519 1316 m_encRCSeq->setLastLambda( updateLastLambda ); 1520 1317 } 1521 #endif 1522 } 1523 1524 #if RATE_CONTROL_INTRA 1318 } 1319 1525 1320 Int TEncRCPic::getRefineBitsForIntra( Int orgBits ) 1526 1321 { … … 1611 1406 return estLambda; 1612 1407 } 1613 #endif1614 1408 1615 1409 TEncRateCtrl::TEncRateCtrl() … … 1645 1439 } 1646 1440 1647 #if M0036_RC_IMPROVEMENT1648 1441 #if KWU_RC_MADPRED_E0227 1649 1442 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], Int layerID ) … … 1651 1444 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] ) 1652 1445 #endif 1653 #else1654 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] )1655 #endif1656 1446 { 1657 1447 destroy(); … … 1668 1458 1669 1459 Int numberOfLevel = 1; 1670 #if M0036_RC_IMPROVEMENT1671 1460 Int adaptiveBit = 0; 1672 1461 if ( keepHierBits > 0 ) 1673 #else1674 if ( keepHierBits )1675 #endif1676 1462 { 1677 1463 numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1; … … 1696 1482 } 1697 1483 1698 #if M0036_RC_IMPROVEMENT1699 1484 if ( keepHierBits > 0 ) 1700 #else1701 if ( keepHierBits )1702 #endif1703 1485 { 1704 1486 Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) ); … … 1733 1515 bitsRatio[3] = 14; 1734 1516 } 1735 #if M0036_RC_IMPROVEMENT1736 1517 if ( keepHierBits == 2 ) 1737 1518 { 1738 1519 adaptiveBit = 1; 1739 1520 } 1740 #endif1741 1521 } 1742 1522 else if ( GOPSize == 8 && !isLowdelay ) … … 1786 1566 bitsRatio[7] = 1; 1787 1567 } 1788 #if M0036_RC_IMPROVEMENT1789 1568 if ( keepHierBits == 2 ) 1790 1569 { 1791 1570 adaptiveBit = 2; 1792 1571 } 1793 #endif1794 1572 } 1795 1573 else 1796 1574 { 1797 #if M0036_RC_IMPROVEMENT1798 1575 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" ); 1799 #else1800 printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );1801 #endif1802 1576 } 1803 1577 } … … 1812 1586 } 1813 1587 } 1814 #if M0036_RC_IMPROVEMENT1815 1588 if ( keepHierBits > 0 ) 1816 #else1817 if ( keepHierBits )1818 #endif1819 1589 { 1820 1590 if ( GOPSize == 4 && isLowdelay ) … … 1851 1621 1852 1622 m_encRCSeq = new TEncRCSeq; 1853 #if M0036_RC_IMPROVEMENT1854 1623 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit ); 1855 #else1856 m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );1857 #endif1858 1624 m_encRCSeq->initBitsRatio( bitsRatio ); 1859 1625 m_encRCSeq->initGOPID2Level( GOPID2Level ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncRateCtrl.h
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 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 101 89 #if KWU_RC_MADPRED_E0227 102 90 Double m_MAD; 103 104 91 Int m_CUWidth; 105 92 Int m_CUHeight; … … 121 108 122 109 public: 123 #if M0036_RC_IMPROVEMENT124 110 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit ); 125 #else126 Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );127 #endif128 111 Void destroy(); 129 112 Void initBitsRatio( Int bitsRatio[] ); … … 132 115 Void initLCUPara( TRCParameter** LCUPara = NULL ); // NULL to initial with default value 133 116 Void updateAfterPic ( Int bits ); 134 #if !RATE_CONTROL_INTRA135 Int getRefineBitsForIntra( Int orgBits );136 #endif137 #if M0036_RC_IMPROVEMENT138 117 Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB ); 139 #endif140 118 141 119 public: … … 175 153 Double getBetaUpdate() { return m_betaUpdate; } 176 154 177 #if M0036_RC_IMPROVEMENT178 155 Int getAdaptiveBits() { return m_adaptiveBit; } 179 156 Double getLastLambda() { return m_lastLambda; } 180 157 Void setLastLambda( Double lamdba ) { m_lastLambda = lamdba; } 181 #endif182 158 183 159 private: … … 208 184 Bool m_useLCUSeparateModel; 209 185 210 #if M0036_RC_IMPROVEMENT211 186 Int m_adaptiveBit; 212 187 Double m_lastLambda; 213 #endif214 188 }; 215 189 … … 227 201 private: 228 202 Int xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize ); 229 #if M0036_RC_IMPROVEMENT230 203 Void xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 231 204 Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize ); 232 #endif233 205 234 206 public: … … 266 238 Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC ); 267 239 #endif 268 #if !RATE_CONTROL_INTRA269 Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );270 #endif271 240 Int estimatePicQP ( Double lambda, list<TEncRCPic*>& listPreviousPictures ); 272 #if RATE_CONTROL_INTRA273 241 Int getRefineBitsForIntra(Int orgBits); 274 242 Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel); … … 279 247 Double getLCUTargetBpp(SliceType eSliceType); 280 248 Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP); 281 #else282 Double getLCUTargetBpp();283 #endif284 285 249 #if KWU_RC_MADPRED_E0227 286 250 Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity ); 287 251 #endif 288 289 252 Double getLCUEstLambda( Double bpp ); 290 253 Int getLCUEstQP( Double lambda, Int clipPicQP ); 291 254 292 255 Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true ); 293 #if M0036_RC_IMPROVEMENT294 #if RATE_CONTROL_INTRA295 256 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType); 296 #else297 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );298 #endif299 #else300 Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );301 #endif302 257 303 258 Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures ); 304 305 259 #if KWU_RC_MADPRED_E0227 306 260 Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures ); 307 261 Void setIVPic( TEncRCPic* baseRCPic ); 308 #endif309 310 #if !M0036_RC_IMPROVEMENT311 Double getEffectivePercentage();312 262 #endif 313 263 Double calAverageQP(); … … 326 276 Int getNumberOfLCU() { return m_numberOfLCU; } 327 277 Int getTargetBits() { return m_targetBits; } 328 #if !RATE_CONTROL_INTRA329 Void setTargetBits( Int bits ) { m_targetBits = bits; }330 #endif331 278 Int getEstHeaderBits() { return m_estHeaderBits; } 332 279 Int getLCULeft() { return m_LCULeft; } … … 338 285 TRCLCU& getLCU( Int LCUIdx ) { return m_LCUs[LCUIdx]; } 339 286 Int getPicActualHeaderBits() { return m_picActualHeaderBits; } 340 #if !M0036_RC_IMPROVEMENT341 Double getTotalMAD() { return m_totalMAD; }342 Void setTotalMAD( Double MAD ) { m_totalMAD = MAD; }343 #endif344 #if RATE_CONTROL_INTRA345 287 Void setTargetBits( Int bits ) { m_targetBits = bits; m_bitsLeft = bits;} 346 288 Void setTotalIntraCost(Double cost) { m_totalCostIntra = cost; } 347 289 Void getLCUInitTargetBits(); 348 #endif349 350 290 #if KWU_RC_MADPRED_E0227 351 291 Double getTotalMAD() { return m_totalMAD; } … … 368 308 Void setLayerID(Int layerid) { m_LayerID = layerid; } 369 309 #endif 370 371 310 private: 372 311 TEncRCSeq* m_encRCSeq; … … 390 329 Double m_totalMAD; 391 330 #endif 392 #if RATE_CONTROL_INTRA393 331 Double m_totalCostIntra; 394 332 Double m_remainingCostIntra; 395 #endif396 333 Int m_picActualBits; // the whole picture, including header 397 334 Int m_picQP; // in integer form 398 335 Double m_picLambda; 399 #if !M0036_RC_IMPROVEMENT400 TEncRCPic* m_lastPicture;401 #endif402 403 336 #if KWU_RC_MADPRED_E0227 404 337 Double m_totalMAD; … … 417 350 418 351 public: 419 #if M0036_RC_IMPROVEMENT420 352 #if KWU_RC_MADPRED_E0227 421 353 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP], Int layerID ); 422 354 #else 423 355 Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] ); 424 #endif425 #else426 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] );427 356 #endif 428 357 Void destroy(); … … 443 372 Void setLayerID(Int layerid) { m_LayerID = layerid; } 444 373 #endif 445 446 374 private: 447 375 TEncRCSeq* m_encRCSeq; … … 450 378 list<TEncRCPic*> m_listRCPictures; 451 379 Int m_RCQP; 452 453 380 #if KWU_RC_MADPRED_E0227 454 381 Int m_LayerID; … … 456 383 }; 457 384 458 #else 459 460 // ==================================================================================================================== 461 // Class definition 462 // ==================================================================================================================== 463 #define MAX_DELTA_QP 2 464 #define MAX_CUDQP_DEPTH 0 465 466 typedef struct FrameData 467 { 468 Bool m_isReferenced; 469 Int m_qp; 470 Int m_bits; 471 Double m_costMAD; 472 }FrameData; 473 474 typedef struct LCUData 475 { 476 Int m_qp; ///< coded QP 477 Int m_bits; ///< actually generated bits 478 Int m_pixels; ///< number of pixels for a unit 479 Int m_widthInPixel; ///< number of pixels for width 480 Int m_heightInPixel; ///< number of pixels for height 481 Double m_costMAD; ///< texture complexity for a unit 482 }LCUData; 483 484 class MADLinearModel 485 { 486 private: 487 Bool m_activeOn; 488 Double m_paramY1; 489 Double m_paramY2; 490 Double m_costMADs[3]; 491 492 public: 493 MADLinearModel () {}; 494 ~MADLinearModel() {}; 495 496 Void initMADLinearModel (); 497 Double getMAD (); 498 Void updateMADLiearModel (); 499 Void updateMADHistory (Double costMAD); 500 Bool IsUpdateAvailable () { return m_activeOn; } 501 }; 502 503 class PixelBaseURQQuadraticModel 504 { 505 private: 506 Double m_paramHighX1; 507 Double m_paramHighX2; 508 Double m_paramLowX1; 509 Double m_paramLowX2; 510 public: 511 PixelBaseURQQuadraticModel () {}; 512 ~PixelBaseURQQuadraticModel() {}; 513 514 Void initPixelBaseQuadraticModel (); 515 Int getQP (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD); 516 Void updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD); 517 Bool checkUpdateAvailable (Int qpReference ); 518 Double xConvertQP2QStep (Int qp ); 519 Int xConvertQStep2QP (Double qStep ); 520 }; 521 522 class TEncRateCtrl 523 { 524 private: 525 Bool m_isLowdelay; 526 Int m_prevBitrate; 527 Int m_currBitrate; 528 Int m_frameRate; 529 Int m_refFrameNum; 530 Int m_nonRefFrameNum; 531 Int m_numOfPixels; 532 Int m_sourceWidthInLCU; 533 Int m_sourceHeightInLCU; 534 Int m_sizeGOP; 535 Int m_indexGOP; 536 Int m_indexFrame; 537 Int m_indexLCU; 538 Int m_indexUnit; 539 Int m_indexRefFrame; 540 Int m_indexNonRefFrame; 541 Int m_indexPOCInGOP; 542 Int m_indexPrevPOCInGOP; 543 Int m_occupancyVB; 544 Int m_initialOVB; 545 Int m_targetBufLevel; 546 Int m_initialTBL; 547 Int m_remainingBitsInGOP; 548 Int m_remainingBitsInFrame; 549 Int m_occupancyVBInFrame; 550 Int m_targetBits; 551 Int m_numUnitInFrame; 552 Int m_codedPixels; 553 Bool m_activeUnitLevelOn; 554 Double m_costNonRefAvgWeighting; 555 Double m_costRefAvgWeighting; 556 Double m_costAvgbpp; 557 558 FrameData* m_pcFrameData; 559 LCUData* m_pcLCUData; 560 561 MADLinearModel m_cMADLinearModel; 562 PixelBaseURQQuadraticModel m_cPixelURQQuadraticModel; 563 564 public: 565 TEncRateCtrl () {}; 566 virtual ~TEncRateCtrl() {}; 567 568 Void create (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight); 569 Void destroy (); 570 571 Void initFrameData (Int qp = 0); 572 Void initUnitData (Int qp = 0); 573 Int getFrameQP (Bool isReferenced, Int POC); 574 Bool calculateUnitQP (); 575 Int getUnitQP () { return m_pcLCUData[m_indexLCU].m_qp; } 576 Void updateRCGOPStatus (); 577 Void updataRCFrameStatus (Int frameBits, SliceType eSliceType); 578 Void updataRCUnitStatus (); 579 Void updateLCUData (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp); 580 #if KWU_RC_MADPRED_E0227 581 Void updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction); 582 #endif 583 Void updateFrameData (UInt64 actualFrameBits); 584 Double xAdjustmentBits (Int& reductionBits, Int& compensationBits); 585 Int getGOPId () { return m_indexFrame; } 586 }; 587 #endif 588 589 #endif 590 591 385 #endif 386 387 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 45 45 //! \{ 46 46 47 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()48 {49 m_pcEntropyCoder = NULL;50 m_pppcRDSbacCoder = NULL;51 m_pcRDGoOnSbacCoder = NULL;52 m_pppcBinCoderCABAC = NULL;53 m_iCount = NULL;54 m_iOffset = NULL;55 m_iOffsetOrg = NULL;56 m_iRate = NULL;57 m_iDist = NULL;58 m_dCost = NULL;59 m_dCostPartBest = NULL;60 m_iDistOrg = NULL;61 m_iTypePartBest = NULL;62 #if SAO_ENCODING_CHOICE_CHROMA63 m_depthSaoRate[0][0] = 0;64 m_depthSaoRate[0][1] = 0;65 m_depthSaoRate[0][2] = 0;66 m_depthSaoRate[0][3] = 0;67 m_depthSaoRate[1][0] = 0;68 m_depthSaoRate[1][1] = 0;69 m_depthSaoRate[1][2] = 0;70 m_depthSaoRate[1][3] = 0;71 #endif72 }73 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()74 {75 76 }77 // ====================================================================================================================78 // Constants79 // ====================================================================================================================80 81 82 // ====================================================================================================================83 // Tables84 // ====================================================================================================================85 86 inline Double xRoundIbdi2(Int bitDepth, Double x)87 {88 return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));89 }90 47 91 48 /** rounding with IBDI 92 49 * \param x 93 50 */ 51 inline Double xRoundIbdi2(Int bitDepth, Double x) 52 { 53 return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8)))); 54 } 55 94 56 inline Double xRoundIbdi(Int bitDepth, Double x) 95 57 { … … 98 60 99 61 100 101 /** process SAO for one partition 102 * \param *psQTPart, iPartIdx, dLambda 103 */ 104 Void TEncSampleAdaptiveOffset::rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr) 105 { 106 Int iTypeIdx; 107 Int iNumTotalType = MAX_NUM_SAO_TYPE; 108 SAOQTPart* pOnePart = &(psQTPart[iPartIdx]); 109 110 Int64 iEstDist; 111 Int iClassIdx; 112 Int uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT((yCbCr == 0 ? g_bitDepthY : g_bitDepthC)-8); 113 UInt uiDepth = pOnePart->PartLevel; 114 115 m_iDistOrg [iPartIdx] = 0; 116 117 Double bestRDCostTableBo = MAX_DOUBLE; 118 Int bestClassTableBo = 0; 119 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 120 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 121 122 Int addr; 123 Int allowMergeLeft; 124 Int allowMergeUp; 125 Int frameWidthInCU = m_pcPic->getFrameWidthInCU(); 126 SaoLcuParam saoLcuParamRdo; 127 128 for (iTypeIdx=-1; iTypeIdx<iNumTotalType; iTypeIdx++) 129 { 130 if( m_bUseSBACRD ) 131 { 132 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 133 m_pcRDGoOnSbacCoder->resetBits(); 134 } 135 else 136 { 137 m_pcEntropyCoder->resetEntropy(); 138 m_pcEntropyCoder->resetBits(); 139 } 140 141 iEstDist = 0; 142 143 if (iTypeIdx == -1) 144 { 145 for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++) 146 { 147 for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++) 148 { 149 addr = ry * frameWidthInCU + rx; 150 151 // get bits for iTypeIdx = -1 152 allowMergeLeft = 1; 153 allowMergeUp = 1; 154 if (rx != 0) 155 { 156 // check tile id and slice id 157 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 158 { 159 allowMergeLeft = 0; 160 } 161 } 162 if (ry!=0) 163 { 164 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 165 { 166 allowMergeUp = 0; 167 } 168 } 169 170 // reset 171 resetSaoUnit(&saoLcuParamRdo); 172 173 // set merge flag 174 saoLcuParamRdo.mergeUpFlag = 1; 175 saoLcuParamRdo.mergeLeftFlag = 1; 176 177 if (ry == pOnePart->StartCUY) 178 { 179 saoLcuParamRdo.mergeUpFlag = 0; 180 } 181 182 if (rx == pOnePart->StartCUX) 183 { 184 saoLcuParamRdo.mergeLeftFlag = 0; 185 } 186 187 m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry, &saoLcuParamRdo, 1, 1, allowMergeLeft, allowMergeUp); 188 189 } 190 } 191 } 192 193 if (iTypeIdx>=0) 194 { 195 iEstDist = estSaoTypeDist(iPartIdx, iTypeIdx, uiShift, dLambda, currentDistortionTableBo, currentRdCostTableBo); 196 if( iTypeIdx == SAO_BO ) 197 { 198 // Estimate Best Position 199 Double currentRDCost = 0.0; 200 201 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 202 { 203 currentRDCost = 0.0; 204 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 205 { 206 currentRDCost += currentRdCostTableBo[uj]; 207 } 208 209 if( currentRDCost < bestRDCostTableBo) 210 { 211 bestRDCostTableBo = currentRDCost; 212 bestClassTableBo = i; 213 } 214 } 215 216 // Re code all Offsets 217 // Code Center 218 for(iClassIdx = bestClassTableBo; iClassIdx < bestClassTableBo+SAO_BO_LEN; iClassIdx++) 219 { 220 iEstDist += currentDistortionTableBo[iClassIdx]; 221 } 222 } 223 224 for (Int ry = pOnePart->StartCUY; ry<= pOnePart->EndCUY; ry++) 225 { 226 for (Int rx = pOnePart->StartCUX; rx <= pOnePart->EndCUX; rx++) 227 { 228 addr = ry * frameWidthInCU + rx; 229 230 // get bits for iTypeIdx = -1 231 allowMergeLeft = 1; 232 allowMergeUp = 1; 233 if (rx != 0) 234 { 235 // check tile id and slice id 236 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 237 { 238 allowMergeLeft = 0; 239 } 240 } 241 if (ry!=0) 242 { 243 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 244 { 245 allowMergeUp = 0; 246 } 247 } 248 249 // reset 250 resetSaoUnit(&saoLcuParamRdo); 251 252 // set merge flag 253 saoLcuParamRdo.mergeUpFlag = 1; 254 saoLcuParamRdo.mergeLeftFlag = 1; 255 256 if (ry == pOnePart->StartCUY) 257 { 258 saoLcuParamRdo.mergeUpFlag = 0; 259 } 260 261 if (rx == pOnePart->StartCUX) 262 { 263 saoLcuParamRdo.mergeLeftFlag = 0; 264 } 265 266 // set type and offsets 267 saoLcuParamRdo.typeIdx = iTypeIdx; 268 saoLcuParamRdo.subTypeIdx = (iTypeIdx==SAO_BO)?bestClassTableBo:0; 269 saoLcuParamRdo.length = m_iNumClass[iTypeIdx]; 270 for (iClassIdx = 0; iClassIdx < saoLcuParamRdo.length; iClassIdx++) 271 { 272 saoLcuParamRdo.offset[iClassIdx] = (Int)m_iOffset[iPartIdx][iTypeIdx][iClassIdx+saoLcuParamRdo.subTypeIdx+1]; 273 } 274 275 m_pcEntropyCoder->encodeSaoUnitInterleaving(yCbCr, 1, rx, ry, &saoLcuParamRdo, 1, 1, allowMergeLeft, allowMergeUp); 276 277 } 278 } 279 280 m_iDist[iPartIdx][iTypeIdx] = iEstDist; 281 m_iRate[iPartIdx][iTypeIdx] = m_pcEntropyCoder->getNumberOfWrittenBits(); 282 283 m_dCost[iPartIdx][iTypeIdx] = (Double)((Double)m_iDist[iPartIdx][iTypeIdx] + dLambda * (Double) m_iRate[iPartIdx][iTypeIdx]); 284 285 if(m_dCost[iPartIdx][iTypeIdx] < m_dCostPartBest[iPartIdx]) 286 { 287 m_iDistOrg [iPartIdx] = 0; 288 m_dCostPartBest[iPartIdx] = m_dCost[iPartIdx][iTypeIdx]; 289 m_iTypePartBest[iPartIdx] = iTypeIdx; 290 if( m_bUseSBACRD ) 291 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] ); 292 } 293 } 294 else 295 { 296 if(m_iDistOrg[iPartIdx] < m_dCostPartBest[iPartIdx] ) 297 { 298 m_dCostPartBest[iPartIdx] = (Double) m_iDistOrg[iPartIdx] + m_pcEntropyCoder->getNumberOfWrittenBits()*dLambda ; 299 m_iTypePartBest[iPartIdx] = -1; 300 if( m_bUseSBACRD ) 301 { 302 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[pOnePart->PartLevel][CI_TEMP_BEST] ); 303 } 304 } 305 } 306 } 307 308 pOnePart->bProcessed = true; 309 pOnePart->bSplit = false; 310 pOnePart->iMinDist = m_iTypePartBest[iPartIdx] >= 0 ? m_iDist[iPartIdx][m_iTypePartBest[iPartIdx]] : m_iDistOrg[iPartIdx]; 311 pOnePart->iMinRate = (Int) (m_iTypePartBest[iPartIdx] >= 0 ? m_iRate[iPartIdx][m_iTypePartBest[iPartIdx]] : 0); 312 pOnePart->dMinCost = pOnePart->iMinDist + dLambda * pOnePart->iMinRate; 313 pOnePart->iBestType = m_iTypePartBest[iPartIdx]; 314 if (pOnePart->iBestType != -1) 315 { 316 // pOnePart->bEnableFlag = 1; 317 pOnePart->iLength = m_iNumClass[pOnePart->iBestType]; 318 Int minIndex = 0; 319 if( pOnePart->iBestType == SAO_BO ) 320 { 321 pOnePart->subTypeIdx = bestClassTableBo; 322 minIndex = pOnePart->subTypeIdx; 323 } 324 for (Int i=0; i< pOnePart->iLength ; i++) 325 { 326 pOnePart->iOffset[i] = (Int) m_iOffset[iPartIdx][pOnePart->iBestType][minIndex+i+1]; 327 } 328 329 } 330 else 331 { 332 // pOnePart->bEnableFlag = 0; 333 pOnePart->iLength = 0; 334 } 335 } 336 337 /** Run partition tree disable 338 */ 339 Void TEncSampleAdaptiveOffset::disablePartTree(SAOQTPart *psQTPart, Int iPartIdx) 340 { 341 SAOQTPart* pOnePart= &(psQTPart[iPartIdx]); 342 pOnePart->bSplit = false; 343 pOnePart->iLength = 0; 344 pOnePart->iBestType = -1; 345 346 if (pOnePart->PartLevel < m_uiMaxSplitLevel) 347 { 348 for (Int i=0; i<NUM_DOWN_PART; i++) 349 { 350 disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]); 351 } 352 } 353 } 354 355 /** Run quadtree decision function 356 * \param iPartIdx, pcPicOrg, pcPicDec, pcPicRest, &dCostFinal 357 */ 358 Void TEncSampleAdaptiveOffset::runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr) 359 { 360 SAOQTPart* pOnePart = &(psQTPart[iPartIdx]); 361 362 UInt uiDepth = pOnePart->PartLevel; 363 UInt uhNextDepth = uiDepth+1; 364 365 if (iPartIdx == 0) 366 { 367 dCostFinal = 0; 368 } 369 370 //SAO for this part 371 if(!pOnePart->bProcessed) 372 { 373 rdoSaoOnePart (psQTPart, iPartIdx, dLambda, yCbCr); 374 } 375 376 //SAO for sub 4 parts 377 if (pOnePart->PartLevel < iMaxLevel) 378 { 379 Double dCostNotSplit = dLambda + pOnePart->dMinCost; 380 Double dCostSplit = dLambda; 381 382 for (Int i=0; i< NUM_DOWN_PART ;i++) 383 { 384 if( m_bUseSBACRD ) 385 { 386 if ( 0 == i) //initialize RD with previous depth buffer 387 { 388 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 389 } 390 else 391 { 392 m_pppcRDSbacCoder[uhNextDepth][CI_CURR_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 393 } 394 } 395 runQuadTreeDecision(psQTPart, pOnePart->DownPartsIdx[i], dCostFinal, iMaxLevel, dLambda, yCbCr); 396 dCostSplit += dCostFinal; 397 if( m_bUseSBACRD ) 398 { 399 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_TEMP_BEST]); 400 } 401 } 402 403 if(dCostSplit < dCostNotSplit) 404 { 405 dCostFinal = dCostSplit; 406 pOnePart->bSplit = true; 407 pOnePart->iLength = 0; 408 pOnePart->iBestType = -1; 409 if( m_bUseSBACRD ) 410 { 411 m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]); 412 } 413 } 414 else 415 { 416 dCostFinal = dCostNotSplit; 417 pOnePart->bSplit = false; 418 for (Int i=0; i<NUM_DOWN_PART; i++) 419 { 420 disablePartTree(psQTPart, pOnePart->DownPartsIdx[i]); 421 } 422 if( m_bUseSBACRD ) 423 { 424 m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]->load(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 425 } 426 } 427 } 428 else 429 { 430 dCostFinal = pOnePart->dMinCost; 431 } 432 } 433 434 /** delete allocated memory of TEncSampleAdaptiveOffset class. 435 */ 436 Void TEncSampleAdaptiveOffset::destroyEncBuffer() 437 { 438 for (Int i=0;i<m_iNumTotalParts;i++) 439 { 440 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 441 { 442 if (m_iCount [i][j]) 443 { 444 delete [] m_iCount [i][j]; 445 } 446 if (m_iOffset[i][j]) 447 { 448 delete [] m_iOffset[i][j]; 449 } 450 if (m_iOffsetOrg[i][j]) 451 { 452 delete [] m_iOffsetOrg[i][j]; 453 } 454 } 455 if (m_iRate[i]) 456 { 457 delete [] m_iRate[i]; 458 } 459 if (m_iDist[i]) 460 { 461 delete [] m_iDist[i]; 462 } 463 if (m_dCost[i]) 464 { 465 delete [] m_dCost[i]; 466 } 467 if (m_iCount [i]) 468 { 469 delete [] m_iCount [i]; 470 } 471 if (m_iOffset[i]) 472 { 473 delete [] m_iOffset[i]; 474 } 475 if (m_iOffsetOrg[i]) 476 { 477 delete [] m_iOffsetOrg[i]; 478 } 479 480 } 481 if (m_iDistOrg) 482 { 483 delete [] m_iDistOrg ; m_iDistOrg = NULL; 484 } 485 if (m_dCostPartBest) 486 { 487 delete [] m_dCostPartBest ; m_dCostPartBest = NULL; 488 } 489 if (m_iTypePartBest) 490 { 491 delete [] m_iTypePartBest ; m_iTypePartBest = NULL; 492 } 493 if (m_iRate) 494 { 495 delete [] m_iRate ; m_iRate = NULL; 496 } 497 if (m_iDist) 498 { 499 delete [] m_iDist ; m_iDist = NULL; 500 } 501 if (m_dCost) 502 { 503 delete [] m_dCost ; m_dCost = NULL; 504 } 505 if (m_iCount) 506 { 507 delete [] m_iCount ; m_iCount = NULL; 508 } 509 if (m_iOffset) 510 { 511 delete [] m_iOffset ; m_iOffset = NULL; 512 } 513 if (m_iOffsetOrg) 514 { 515 delete [] m_iOffsetOrg ; m_iOffsetOrg = NULL; 516 } 517 Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight; 518 519 for (Int i=0;i<numLcu;i++) 520 { 521 for (Int j=0;j<3;j++) 522 { 523 for (Int k=0;k<MAX_NUM_SAO_TYPE;k++) 524 { 525 if (m_count_PreDblk [i][j][k]) 526 { 527 delete [] m_count_PreDblk [i][j][k]; 528 } 529 if (m_offsetOrg_PreDblk[i][j][k]) 530 { 531 delete [] m_offsetOrg_PreDblk[i][j][k]; 532 } 533 } 534 if (m_count_PreDblk [i][j]) 535 { 536 delete [] m_count_PreDblk [i][j]; 537 } 538 if (m_offsetOrg_PreDblk[i][j]) 539 { 540 delete [] m_offsetOrg_PreDblk[i][j]; 541 } 542 } 543 if (m_count_PreDblk [i]) 544 { 545 delete [] m_count_PreDblk [i]; 546 } 547 if (m_offsetOrg_PreDblk[i]) 548 { 549 delete [] m_offsetOrg_PreDblk[i]; 550 } 551 } 552 if (m_count_PreDblk) 553 { 554 delete [] m_count_PreDblk ; m_count_PreDblk = NULL; 555 } 556 if (m_offsetOrg_PreDblk) 557 { 558 delete [] m_offsetOrg_PreDblk ; m_offsetOrg_PreDblk = NULL; 559 } 560 561 Int iMaxDepth = 4; 562 Int iDepth; 563 for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 564 { 565 for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) 566 { 567 delete m_pppcRDSbacCoder[iDepth][iCIIdx]; 568 delete m_pppcBinCoderCABAC[iDepth][iCIIdx]; 569 } 570 } 571 572 for ( iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 573 { 574 delete [] m_pppcRDSbacCoder[iDepth]; 575 delete [] m_pppcBinCoderCABAC[iDepth]; 576 } 577 578 delete [] m_pppcRDSbacCoder; 579 delete [] m_pppcBinCoderCABAC; 580 } 581 582 /** create Encoder Buffer for SAO 583 * \param 584 */ 585 Void TEncSampleAdaptiveOffset::createEncBuffer() 586 { 587 m_iDistOrg = new Int64 [m_iNumTotalParts]; 588 m_dCostPartBest = new Double [m_iNumTotalParts]; 589 m_iTypePartBest = new Int [m_iNumTotalParts]; 590 591 m_iRate = new Int64* [m_iNumTotalParts]; 592 m_iDist = new Int64* [m_iNumTotalParts]; 593 m_dCost = new Double*[m_iNumTotalParts]; 594 595 m_iCount = new Int64 **[m_iNumTotalParts]; 596 m_iOffset = new Int64 **[m_iNumTotalParts]; 597 m_iOffsetOrg = new Int64 **[m_iNumTotalParts]; 598 599 for (Int i=0;i<m_iNumTotalParts;i++) 600 { 601 m_iRate[i] = new Int64 [MAX_NUM_SAO_TYPE]; 602 m_iDist[i] = new Int64 [MAX_NUM_SAO_TYPE]; 603 m_dCost[i] = new Double [MAX_NUM_SAO_TYPE]; 604 605 m_iCount [i] = new Int64 *[MAX_NUM_SAO_TYPE]; 606 m_iOffset[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 607 m_iOffsetOrg[i] = new Int64 *[MAX_NUM_SAO_TYPE]; 608 609 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 610 { 611 m_iCount [i][j] = new Int64 [MAX_NUM_SAO_CLASS]; 612 m_iOffset[i][j] = new Int64 [MAX_NUM_SAO_CLASS]; 613 m_iOffsetOrg[i][j]= new Int64 [MAX_NUM_SAO_CLASS]; 614 } 615 } 616 Int numLcu = m_iNumCuInWidth * m_iNumCuInHeight; 617 m_count_PreDblk = new Int64 ***[numLcu]; 618 m_offsetOrg_PreDblk = new Int64 ***[numLcu]; 619 for (Int i=0; i<numLcu; i++) 620 { 621 m_count_PreDblk[i] = new Int64 **[3]; 622 m_offsetOrg_PreDblk[i] = new Int64 **[3]; 623 624 for (Int j=0;j<3;j++) 625 { 626 m_count_PreDblk [i][j] = new Int64 *[MAX_NUM_SAO_TYPE]; 627 m_offsetOrg_PreDblk[i][j] = new Int64 *[MAX_NUM_SAO_TYPE]; 628 629 for (Int k=0;k<MAX_NUM_SAO_TYPE;k++) 630 { 631 m_count_PreDblk [i][j][k] = new Int64 [MAX_NUM_SAO_CLASS]; 632 m_offsetOrg_PreDblk[i][j][k]= new Int64 [MAX_NUM_SAO_CLASS]; 633 } 634 } 635 } 636 637 Int iMaxDepth = 4; 638 m_pppcRDSbacCoder = new TEncSbac** [iMaxDepth+1]; 639 #if FAST_BIT_EST 640 m_pppcBinCoderCABAC = new TEncBinCABACCounter** [iMaxDepth+1]; 641 #else 642 m_pppcBinCoderCABAC = new TEncBinCABAC** [iMaxDepth+1]; 643 #endif 644 645 for ( Int iDepth = 0; iDepth < iMaxDepth+1; iDepth++ ) 646 { 647 m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM]; 648 #if FAST_BIT_EST 649 m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM]; 650 #else 651 m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM]; 652 #endif 653 for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ ) 654 { 655 m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac; 656 #if FAST_BIT_EST 657 m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter; 658 #else 659 m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC; 660 #endif 661 m_pppcRDSbacCoder [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] ); 662 } 663 } 664 } 665 666 /** Start SAO encoder 667 * \param pcPic, pcEntropyCoder, pppcRDSbacCoder, pcRDGoOnSbacCoder 668 */ 669 Void TEncSampleAdaptiveOffset::startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder) 670 { 671 m_bUseSBACRD = true; 672 m_pcPic = pcPic; 673 m_pcEntropyCoder = pcEntropyCoder; 674 62 TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset() 63 { 64 m_pppcRDSbacCoder = NULL; 65 m_pcRDGoOnSbacCoder = NULL; 66 m_pppcBinCoderCABAC = NULL; 67 m_statData = NULL; 68 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 69 m_preDBFstatData = NULL; 70 #endif 71 } 72 73 TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset() 74 { 75 destroyEncData(); 76 } 77 78 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 79 Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed) 80 #else 81 Void TEncSampleAdaptiveOffset::createEncData() 82 #endif 83 { 84 85 //cabac coder for RDO 86 m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS]; 87 m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS]; 88 89 for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++) 90 { 91 m_pppcRDSbacCoder[cs] = new TEncSbac; 92 m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter; 93 m_pppcRDSbacCoder [cs]->init( m_pppcBinCoderCABAC [cs] ); 94 } 95 96 97 //statistics 98 m_statData = new SAOStatData**[m_numCTUsPic]; 99 for(Int i=0; i< m_numCTUsPic; i++) 100 { 101 m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 102 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 103 { 104 m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 105 } 106 } 107 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 108 if(isPreDBFSamplesUsed) 109 { 110 m_preDBFstatData = new SAOStatData**[m_numCTUsPic]; 111 for(Int i=0; i< m_numCTUsPic; i++) 112 { 113 m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS]; 114 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 115 { 116 m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES]; 117 } 118 } 119 120 } 121 #endif 122 123 #if SAO_ENCODING_CHOICE 124 ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate)); 125 #endif 126 127 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 128 { 129 m_skipLinesR[SAO_Y ][typeIdc]= 5; 130 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 131 132 m_skipLinesB[SAO_Y ][typeIdc]= 4; 133 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 134 135 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 136 if(isPreDBFSamplesUsed) 137 { 138 switch(typeIdc) 139 { 140 case SAO_TYPE_EO_0: 141 { 142 m_skipLinesR[SAO_Y ][typeIdc]= 5; 143 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 144 145 m_skipLinesB[SAO_Y ][typeIdc]= 3; 146 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 147 } 148 break; 149 case SAO_TYPE_EO_90: 150 { 151 m_skipLinesR[SAO_Y ][typeIdc]= 4; 152 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 153 154 m_skipLinesB[SAO_Y ][typeIdc]= 4; 155 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 156 } 157 break; 158 case SAO_TYPE_EO_135: 159 case SAO_TYPE_EO_45: 160 { 161 m_skipLinesR[SAO_Y ][typeIdc]= 5; 162 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3; 163 164 m_skipLinesB[SAO_Y ][typeIdc]= 4; 165 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2; 166 } 167 break; 168 case SAO_TYPE_BO: 169 { 170 m_skipLinesR[SAO_Y ][typeIdc]= 4; 171 m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2; 172 173 m_skipLinesB[SAO_Y ][typeIdc]= 3; 174 m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1; 175 } 176 break; 177 default: 178 { 179 printf("Not a supported type"); 180 assert(0); 181 exit(-1); 182 } 183 } 184 } 185 #endif 186 } 187 188 } 189 190 Void TEncSampleAdaptiveOffset::destroyEncData() 191 { 192 if(m_pppcRDSbacCoder != NULL) 193 { 194 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 195 { 196 delete m_pppcRDSbacCoder[cs]; 197 } 198 delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL; 199 } 200 201 if(m_pppcBinCoderCABAC != NULL) 202 { 203 for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ ) 204 { 205 delete m_pppcBinCoderCABAC[cs]; 206 } 207 delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL; 208 } 209 210 if(m_statData != NULL) 211 { 212 for(Int i=0; i< m_numCTUsPic; i++) 213 { 214 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 215 { 216 delete[] m_statData[i][compIdx]; 217 } 218 delete[] m_statData[i]; 219 } 220 delete[] m_statData; m_statData = NULL; 221 } 222 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 223 if(m_preDBFstatData != NULL) 224 { 225 for(Int i=0; i< m_numCTUsPic; i++) 226 { 227 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 228 { 229 delete[] m_preDBFstatData[i][compIdx]; 230 } 231 delete[] m_preDBFstatData[i]; 232 } 233 delete[] m_preDBFstatData; m_preDBFstatData = NULL; 234 } 235 236 #endif 237 } 238 239 Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) 240 { 675 241 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 676 m_pcEntropyCoder->setEntropyCoder(m_pcRDGoOnSbacCoder, pcPic->getSlice(0)); 677 m_pcEntropyCoder->resetEntropy(); 678 m_pcEntropyCoder->resetBits(); 679 680 if( m_bUseSBACRD ) 681 { 682 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_NEXT_BEST]); 683 m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_NEXT_BEST]); 684 } 685 } 686 687 /** End SAO encoder 688 */ 689 Void TEncSampleAdaptiveOffset::endSaoEnc() 690 { 691 m_pcPic = NULL; 692 m_pcEntropyCoder = NULL; 693 } 694 695 inline Int xSign(Int x) 696 { 697 return ((x >> 31) | ((Int)( (((UInt) -x)) >> 31))); 698 } 699 700 /** Calculate SAO statistics for non-cross-slice or non-cross-tile processing 701 * \param pRecStart to-be-filtered block buffer pointer 702 * \param pOrgStart original block buffer pointer 703 * \param stride picture buffer stride 704 * \param ppStat statistics buffer 705 * \param ppCount counter buffer 706 * \param width block width 707 * \param height block height 708 * \param pbBorderAvail availabilities of block border pixels 709 */ 710 Void TEncSampleAdaptiveOffset::calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr) 711 { 712 Int64 *stats, *count; 713 Int classIdx, posShift, startX, endX, startY, endY, signLeft,signRight,signDown,signDown1; 714 Pel *pOrg, *pRec; 715 UInt edgeType; 716 Int x, y; 717 Pel *pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo; 718 719 //--------- Band offset-----------// 720 stats = ppStats[SAO_BO]; 721 count = ppCount[SAO_BO]; 722 pOrg = pOrgStart; 723 pRec = pRecStart; 724 for (y=0; y< height; y++) 725 { 726 for (x=0; x< width; x++) 727 { 728 classIdx = pTableBo[pRec[x]]; 729 if (classIdx) 730 { 731 stats[classIdx] += (pOrg[x] - pRec[x]); 732 count[classIdx] ++; 733 } 734 } 735 pOrg += stride; 736 pRec += stride; 737 } 738 //---------- Edge offset 0--------------// 739 stats = ppStats[SAO_EO_0]; 740 count = ppCount[SAO_EO_0]; 741 pOrg = pOrgStart; 742 pRec = pRecStart; 743 744 745 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 746 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 747 for (y=0; y< height; y++) 748 { 749 signLeft = xSign(pRec[startX] - pRec[startX-1]); 750 for (x=startX; x< endX; x++) 751 { 752 signRight = xSign(pRec[x] - pRec[x+1]); 753 edgeType = signRight + signLeft + 2; 754 signLeft = -signRight; 755 756 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 757 count[m_auiEoTable[edgeType]] ++; 758 } 759 pRec += stride; 760 pOrg += stride; 761 } 762 763 //---------- Edge offset 1--------------// 764 stats = ppStats[SAO_EO_1]; 765 count = ppCount[SAO_EO_1]; 766 pOrg = pOrgStart; 767 pRec = pRecStart; 768 769 startY = (pbBorderAvail[SGU_T]) ? 0 : 1; 770 endY = (pbBorderAvail[SGU_B]) ? height : height-1; 771 if (!pbBorderAvail[SGU_T]) 772 { 773 pRec += stride; 774 pOrg += stride; 775 } 776 777 for (x=0; x< width; x++) 778 { 779 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]); 780 } 781 for (y=startY; y<endY; y++) 782 { 783 for (x=0; x< width; x++) 784 { 785 signDown = xSign(pRec[x] - pRec[x+stride]); 786 edgeType = signDown + m_iUpBuff1[x] + 2; 787 m_iUpBuff1[x] = -signDown; 788 789 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 790 count[m_auiEoTable[edgeType]] ++; 791 } 792 pOrg += stride; 793 pRec += stride; 794 } 795 //---------- Edge offset 2--------------// 796 stats = ppStats[SAO_EO_2]; 797 count = ppCount[SAO_EO_2]; 798 pOrg = pOrgStart; 799 pRec = pRecStart; 800 801 posShift= stride + 1; 802 803 startX = (pbBorderAvail[SGU_L]) ? 0 : 1 ; 804 endX = (pbBorderAvail[SGU_R]) ? width : (width-1); 805 806 //prepare 2nd line upper sign 807 pRec += stride; 808 for (x=startX; x< endX+1; x++) 809 { 810 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]); 811 } 812 813 //1st line 814 pRec -= stride; 815 if(pbBorderAvail[SGU_TL]) 816 { 817 x= 0; 818 edgeType = xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2; 819 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 820 count[m_auiEoTable[edgeType]] ++; 821 } 822 if(pbBorderAvail[SGU_T]) 823 { 824 for(x= 1; x< endX; x++) 825 { 826 edgeType = xSign(pRec[x] - pRec[x- posShift]) - m_iUpBuff1[x+1] + 2; 827 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 828 count[m_auiEoTable[edgeType]] ++; 829 } 830 } 831 pRec += stride; 832 pOrg += stride; 833 834 //middle lines 835 for (y= 1; y< height-1; y++) 836 { 837 for (x=startX; x<endX; x++) 838 { 839 signDown1 = xSign(pRec[x] - pRec[x+ posShift]) ; 840 edgeType = signDown1 + m_iUpBuff1[x] + 2; 841 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 842 count[m_auiEoTable[edgeType]] ++; 843 844 m_iUpBufft[x+1] = -signDown1; 845 } 846 m_iUpBufft[startX] = xSign(pRec[stride+startX] - pRec[startX-1]); 847 848 ipSwap = m_iUpBuff1; 849 m_iUpBuff1 = m_iUpBufft; 850 m_iUpBufft = ipSwap; 851 852 pRec += stride; 853 pOrg += stride; 854 } 855 856 //last line 857 if(pbBorderAvail[SGU_B]) 858 { 859 for(x= startX; x< width-1; x++) 860 { 861 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 862 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 863 count[m_auiEoTable[edgeType]] ++; 864 } 865 } 866 if(pbBorderAvail[SGU_BR]) 867 { 868 x= width -1; 869 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 870 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 871 count[m_auiEoTable[edgeType]] ++; 872 } 873 874 //---------- Edge offset 3--------------// 875 876 stats = ppStats[SAO_EO_3]; 877 count = ppCount[SAO_EO_3]; 878 pOrg = pOrgStart; 879 pRec = pRecStart; 880 881 posShift = stride - 1; 882 startX = (pbBorderAvail[SGU_L]) ? 0 : 1; 883 endX = (pbBorderAvail[SGU_R]) ? width : (width -1); 884 885 //prepare 2nd line upper sign 886 pRec += stride; 887 for (x=startX-1; x< endX; x++) 888 { 889 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x- posShift]); 890 } 891 892 893 //first line 894 pRec -= stride; 895 if(pbBorderAvail[SGU_T]) 896 { 897 for(x= startX; x< width -1; x++) 898 { 899 edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2; 900 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 901 count[m_auiEoTable[edgeType]] ++; 902 } 903 } 904 if(pbBorderAvail[SGU_TR]) 905 { 906 x= width-1; 907 edgeType = xSign(pRec[x] - pRec[x- posShift]) -m_iUpBuff1[x-1] + 2; 908 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 909 count[m_auiEoTable[edgeType]] ++; 910 } 911 pRec += stride; 912 pOrg += stride; 913 914 //middle lines 915 for (y= 1; y< height-1; y++) 916 { 917 for(x= startX; x< endX; x++) 918 { 919 signDown1 = xSign(pRec[x] - pRec[x+ posShift]) ; 920 edgeType = signDown1 + m_iUpBuff1[x] + 2; 921 922 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 923 count[m_auiEoTable[edgeType]] ++; 924 m_iUpBuff1[x-1] = -signDown1; 925 926 } 927 m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]); 928 929 pRec += stride; 930 pOrg += stride; 931 } 932 933 //last line 934 if(pbBorderAvail[SGU_BL]) 935 { 936 x= 0; 937 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 938 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 939 count[m_auiEoTable[edgeType]] ++; 940 941 } 942 if(pbBorderAvail[SGU_B]) 943 { 944 for(x= 1; x< endX; x++) 945 { 946 edgeType = xSign(pRec[x] - pRec[x+ posShift]) + m_iUpBuff1[x] + 2; 947 stats[m_auiEoTable[edgeType]] += (pOrg[x] - pRec[x]); 948 count[m_auiEoTable[edgeType]] ++; 949 } 950 } 951 } 952 953 /** Calculate SAO statistics for current LCU 954 * \param iAddr, iPartIdx, iYCbCr 955 */ 956 Void TEncSampleAdaptiveOffset::calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr) 957 { 958 if(!m_bUseNIF) 959 { 960 calcSaoStatsCuOrg( iAddr, iPartIdx, iYCbCr); 961 } 962 else 963 { 964 Int64** ppStats = m_iOffsetOrg[iPartIdx]; 965 Int64** ppCount = m_iCount [iPartIdx]; 966 967 //parameters 968 Int isChroma = (iYCbCr != 0)? 1:0; 969 Int stride = (iYCbCr != 0)?(m_pcPic->getCStride()):(m_pcPic->getStride()); 970 Pel* pPicOrg = getPicYuvAddr (m_pcPic->getPicYuvOrg(), iYCbCr); 971 Pel* pPicRec = getPicYuvAddr(m_pcYuvTmp, iYCbCr); 972 973 std::vector<NDBFBlockInfo>& vFilterBlocks = *(m_pcPic->getCU(iAddr)->getNDBFilterBlocks()); 974 975 //variables 976 UInt xPos, yPos, width, height; 977 Bool* pbBorderAvail; 978 UInt posOffset; 979 980 for(Int i=0; i< vFilterBlocks.size(); i++) 981 { 982 xPos = vFilterBlocks[i].posX >> isChroma; 983 yPos = vFilterBlocks[i].posY >> isChroma; 984 width = vFilterBlocks[i].width >> isChroma; 985 height = vFilterBlocks[i].height >> isChroma; 986 pbBorderAvail = vFilterBlocks[i].isBorderAvailable; 987 988 posOffset = (yPos* stride) + xPos; 989 990 calcSaoStatsBlock(pPicRec+ posOffset, pPicOrg+ posOffset, stride, ppStats, ppCount,width, height, pbBorderAvail, iYCbCr); 991 } 992 } 993 994 } 995 996 /** Calculate SAO statistics for current LCU without non-crossing slice 997 * \param iAddr, iPartIdx, iYCbCr 998 */ 999 Void TEncSampleAdaptiveOffset::calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr) 1000 { 1001 Int x,y; 1002 TComDataCU *pTmpCu = m_pcPic->getCU(iAddr); 1003 TComSPS *pTmpSPS = m_pcPic->getSlice(0)->getSPS(); 1004 1005 Pel* pOrg; 1006 Pel* pRec; 1007 Int iStride; 1008 Int iLcuHeight = pTmpSPS->getMaxCUHeight(); 1009 Int iLcuWidth = pTmpSPS->getMaxCUWidth(); 1010 UInt uiLPelX = pTmpCu->getCUPelX(); 1011 UInt uiTPelY = pTmpCu->getCUPelY(); 1012 UInt uiRPelX; 1013 UInt uiBPelY; 1014 Int64* iStats; 1015 Int64* iCount; 1016 Int iClassIdx; 1017 Int iPicWidthTmp; 1018 Int iPicHeightTmp; 1019 Int iStartX; 1020 Int iStartY; 1021 Int iEndX; 1022 Int iEndY; 1023 Pel* pTableBo = (iYCbCr==0)?m_lumaTableBo:m_chromaTableBo; 1024 1025 Int iIsChroma = (iYCbCr!=0)? 1:0; 1026 Int numSkipLine = iIsChroma? 2:4; 1027 if (m_saoLcuBasedOptimization == 0) 1028 { 1029 numSkipLine = 0; 1030 } 1031 1032 Int numSkipLineRight = iIsChroma? 3:5; 1033 if (m_saoLcuBasedOptimization == 0) 1034 { 1035 numSkipLineRight = 0; 1036 } 1037 1038 iPicWidthTmp = m_iPicWidth >> iIsChroma; 1039 iPicHeightTmp = m_iPicHeight >> iIsChroma; 1040 iLcuWidth = iLcuWidth >> iIsChroma; 1041 iLcuHeight = iLcuHeight >> iIsChroma; 1042 uiLPelX = uiLPelX >> iIsChroma; 1043 uiTPelY = uiTPelY >> iIsChroma; 1044 uiRPelX = uiLPelX + iLcuWidth ; 1045 uiBPelY = uiTPelY + iLcuHeight ; 1046 uiRPelX = uiRPelX > iPicWidthTmp ? iPicWidthTmp : uiRPelX; 1047 uiBPelY = uiBPelY > iPicHeightTmp ? iPicHeightTmp : uiBPelY; 1048 iLcuWidth = uiRPelX - uiLPelX; 1049 iLcuHeight = uiBPelY - uiTPelY; 1050 1051 iStride = (iYCbCr == 0)? m_pcPic->getStride(): m_pcPic->getCStride(); 1052 1053 //if(iSaoType == BO_0 || iSaoType == BO_1) 1054 { 1055 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1056 { 1057 numSkipLine = iIsChroma? 1:3; 1058 numSkipLineRight = iIsChroma? 2:4; 1059 } 1060 iStats = m_iOffsetOrg[iPartIdx][SAO_BO]; 1061 iCount = m_iCount [iPartIdx][SAO_BO]; 1062 1063 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1064 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1065 1066 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight; 1067 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight : iLcuHeight-numSkipLine; 1068 for (y=0; y<iEndY; y++) 1069 { 1070 for (x=0; x<iEndX; x++) 1071 { 1072 iClassIdx = pTableBo[pRec[x]]; 1073 if (iClassIdx) 1074 { 1075 iStats[iClassIdx] += (pOrg[x] - pRec[x]); 1076 iCount[iClassIdx] ++; 1077 } 1078 } 1079 pOrg += iStride; 1080 pRec += iStride; 1081 } 1082 1083 } 1084 Int iSignLeft; 1085 Int iSignRight; 1086 Int iSignDown; 1087 Int iSignDown1; 1088 Int iSignDown2; 1089 1090 UInt uiEdgeType; 1091 1092 //if (iSaoType == EO_0 || iSaoType == EO_1 || iSaoType == EO_2 || iSaoType == EO_3) 1093 { 1094 //if (iSaoType == EO_0) 1095 { 1096 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1097 { 1098 numSkipLine = iIsChroma? 1:3; 1099 numSkipLineRight = iIsChroma? 3:5; 1100 } 1101 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_0]; 1102 iCount = m_iCount [iPartIdx][SAO_EO_0]; 1103 1104 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1105 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1106 1107 iStartX = (uiLPelX == 0) ? 1 : 0; 1108 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1109 for (y=0; y<iLcuHeight-numSkipLine; y++) 1110 { 1111 iSignLeft = xSign(pRec[iStartX] - pRec[iStartX-1]); 1112 for (x=iStartX; x< iEndX; x++) 1113 { 1114 iSignRight = xSign(pRec[x] - pRec[x+1]); 1115 uiEdgeType = iSignRight + iSignLeft + 2; 1116 iSignLeft = -iSignRight; 1117 1118 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1119 iCount[m_auiEoTable[uiEdgeType]] ++; 1120 } 1121 pOrg += iStride; 1122 pRec += iStride; 1123 } 1124 } 1125 1126 //if (iSaoType == EO_1) 1127 { 1128 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1129 { 1130 numSkipLine = iIsChroma? 2:4; 1131 numSkipLineRight = iIsChroma? 2:4; 1132 } 1133 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_1]; 1134 iCount = m_iCount [iPartIdx][SAO_EO_1]; 1135 1136 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1137 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1138 1139 iStartY = (uiTPelY == 0) ? 1 : 0; 1140 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth : iLcuWidth-numSkipLineRight; 1141 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1142 if (uiTPelY == 0) 1143 { 1144 pOrg += iStride; 1145 pRec += iStride; 1146 } 1147 1148 for (x=0; x< iLcuWidth; x++) 1149 { 1150 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride]); 1151 } 1152 for (y=iStartY; y<iEndY; y++) 1153 { 1154 for (x=0; x<iEndX; x++) 1155 { 1156 iSignDown = xSign(pRec[x] - pRec[x+iStride]); 1157 uiEdgeType = iSignDown + m_iUpBuff1[x] + 2; 1158 m_iUpBuff1[x] = -iSignDown; 1159 1160 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1161 iCount[m_auiEoTable[uiEdgeType]] ++; 1162 } 1163 pOrg += iStride; 1164 pRec += iStride; 1165 } 1166 } 1167 //if (iSaoType == EO_2) 1168 { 1169 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1170 { 1171 numSkipLine = iIsChroma? 2:4; 1172 numSkipLineRight = iIsChroma? 3:5; 1173 } 1174 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_2]; 1175 iCount = m_iCount [iPartIdx][SAO_EO_2]; 1176 1177 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1178 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1179 1180 iStartX = (uiLPelX == 0) ? 1 : 0; 1181 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1182 1183 iStartY = (uiTPelY == 0) ? 1 : 0; 1184 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1185 if (uiTPelY == 0) 1186 { 1187 pOrg += iStride; 1188 pRec += iStride; 1189 } 1190 1191 for (x=iStartX; x<iEndX; x++) 1192 { 1193 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride-1]); 1194 } 1195 for (y=iStartY; y<iEndY; y++) 1196 { 1197 iSignDown2 = xSign(pRec[iStride+iStartX] - pRec[iStartX-1]); 1198 for (x=iStartX; x<iEndX; x++) 1199 { 1200 iSignDown1 = xSign(pRec[x] - pRec[x+iStride+1]) ; 1201 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 1202 m_iUpBufft[x+1] = -iSignDown1; 1203 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1204 iCount[m_auiEoTable[uiEdgeType]] ++; 1205 } 1206 m_iUpBufft[iStartX] = iSignDown2; 1207 ipSwap = m_iUpBuff1; 1208 m_iUpBuff1 = m_iUpBufft; 1209 m_iUpBufft = ipSwap; 1210 1211 pRec += iStride; 1212 pOrg += iStride; 1213 } 1214 } 1215 //if (iSaoType == EO_3 ) 1216 { 1217 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ) 1218 { 1219 numSkipLine = iIsChroma? 2:4; 1220 numSkipLineRight = iIsChroma? 3:5; 1221 } 1222 iStats = m_iOffsetOrg[iPartIdx][SAO_EO_3]; 1223 iCount = m_iCount [iPartIdx][SAO_EO_3]; 1224 1225 pOrg = getPicYuvAddr(m_pcPic->getPicYuvOrg(), iYCbCr, iAddr); 1226 pRec = getPicYuvAddr(m_pcPic->getPicYuvRec(), iYCbCr, iAddr); 1227 1228 iStartX = (uiLPelX == 0) ? 1 : 0; 1229 iEndX = (uiRPelX == iPicWidthTmp) ? iLcuWidth-1 : iLcuWidth-numSkipLineRight; 1230 1231 iStartY = (uiTPelY == 0) ? 1 : 0; 1232 iEndY = (uiBPelY == iPicHeightTmp) ? iLcuHeight-1 : iLcuHeight-numSkipLine; 1233 if (iStartY == 1) 1234 { 1235 pOrg += iStride; 1236 pRec += iStride; 1237 } 1238 1239 for (x=iStartX-1; x<iEndX; x++) 1240 { 1241 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-iStride+1]); 1242 } 1243 1244 for (y=iStartY; y<iEndY; y++) 1245 { 1246 for (x=iStartX; x<iEndX; x++) 1247 { 1248 iSignDown1 = xSign(pRec[x] - pRec[x+iStride-1]) ; 1249 uiEdgeType = iSignDown1 + m_iUpBuff1[x] + 2; 1250 m_iUpBuff1[x-1] = -iSignDown1; 1251 iStats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1252 iCount[m_auiEoTable[uiEdgeType]] ++; 1253 } 1254 m_iUpBuff1[iEndX-1] = xSign(pRec[iEndX-1 + iStride] - pRec[iEndX]); 1255 1256 pRec += iStride; 1257 pOrg += iStride; 1258 } 1259 } 1260 } 1261 } 1262 1263 1264 Void TEncSampleAdaptiveOffset::calcSaoStatsCu_BeforeDblk( TComPic* pcPic ) 1265 { 1266 Int addr, yCbCr; 1267 Int x,y; 1268 TComSPS *pTmpSPS = pcPic->getSlice(0)->getSPS(); 1269 1270 Pel* pOrg; 1271 Pel* pRec; 1272 Int stride; 1273 Int lcuHeight = pTmpSPS->getMaxCUHeight(); 1274 Int lcuWidth = pTmpSPS->getMaxCUWidth(); 1275 UInt rPelX; 1276 UInt bPelY; 1277 Int64* stats; 1278 Int64* count; 1279 Int classIdx; 1280 Int picWidthTmp = 0; 1281 Int picHeightTmp = 0; 1282 Int startX; 1283 Int startY; 1284 Int endX; 1285 Int endY; 1286 Int firstX, firstY; 1287 1288 Int idxY; 1289 Int idxX; 1290 Int frameHeightInCU = m_iNumCuInHeight; 1291 Int frameWidthInCU = m_iNumCuInWidth; 1292 Int j, k; 1293 1294 Int isChroma; 1295 Int numSkipLine, numSkipLineRight; 1296 1297 UInt lPelX, tPelY; 1298 TComDataCU *pTmpCu; 1299 Pel* pTableBo; 1300 1301 for (idxY = 0; idxY< frameHeightInCU; idxY++) 1302 { 1303 for (idxX = 0; idxX< frameWidthInCU; idxX++) 1304 { 1305 lcuHeight = pTmpSPS->getMaxCUHeight(); 1306 lcuWidth = pTmpSPS->getMaxCUWidth(); 1307 addr = idxX + frameWidthInCU*idxY; 1308 pTmpCu = pcPic->getCU(addr); 1309 lPelX = pTmpCu->getCUPelX(); 1310 tPelY = pTmpCu->getCUPelY(); 1311 for( yCbCr = 0; yCbCr < 3; yCbCr++ ) 1312 { 1313 isChroma = (yCbCr!=0)? 1:0; 1314 1315 for ( j=0;j<MAX_NUM_SAO_TYPE;j++) 1316 { 1317 for ( k=0;k< MAX_NUM_SAO_CLASS;k++) 1318 { 1319 m_count_PreDblk [addr][yCbCr][j][k] = 0; 1320 m_offsetOrg_PreDblk[addr][yCbCr][j][k] = 0; 1321 } 1322 } 1323 if( yCbCr == 0 ) 1324 { 1325 picWidthTmp = m_iPicWidth; 1326 picHeightTmp = m_iPicHeight; 1327 } 1328 else if( yCbCr == 1 ) 1329 { 1330 picWidthTmp = m_iPicWidth >> isChroma; 1331 picHeightTmp = m_iPicHeight >> isChroma; 1332 lcuWidth = lcuWidth >> isChroma; 1333 lcuHeight = lcuHeight >> isChroma; 1334 lPelX = lPelX >> isChroma; 1335 tPelY = tPelY >> isChroma; 1336 } 1337 rPelX = lPelX + lcuWidth ; 1338 bPelY = tPelY + lcuHeight ; 1339 rPelX = rPelX > picWidthTmp ? picWidthTmp : rPelX; 1340 bPelY = bPelY > picHeightTmp ? picHeightTmp : bPelY; 1341 lcuWidth = rPelX - lPelX; 1342 lcuHeight = bPelY - tPelY; 1343 1344 stride = (yCbCr == 0)? pcPic->getStride(): pcPic->getCStride(); 1345 pTableBo = (yCbCr==0)?m_lumaTableBo:m_chromaTableBo; 1346 1347 //if(iSaoType == BO) 1348 1349 numSkipLine = isChroma? 1:3; 1350 numSkipLineRight = isChroma? 2:4; 1351 1352 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_BO]; 1353 count = m_count_PreDblk[addr][yCbCr][SAO_BO]; 1354 1355 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1356 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1357 1358 startX = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight; 1359 startY = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine; 1360 1361 for (y=0; y<lcuHeight; y++) 1362 { 1363 for (x=0; x<lcuWidth; x++) 1364 { 1365 if( x < startX && y < startY ) 1366 continue; 1367 1368 classIdx = pTableBo[pRec[x]]; 1369 if (classIdx) 1370 { 1371 stats[classIdx] += (pOrg[x] - pRec[x]); 1372 count[classIdx] ++; 1373 } 1374 } 1375 pOrg += stride; 1376 pRec += stride; 1377 } 1378 1379 Int signLeft; 1380 Int signRight; 1381 Int signDown; 1382 Int signDown1; 1383 Int signDown2; 1384 1385 UInt uiEdgeType; 1386 1387 //if (iSaoType == EO_0) 1388 1389 numSkipLine = isChroma? 1:3; 1390 numSkipLineRight = isChroma? 3:5; 1391 1392 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_0]; 1393 count = m_count_PreDblk[addr][yCbCr][SAO_EO_0]; 1394 1395 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1396 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1397 1398 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1399 startY = (bPelY == picHeightTmp) ? lcuHeight : lcuHeight-numSkipLine; 1400 firstX = (lPelX == 0) ? 1 : 0; 1401 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1402 1403 for (y=0; y<lcuHeight; y++) 1404 { 1405 signLeft = xSign(pRec[firstX] - pRec[firstX-1]); 1406 for (x=firstX; x< endX; x++) 1407 { 1408 signRight = xSign(pRec[x] - pRec[x+1]); 1409 uiEdgeType = signRight + signLeft + 2; 1410 signLeft = -signRight; 1411 1412 if( x < startX && y < startY ) 1413 continue; 1414 1415 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1416 count[m_auiEoTable[uiEdgeType]] ++; 1417 } 1418 pOrg += stride; 1419 pRec += stride; 1420 } 1421 1422 //if (iSaoType == EO_1) 1423 1424 numSkipLine = isChroma? 2:4; 1425 numSkipLineRight = isChroma? 2:4; 1426 1427 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_1]; 1428 count = m_count_PreDblk[addr][yCbCr][SAO_EO_1]; 1429 1430 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1431 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1432 1433 startX = (rPelX == picWidthTmp) ? lcuWidth : lcuWidth-numSkipLineRight; 1434 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1435 firstY = (tPelY == 0) ? 1 : 0; 1436 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1437 if (firstY == 1) 1438 { 1439 pOrg += stride; 1440 pRec += stride; 1441 } 1442 1443 for (x=0; x< lcuWidth; x++) 1444 { 1445 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride]); 1446 } 1447 for (y=firstY; y<endY; y++) 1448 { 1449 for (x=0; x<lcuWidth; x++) 1450 { 1451 signDown = xSign(pRec[x] - pRec[x+stride]); 1452 uiEdgeType = signDown + m_iUpBuff1[x] + 2; 1453 m_iUpBuff1[x] = -signDown; 1454 1455 if( x < startX && y < startY ) 1456 continue; 1457 1458 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1459 count[m_auiEoTable[uiEdgeType]] ++; 1460 } 1461 pOrg += stride; 1462 pRec += stride; 1463 } 1464 1465 //if (iSaoType == EO_2) 1466 1467 numSkipLine = isChroma? 2:4; 1468 numSkipLineRight = isChroma? 3:5; 1469 1470 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_2]; 1471 count = m_count_PreDblk[addr][yCbCr][SAO_EO_2]; 1472 1473 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1474 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1475 1476 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1477 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1478 firstX = (lPelX == 0) ? 1 : 0; 1479 firstY = (tPelY == 0) ? 1 : 0; 1480 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1481 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1482 if (firstY == 1) 1483 { 1484 pOrg += stride; 1485 pRec += stride; 1486 } 1487 1488 for (x=firstX; x<endX; x++) 1489 { 1490 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride-1]); 1491 } 1492 for (y=firstY; y<endY; y++) 1493 { 1494 signDown2 = xSign(pRec[stride+startX] - pRec[startX-1]); 1495 for (x=firstX; x<endX; x++) 1496 { 1497 signDown1 = xSign(pRec[x] - pRec[x+stride+1]) ; 1498 uiEdgeType = signDown1 + m_iUpBuff1[x] + 2; 1499 m_iUpBufft[x+1] = -signDown1; 1500 1501 if( x < startX && y < startY ) 1502 continue; 1503 1504 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1505 count[m_auiEoTable[uiEdgeType]] ++; 1506 } 1507 m_iUpBufft[firstX] = signDown2; 1508 ipSwap = m_iUpBuff1; 1509 m_iUpBuff1 = m_iUpBufft; 1510 m_iUpBufft = ipSwap; 1511 1512 pRec += stride; 1513 pOrg += stride; 1514 } 1515 1516 //if (iSaoType == EO_3) 1517 1518 numSkipLine = isChroma? 2:4; 1519 numSkipLineRight = isChroma? 3:5; 1520 1521 stats = m_offsetOrg_PreDblk[addr][yCbCr][SAO_EO_3]; 1522 count = m_count_PreDblk[addr][yCbCr][SAO_EO_3]; 1523 1524 pOrg = getPicYuvAddr(pcPic->getPicYuvOrg(), yCbCr, addr); 1525 pRec = getPicYuvAddr(pcPic->getPicYuvRec(), yCbCr, addr); 1526 1527 startX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth-numSkipLineRight; 1528 startY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight-numSkipLine; 1529 firstX = (lPelX == 0) ? 1 : 0; 1530 firstY = (tPelY == 0) ? 1 : 0; 1531 endX = (rPelX == picWidthTmp) ? lcuWidth-1 : lcuWidth; 1532 endY = (bPelY == picHeightTmp) ? lcuHeight-1 : lcuHeight; 1533 if (firstY == 1) 1534 { 1535 pOrg += stride; 1536 pRec += stride; 1537 } 1538 1539 for (x=firstX-1; x<endX; x++) 1540 { 1541 m_iUpBuff1[x] = xSign(pRec[x] - pRec[x-stride+1]); 1542 } 1543 1544 for (y=firstY; y<endY; y++) 1545 { 1546 for (x=firstX; x<endX; x++) 1547 { 1548 signDown1 = xSign(pRec[x] - pRec[x+stride-1]) ; 1549 uiEdgeType = signDown1 + m_iUpBuff1[x] + 2; 1550 m_iUpBuff1[x-1] = -signDown1; 1551 1552 if( x < startX && y < startY ) 1553 continue; 1554 1555 stats[m_auiEoTable[uiEdgeType]] += (pOrg[x] - pRec[x]); 1556 count[m_auiEoTable[uiEdgeType]] ++; 1557 } 1558 m_iUpBuff1[endX-1] = xSign(pRec[endX-1 + stride] - pRec[endX]); 1559 1560 pRec += stride; 1561 pOrg += stride; 1562 } 1563 } 1564 } 1565 } 1566 } 1567 1568 1569 /** get SAO statistics 1570 * \param *psQTPart, iYCbCr 1571 */ 1572 Void TEncSampleAdaptiveOffset::getSaoStats(SAOQTPart *psQTPart, Int iYCbCr) 1573 { 1574 Int iLevelIdx, iPartIdx, iTypeIdx, iClassIdx; 1575 Int i; 1576 Int iNumTotalType = MAX_NUM_SAO_TYPE; 1577 Int LcuIdxX; 1578 Int LcuIdxY; 1579 Int iAddr; 1580 Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU(); 1581 Int iDownPartIdx; 1582 Int iPartStart; 1583 Int iPartEnd; 1584 SAOQTPart* pOnePart; 1585 1586 if (m_uiMaxSplitLevel == 0) 1587 { 1588 iPartIdx = 0; 1589 pOnePart = &(psQTPart[iPartIdx]); 1590 for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++) 1591 { 1592 for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++) 1593 { 1594 iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX; 1595 calcSaoStatsCu(iAddr, iPartIdx, iYCbCr); 1596 } 1597 } 1598 } 1599 else 1600 { 1601 for(iPartIdx=m_aiNumCulPartsLevel[m_uiMaxSplitLevel-1]; iPartIdx<m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; iPartIdx++) 1602 { 1603 pOnePart = &(psQTPart[iPartIdx]); 1604 for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++) 1605 { 1606 for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++) 1607 { 1608 iAddr = LcuIdxY*iFrameWidthInCU + LcuIdxX; 1609 calcSaoStatsCu(iAddr, iPartIdx, iYCbCr); 1610 } 1611 } 1612 } 1613 for (iLevelIdx = m_uiMaxSplitLevel-1; iLevelIdx>=0; iLevelIdx-- ) 1614 { 1615 iPartStart = (iLevelIdx > 0) ? m_aiNumCulPartsLevel[iLevelIdx-1] : 0; 1616 iPartEnd = m_aiNumCulPartsLevel[iLevelIdx]; 1617 1618 for(iPartIdx = iPartStart; iPartIdx < iPartEnd; iPartIdx++) 1619 { 1620 pOnePart = &(psQTPart[iPartIdx]); 1621 for (i=0; i< NUM_DOWN_PART; i++) 1622 { 1623 iDownPartIdx = pOnePart->DownPartsIdx[i]; 1624 for (iTypeIdx=0; iTypeIdx<iNumTotalType; iTypeIdx++) 1625 { 1626 for (iClassIdx=0; iClassIdx< (iTypeIdx < SAO_BO ? m_iNumClass[iTypeIdx] : SAO_MAX_BO_CLASSES) +1; iClassIdx++) 1627 { 1628 m_iOffsetOrg[iPartIdx][iTypeIdx][iClassIdx] += m_iOffsetOrg[iDownPartIdx][iTypeIdx][iClassIdx]; 1629 m_iCount [iPartIdx][iTypeIdx][iClassIdx] += m_iCount [iDownPartIdx][iTypeIdx][iClassIdx]; 1630 } 1631 } 1632 } 1633 } 1634 } 1635 } 1636 } 1637 1638 /** reset offset statistics 1639 * \param 1640 */ 1641 Void TEncSampleAdaptiveOffset::resetStats() 1642 { 1643 for (Int i=0;i<m_iNumTotalParts;i++) 1644 { 1645 m_dCostPartBest[i] = MAX_DOUBLE; 1646 m_iTypePartBest[i] = -1; 1647 m_iDistOrg[i] = 0; 1648 for (Int j=0;j<MAX_NUM_SAO_TYPE;j++) 1649 { 1650 m_iDist[i][j] = 0; 1651 m_iRate[i][j] = 0; 1652 m_dCost[i][j] = 0; 1653 for (Int k=0;k<MAX_NUM_SAO_CLASS;k++) 1654 { 1655 m_iCount [i][j][k] = 0; 1656 m_iOffset[i][j][k] = 0; 1657 m_iOffsetOrg[i][j][k] = 0; 1658 } 1659 } 1660 } 1661 } 1662 1663 #if SAO_CHROMA_LAMBDA 1664 /** Sample adaptive offset process 1665 * \param pcSaoParam 1666 * \param dLambdaLuma 1667 * \param dLambdaChroma 1668 */ 1669 #if SAO_ENCODING_CHOICE 1670 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma, Int depth) 1671 #else 1672 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma) 1673 #endif 1674 #else 1675 /** Sample adaptive offset process 1676 * \param dLambda 1677 */ 1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda) 1679 #endif 1680 { 1681 if(m_bUseNIF) 1682 { 1683 m_pcPic->getPicYuvRec()->copyToPic(m_pcYuvTmp); 1684 } 1685 1686 m_uiSaoBitIncreaseY = max(g_bitDepthY - 10, 0); 1687 m_uiSaoBitIncreaseC = max(g_bitDepthC - 10, 0); 1688 m_iOffsetThY = 1 << min(g_bitDepthY - 5, 5); 1689 m_iOffsetThC = 1 << min(g_bitDepthC - 5, 5); 1690 resetSAOParam(pcSaoParam); 1691 if( !m_saoLcuBasedOptimization || !m_saoLcuBoundary ) 1692 { 1693 resetStats(); 1694 } 1695 Double dCostFinal = 0; 1696 if ( m_saoLcuBasedOptimization) 1697 { 1698 #if SAO_ENCODING_CHOICE 1699 rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma, depth); 1700 #else 1701 rdoSaoUnitAll(pcSaoParam, dLambdaLuma, dLambdaChroma); 1702 #endif 1703 } 1704 else 1705 { 1706 pcSaoParam->bSaoFlag[0] = 1; 1707 pcSaoParam->bSaoFlag[1] = 0; 1708 dCostFinal = 0; 1709 Double lambdaRdo = dLambdaLuma; 1710 resetStats(); 1711 getSaoStats(pcSaoParam->psSaoPart[0], 0); 1712 runQuadTreeDecision(pcSaoParam->psSaoPart[0], 0, dCostFinal, m_uiMaxSplitLevel, lambdaRdo, 0); 1713 pcSaoParam->bSaoFlag[0] = dCostFinal < 0 ? 1:0; 1714 if(pcSaoParam->bSaoFlag[0]) 1715 { 1716 convertQT2SaoUnit(pcSaoParam, 0, 0); 1717 assignSaoUnitSyntax(pcSaoParam->saoLcuParam[0], pcSaoParam->psSaoPart[0], pcSaoParam->oneUnitFlag[0], 0); 1718 } 1719 } 1720 if (pcSaoParam->bSaoFlag[0]) 1721 { 1722 processSaoUnitAll( pcSaoParam->saoLcuParam[0], pcSaoParam->oneUnitFlag[0], 0); 1723 } 1724 if (pcSaoParam->bSaoFlag[1]) 1725 { 1726 processSaoUnitAll( pcSaoParam->saoLcuParam[1], pcSaoParam->oneUnitFlag[1], 1); 1727 processSaoUnitAll( pcSaoParam->saoLcuParam[2], pcSaoParam->oneUnitFlag[2], 2); 1728 } 1729 } 1730 /** Check merge SAO unit 1731 * \param saoUnitCurr current SAO unit 1732 * \param saoUnitCheck SAO unit tobe check 1733 * \param dir direction 1734 */ 1735 Void TEncSampleAdaptiveOffset::checkMerge(SaoLcuParam * saoUnitCurr, SaoLcuParam * saoUnitCheck, Int dir) 1736 { 1737 Int i ; 1738 Int countDiff = 0; 1739 if (saoUnitCurr->partIdx != saoUnitCheck->partIdx) 1740 { 1741 if (saoUnitCurr->typeIdx !=-1) 1742 { 1743 if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx) 1744 { 1745 for (i=0;i<saoUnitCurr->length;i++) 1746 { 1747 countDiff += (saoUnitCurr->offset[i] != saoUnitCheck->offset[i]); 1748 } 1749 countDiff += (saoUnitCurr->subTypeIdx != saoUnitCheck->subTypeIdx); 1750 if (countDiff ==0) 1751 { 1752 saoUnitCurr->partIdx = saoUnitCheck->partIdx; 1753 if (dir == 1) 1754 { 1755 saoUnitCurr->mergeUpFlag = 1; 1756 saoUnitCurr->mergeLeftFlag = 0; 1757 } 1758 else 1759 { 1760 saoUnitCurr->mergeUpFlag = 0; 1761 saoUnitCurr->mergeLeftFlag = 1; 1762 } 1763 } 1764 } 1765 } 1766 else 1767 { 1768 if (saoUnitCurr->typeIdx == saoUnitCheck->typeIdx) 1769 { 1770 saoUnitCurr->partIdx = saoUnitCheck->partIdx; 1771 if (dir == 1) 1772 { 1773 saoUnitCurr->mergeUpFlag = 1; 1774 saoUnitCurr->mergeLeftFlag = 0; 1775 } 1776 else 1777 { 1778 saoUnitCurr->mergeUpFlag = 0; 1779 saoUnitCurr->mergeLeftFlag = 1; 1780 } 1781 } 1782 } 1783 } 1784 } 1785 /** Assign SAO unit syntax from picture-based algorithm 1786 * \param saoLcuParam SAO LCU parameters 1787 * \param saoPart SAO part 1788 * \param oneUnitFlag SAO one unit flag 1789 * \param iYCbCr color component Index 1790 */ 1791 Void TEncSampleAdaptiveOffset::assignSaoUnitSyntax(SaoLcuParam* saoLcuParam, SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr) 1792 { 1793 if (saoPart->bSplit == 0) 1794 { 1795 oneUnitFlag = 1; 1796 } 1797 else 1798 { 1799 Int i,j, addr, addrUp, addrLeft, idx, idxUp, idxLeft, idxCount; 1800 1801 oneUnitFlag = 0; 1802 1803 idxCount = -1; 1804 saoLcuParam[0].mergeUpFlag = 0; 1805 saoLcuParam[0].mergeLeftFlag = 0; 1806 1807 for (j=0;j<m_iNumCuInHeight;j++) 1808 { 1809 for (i=0;i<m_iNumCuInWidth;i++) 1810 { 1811 addr = i + j*m_iNumCuInWidth; 1812 addrLeft = (addr%m_iNumCuInWidth == 0) ? -1 : addr - 1; 1813 addrUp = (addr<m_iNumCuInWidth) ? -1 : addr - m_iNumCuInWidth; 1814 idx = saoLcuParam[addr].partIdxTmp; 1815 idxLeft = (addrLeft == -1) ? -1 : saoLcuParam[addrLeft].partIdxTmp; 1816 idxUp = (addrUp == -1) ? -1 : saoLcuParam[addrUp].partIdxTmp; 1817 1818 if(idx!=idxLeft && idx!=idxUp) 1819 { 1820 saoLcuParam[addr].mergeUpFlag = 0; idxCount++; 1821 saoLcuParam[addr].mergeLeftFlag = 0; 1822 saoLcuParam[addr].partIdx = idxCount; 1823 } 1824 else if (idx==idxLeft) 1825 { 1826 saoLcuParam[addr].mergeUpFlag = 1; 1827 saoLcuParam[addr].mergeLeftFlag = 1; 1828 saoLcuParam[addr].partIdx = saoLcuParam[addrLeft].partIdx; 1829 } 1830 else if (idx==idxUp) 1831 { 1832 saoLcuParam[addr].mergeUpFlag = 1; 1833 saoLcuParam[addr].mergeLeftFlag = 0; 1834 saoLcuParam[addr].partIdx = saoLcuParam[addrUp].partIdx; 1835 } 1836 if (addrUp != -1) 1837 { 1838 checkMerge(&saoLcuParam[addr], &saoLcuParam[addrUp], 1); 1839 } 1840 if (addrLeft != -1) 1841 { 1842 checkMerge(&saoLcuParam[addr], &saoLcuParam[addrLeft], 0); 1843 } 1844 } 1845 } 1846 } 1847 } 1848 /** rate distortion optimization of all SAO units 1849 * \param saoParam SAO parameters 1850 * \param lambda 1851 * \param lambdaChroma 1852 */ 1853 #if SAO_ENCODING_CHOICE 1854 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth) 1855 #else 1856 Void TEncSampleAdaptiveOffset::rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma) 1857 #endif 1858 { 1859 1860 Int idxY; 1861 Int idxX; 1862 Int frameHeightInCU = saoParam->numCuInHeight; 1863 Int frameWidthInCU = saoParam->numCuInWidth; 1864 Int j, k; 1865 Int addr = 0; 1866 Int addrUp = -1; 1867 Int addrLeft = -1; 1868 Int compIdx = 0; 1869 SaoLcuParam mergeSaoParam[3][2]; 1870 Double compDistortion[3]; 1871 1872 saoParam->bSaoFlag[0] = true; 1873 saoParam->bSaoFlag[1] = true; 1874 saoParam->oneUnitFlag[0] = false; 1875 saoParam->oneUnitFlag[1] = false; 1876 saoParam->oneUnitFlag[2] = false; 242 m_pcRDGoOnSbacCoder->setSlice(pcSlice); 243 m_pcRDGoOnSbacCoder->resetEntropy(); 244 m_pcRDGoOnSbacCoder->resetBits(); 245 246 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]); 247 } 248 249 250 251 Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 252 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 253 , Bool isPreDBFSamplesUsed 254 #endif 255 ) 256 { 257 TComPicYuv* orgYuv= pPic->getPicYuvOrg(); 258 TComPicYuv* resYuv= pPic->getPicYuvRec(); 259 m_lambda[SAO_Y]= lambdas[0]; m_lambda[SAO_Cb]= lambdas[1]; m_lambda[SAO_Cr]= lambdas[2]; 260 TComPicYuv* srcYuv = m_tempPicYuv; 261 resYuv->copyToPic(srcYuv); 262 srcYuv->setBorderExtension(false); 263 srcYuv->extendPicBorder(); 264 265 //collect statistics 266 getStatistics(m_statData, orgYuv, srcYuv, pPic); 267 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 268 if(isPreDBFSamplesUsed) 269 { 270 addPreDBFStatistics(m_statData); 271 } 272 #endif 273 //slice on/off 274 decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth()); 275 276 //block on/off 277 SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters 278 decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam()); 279 delete[] reconParams; 280 281 } 282 283 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 284 Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic) 285 { 286 getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true); 287 } 288 289 Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats) 290 { 291 for(Int n=0; n< m_numCTUsPic; n++) 292 { 293 for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++) 294 { 295 for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++) 296 { 297 blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc]; 298 } 299 } 300 } 301 } 302 303 #endif 304 305 Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic 306 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 307 , Bool isCalculatePreDeblockSamples 308 #endif 309 ) 310 { 311 Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail; 312 313 for(Int ctu= 0; ctu < m_numCTUsPic; ctu++) 314 { 315 Int yPos = (ctu / m_numCTUInWidth)*m_maxCUHeight; 316 Int xPos = (ctu % m_numCTUInWidth)*m_maxCUWidth; 317 Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight; 318 Int width = (xPos + m_maxCUWidth > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth; 319 320 pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail); 321 322 //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities. 323 //For simplicity, here only picture boundaries are considered. 324 325 isRightAvail = (xPos + m_maxCUWidth < m_picWidth ); 326 isBelowAvail = (yPos + m_maxCUHeight < m_picHeight); 327 isBelowRightAvail = (isRightAvail && isBelowAvail); 328 isBelowLeftAvail = ((xPos > 0) && (isBelowAvail)); 329 isAboveRightAvail = ((yPos > 0) && (isRightAvail)); 330 331 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 332 { 333 Bool isLuma = (compIdx == SAO_Y); 334 Int formatShift= isLuma?0:1; 335 336 Int srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride(); 337 Pel* srcBlk = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift); 338 339 Int orgStride = isLuma?orgYuv->getStride():orgYuv->getCStride(); 340 Pel* orgBlk = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift); 341 342 getBlkStats(compIdx, blkStats[ctu][compIdx] 343 , srcBlk, orgBlk, srcStride, orgStride, (width >> formatShift), (height >> formatShift) 344 , isLeftAvail, isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail 345 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 346 , isCalculatePreDeblockSamples 347 #endif 348 ); 349 350 } 351 } 352 } 353 354 Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer) 355 { 356 //decide sliceEnabled[compIdx] 357 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 358 { 359 // reset flags & counters 360 sliceEnabled[compIdx] = true; 1877 361 1878 362 #if SAO_ENCODING_CHOICE 1879 363 #if SAO_ENCODING_CHOICE_CHROMA 1880 Int numNoSao[2]; 1881 numNoSao[0] = 0;// Luma 1882 numNoSao[1] = 0;// Chroma 1883 if( depth > 0 && m_depthSaoRate[0][depth-1] > SAO_ENCODING_RATE ) 1884 { 1885 saoParam->bSaoFlag[0] = false; 1886 } 1887 if( depth > 0 && m_depthSaoRate[1][depth-1] > SAO_ENCODING_RATE_CHROMA ) 1888 { 1889 saoParam->bSaoFlag[1] = false; 1890 } 1891 #else 1892 Int numNoSao = 0; 1893 1894 if( depth > 0 && m_depth0SaoRate > SAO_ENCODING_RATE ) 1895 { 1896 saoParam->bSaoFlag[0] = false; 1897 saoParam->bSaoFlag[1] = false; 1898 } 1899 #endif 1900 #endif 1901 1902 for (idxY = 0; idxY< frameHeightInCU; idxY++) 1903 { 1904 for (idxX = 0; idxX< frameWidthInCU; idxX++) 1905 { 1906 addr = idxX + frameWidthInCU*idxY; 1907 addrUp = addr < frameWidthInCU ? -1:idxX + frameWidthInCU*(idxY-1); 1908 addrLeft = idxX == 0 ? -1:idxX-1 + frameWidthInCU*idxY; 1909 Int allowMergeLeft = 1; 1910 Int allowMergeUp = 1; 1911 UInt rate; 1912 Double bestCost, mergeCost; 1913 if (idxX!=0) 1914 { 1915 // check tile id and slice id 1916 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-1) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-1)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 1917 { 1918 allowMergeLeft = 0; 1919 } 1920 } 1921 else 1922 { 1923 allowMergeLeft = 0; 1924 } 1925 if (idxY!=0) 1926 { 1927 if ( (m_pcPic->getPicSym()->getTileIdxMap(addr-m_iNumCuInWidth) != m_pcPic->getPicSym()->getTileIdxMap(addr)) || (m_pcPic->getCU(addr-m_iNumCuInWidth)->getSlice()->getSliceIdx() != m_pcPic->getCU(addr)->getSlice()->getSliceIdx())) 1928 { 1929 allowMergeUp = 0; 1930 } 1931 } 1932 else 1933 { 1934 allowMergeUp = 0; 1935 } 1936 1937 compDistortion[0] = 0; 1938 compDistortion[1] = 0; 1939 compDistortion[2] = 0; 1940 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1941 if (allowMergeLeft) 1942 { 1943 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1944 } 1945 if (allowMergeUp) 1946 { 1947 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1948 } 1949 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 1950 // reset stats Y, Cb, Cr 1951 for ( compIdx=0;compIdx<3;compIdx++) 1952 { 1953 for ( j=0;j<MAX_NUM_SAO_TYPE;j++) 1954 { 1955 for ( k=0;k< MAX_NUM_SAO_CLASS;k++) 1956 { 1957 m_iOffset [compIdx][j][k] = 0; 1958 if( m_saoLcuBasedOptimization && m_saoLcuBoundary ){ 1959 m_iCount [compIdx][j][k] = m_count_PreDblk [addr][compIdx][j][k]; 1960 m_iOffsetOrg[compIdx][j][k] = m_offsetOrg_PreDblk[addr][compIdx][j][k]; 1961 } 1962 else 1963 { 1964 m_iCount [compIdx][j][k] = 0; 1965 m_iOffsetOrg[compIdx][j][k] = 0; 1966 } 1967 } 1968 } 1969 saoParam->saoLcuParam[compIdx][addr].typeIdx = -1; 1970 saoParam->saoLcuParam[compIdx][addr].mergeUpFlag = 0; 1971 saoParam->saoLcuParam[compIdx][addr].mergeLeftFlag = 0; 1972 saoParam->saoLcuParam[compIdx][addr].subTypeIdx = 0; 1973 #if SAO_ENCODING_CHOICE 1974 if( (compIdx ==0 && saoParam->bSaoFlag[0])|| (compIdx >0 && saoParam->bSaoFlag[1]) ) 1975 #endif 1976 { 1977 calcSaoStatsCu(addr, compIdx, compIdx); 1978 1979 } 1980 } 1981 saoComponentParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, 0, lambda, &mergeSaoParam[0][0], &compDistortion[0]); 1982 sao2ChromaParamDist(allowMergeLeft, allowMergeUp, saoParam, addr, addrUp, addrLeft, lambdaChroma, &mergeSaoParam[1][0], &mergeSaoParam[2][0], &compDistortion[0]); 1983 if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] ) 1984 { 1985 // Cost of new SAO_params 1986 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1987 m_pcRDGoOnSbacCoder->resetBits(); 1988 if (allowMergeLeft) 1989 { 1990 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1991 } 1992 if (allowMergeUp) 1993 { 1994 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(0); 1995 } 1996 for ( compIdx=0;compIdx<3;compIdx++) 1997 { 1998 if( (compIdx ==0 && saoParam->bSaoFlag[0]) || (compIdx >0 && saoParam->bSaoFlag[1])) 1999 { 2000 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx); 2001 } 2002 } 2003 2004 rate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2005 bestCost = compDistortion[0] + (Double)rate; 2006 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2007 2008 // Cost of Merge 2009 for(Int mergeUp=0; mergeUp<2; ++mergeUp) 2010 { 2011 if ( (allowMergeLeft && (mergeUp==0)) || (allowMergeUp && (mergeUp==1)) ) 2012 { 2013 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 2014 m_pcRDGoOnSbacCoder->resetBits(); 2015 if (allowMergeLeft) 2016 { 2017 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1-mergeUp); 2018 } 2019 if ( allowMergeUp && (mergeUp==1) ) 2020 { 2021 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(1); 2022 } 2023 2024 rate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2025 mergeCost = compDistortion[mergeUp+1] + (Double)rate; 2026 if (mergeCost < bestCost) 2027 { 2028 bestCost = mergeCost; 2029 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2030 for ( compIdx=0;compIdx<3;compIdx++) 2031 { 2032 mergeSaoParam[compIdx][mergeUp].mergeLeftFlag = 1-mergeUp; 2033 mergeSaoParam[compIdx][mergeUp].mergeUpFlag = mergeUp; 2034 if( (compIdx==0 && saoParam->bSaoFlag[0]) || (compIdx>0 && saoParam->bSaoFlag[1])) 2035 { 2036 copySaoUnit(&saoParam->saoLcuParam[compIdx][addr], &mergeSaoParam[compIdx][mergeUp] ); 2037 } 2038 } 2039 } 2040 } 2041 } 2042 #if SAO_ENCODING_CHOICE 2043 #if SAO_ENCODING_CHOICE_CHROMA 2044 if( saoParam->saoLcuParam[0][addr].typeIdx == -1) 2045 { 2046 numNoSao[0]++; 2047 } 2048 if( saoParam->saoLcuParam[1][addr].typeIdx == -1) 2049 { 2050 numNoSao[1]+=2; 2051 } 2052 #else 2053 for ( compIdx=0;compIdx<3;compIdx++) 2054 { 2055 if( depth == 0 && saoParam->saoLcuParam[compIdx][addr].typeIdx == -1) 2056 { 2057 numNoSao++; 2058 } 2059 } 2060 #endif 2061 #endif 2062 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2063 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 2064 } 2065 } 2066 } 2067 #if SAO_ENCODING_CHOICE 2068 #if SAO_ENCODING_CHOICE_CHROMA 2069 if( !saoParam->bSaoFlag[0]) 2070 { 2071 m_depthSaoRate[0][depth] = 1.0; 2072 } 2073 else 2074 { 2075 m_depthSaoRate[0][depth] = numNoSao[0]/((Double) frameHeightInCU*frameWidthInCU); 2076 } 2077 if( !saoParam->bSaoFlag[1]) 2078 { 2079 m_depthSaoRate[1][depth] = 1.0; 2080 } 2081 else 2082 { 2083 m_depthSaoRate[1][depth] = numNoSao[1]/((Double) frameHeightInCU*frameWidthInCU*2); 2084 } 2085 #else 2086 if( depth == 0) 2087 { 2088 // update SAO Rate 2089 m_depth0SaoRate = numNoSao/((Double) frameHeightInCU*frameWidthInCU*3); 2090 } 2091 #endif 2092 #endif 2093 2094 } 2095 /** rate distortion optimization of SAO unit 2096 * \param saoParam SAO parameters 2097 * \param addr address 2098 * \param addrUp above address 2099 * \param addrLeft left address 2100 * \param yCbCr color component index 2101 * \param lambda 2102 */ 2103 inline Int64 TEncSampleAdaptiveOffset::estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo) 2104 { 2105 Int64 estDist = 0; 2106 Int classIdx; 2107 Int bitDepth = (compIdx==0) ? g_bitDepthY : g_bitDepthC; 2108 Int saoBitIncrease = (compIdx==0) ? m_uiSaoBitIncreaseY : m_uiSaoBitIncreaseC; 2109 Int saoOffsetTh = (compIdx==0) ? m_iOffsetThY : m_iOffsetThC; 2110 2111 for(classIdx=1; classIdx < ( (typeIdx < SAO_BO) ? m_iNumClass[typeIdx]+1 : SAO_MAX_BO_CLASSES+1); classIdx++) 2112 { 2113 if( typeIdx == SAO_BO) 2114 { 2115 currentDistortionTableBo[classIdx-1] = 0; 2116 currentRdCostTableBo[classIdx-1] = lambda; 2117 } 2118 if(m_iCount [compIdx][typeIdx][classIdx]) 2119 { 2120 m_iOffset[compIdx][typeIdx][classIdx] = (Int64) xRoundIbdi(bitDepth, (Double)(m_iOffsetOrg[compIdx][typeIdx][classIdx]<<(bitDepth-8)) / (Double)(m_iCount [compIdx][typeIdx][classIdx]<<saoBitIncrease)); 2121 m_iOffset[compIdx][typeIdx][classIdx] = Clip3(-saoOffsetTh+1, saoOffsetTh-1, (Int)m_iOffset[compIdx][typeIdx][classIdx]); 2122 if (typeIdx < 4) 2123 { 2124 if ( m_iOffset[compIdx][typeIdx][classIdx]<0 && classIdx<3 ) 2125 { 2126 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2127 } 2128 if ( m_iOffset[compIdx][typeIdx][classIdx]>0 && classIdx>=3) 2129 { 2130 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2131 } 2132 } 2133 m_iOffset[compIdx][typeIdx][classIdx] = estIterOffset( typeIdx, classIdx, lambda, m_iOffset[compIdx][typeIdx][classIdx], m_iCount [compIdx][typeIdx][classIdx], m_iOffsetOrg[compIdx][typeIdx][classIdx], shift, saoBitIncrease, currentDistortionTableBo, currentRdCostTableBo, saoOffsetTh ); 2134 } 2135 else 2136 { 2137 m_iOffsetOrg[compIdx][typeIdx][classIdx] = 0; 2138 m_iOffset[compIdx][typeIdx][classIdx] = 0; 2139 } 2140 if( typeIdx != SAO_BO ) 2141 { 2142 estDist += estSaoDist( m_iCount [compIdx][typeIdx][classIdx], m_iOffset[compIdx][typeIdx][classIdx] << saoBitIncrease, m_iOffsetOrg[compIdx][typeIdx][classIdx], shift); 2143 } 2144 2145 } 2146 return estDist; 2147 } 2148 2149 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift) 2150 { 2151 return (( count*offset*offset-offsetOrg*offset*2 ) >> shift); 2152 } 2153 inline Int64 TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh ) 2154 { 2155 //Clean up, best_q_offset. 2156 Int64 iterOffset, tempOffset; 364 // decide slice-level on/off based on previous results 365 if( (picTempLayer > 0) 366 && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) ) 367 { 368 sliceEnabled[compIdx] = false; 369 } 370 #else 371 // decide slice-level on/off based on previous results 372 if( (picTempLayer > 0) 373 && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) ) 374 { 375 sliceEnabled[compIdx] = false; 376 } 377 #endif 378 #endif 379 } 380 } 381 382 Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData) 383 { 384 Int64 dist=0; 385 Int inputBitDepth = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ; 386 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8); 387 388 switch(typeIdc) 389 { 390 case SAO_TYPE_EO_0: 391 case SAO_TYPE_EO_90: 392 case SAO_TYPE_EO_135: 393 case SAO_TYPE_EO_45: 394 { 395 for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++) 396 { 397 dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift); 398 } 399 } 400 break; 401 case SAO_TYPE_BO: 402 { 403 for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++) 404 { 405 Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ; 406 dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift); 407 } 408 } 409 break; 410 default: 411 { 412 printf("Not a supported type"); 413 assert(0); 414 exit(-1); 415 } 416 } 417 418 return dist; 419 } 420 421 inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift) 422 { 423 return (( count*offset*offset-diffSum*offset*2 ) >> shift); 424 } 425 426 427 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 ) 428 { 429 Int iterOffset, tempOffset; 2157 430 Int64 tempDist, tempRate; 2158 431 Double tempCost, tempMinCost; 2159 Int 64offsetOutput = 0;432 Int offsetOutput = 0; 2160 433 iterOffset = offsetInput; 2161 434 // 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. … … 2163 436 while (iterOffset != 0) 2164 437 { 2165 // Calculate the bits required for signal ling the offset2166 tempRate = (typeIdx == SAO_ BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);2167 if (abs((Int)iterOffset)==offsetTh -1)438 // Calculate the bits required for signaling the offset 439 tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1); 440 if (abs((Int)iterOffset)==offsetTh) //inclusive 2168 441 { 2169 442 tempRate --; 2170 443 } 2171 // Do the dequ ntization before distorion calculation444 // Do the dequantization before distortion calculation 2172 445 tempOffset = iterOffset << bitIncrease; 2173 tempDist = estSaoDist( count, tempOffset, offsetOrg, shift);446 tempDist = estSaoDist( count, tempOffset, diffSum, shift); 2174 447 tempCost = ((Double)tempDist + lambda * (Double) tempRate); 2175 448 if(tempCost < tempMinCost) … … 2177 450 tempMinCost = tempCost; 2178 451 offsetOutput = iterOffset; 2179 if(typeIdx == SAO_BO) 2180 { 2181 currentDistortionTableBo[classIdx-1] = (Int) tempDist; 2182 currentRdCostTableBo[classIdx-1] = tempCost; 2183 } 452 bestDist = tempDist; 453 bestCost = tempCost; 2184 454 } 2185 455 iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1); … … 2189 459 2190 460 2191 Void TEncSampleAdaptiveOffset::saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *compDistortion) 2192 { 2193 Int typeIdx; 2194 2195 Int64 estDist; 2196 Int classIdx; 2197 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(((yCbCr==0)?g_bitDepthY:g_bitDepthC)-8); 2198 Int64 bestDist; 2199 2200 SaoLcuParam* saoLcuParam = &(saoParam->saoLcuParam[yCbCr][addr]); 2201 SaoLcuParam* saoLcuParamNeighbor = NULL; 2202 2203 resetSaoUnit(saoLcuParam); 2204 resetSaoUnit(&compSaoParam[0]); 2205 resetSaoUnit(&compSaoParam[1]); 2206 2207 2208 Double dCostPartBest = MAX_DOUBLE; 2209 2210 Double bestRDCostTableBo = MAX_DOUBLE; 2211 Int bestClassTableBo = 0; 2212 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 2213 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 2214 2215 2216 SaoLcuParam saoLcuParamRdo; 2217 Double estRate = 0; 2218 2219 resetSaoUnit(&saoLcuParamRdo); 2220 2221 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 461 Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo) 462 { 463 Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC; 464 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8); 465 Int offsetTh = g_saoMaxOffsetQVal[compIdx]; //inclusive 466 467 ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES); 468 469 //derive initial offsets 470 Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES); 471 for(Int classIdx=0; classIdx< numClasses; classIdx++) 472 { 473 if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN) ) 474 { 475 continue; //offset will be zero 476 } 477 478 if(statData.count[classIdx] == 0) 479 { 480 continue; //offset will be zero 481 } 482 483 quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8)) 484 / 485 (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx]) 486 ); 487 quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]); 488 } 489 490 // adjust offsets 491 switch(typeIdc) 492 { 493 case SAO_TYPE_EO_0: 494 case SAO_TYPE_EO_90: 495 case SAO_TYPE_EO_135: 496 case SAO_TYPE_EO_45: 497 { 498 Int64 classDist; 499 Double classCost; 500 for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 501 { 502 if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 503 if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0; 504 if(classIdx==SAO_CLASS_EO_HALF_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 505 if(classIdx==SAO_CLASS_EO_FULL_PEAK && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0; 506 507 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 508 { 509 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh ); 510 } 511 } 512 513 typeAuxInfo =0; 514 } 515 break; 516 case SAO_TYPE_BO: 517 { 518 Int64 distBOClasses[NUM_SAO_BO_CLASSES]; 519 Double costBOClasses[NUM_SAO_BO_CLASSES]; 520 ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES); 521 for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++) 522 { 523 costBOClasses[classIdx]= m_lambda[compIdx]; 524 if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero 525 { 526 quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_lambda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh ); 527 } 528 } 529 530 //decide the starting band index 531 Double minCost = MAX_DOUBLE, cost; 532 for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++) 533 { 534 cost = costBOClasses[band ]; 535 cost += costBOClasses[band+1]; 536 cost += costBOClasses[band+2]; 537 cost += costBOClasses[band+3]; 538 539 if(cost < minCost) 540 { 541 minCost = cost; 542 typeAuxInfo = band; 543 } 544 } 545 //clear those unused classes 546 Int clearQuantOffset[NUM_SAO_BO_CLASSES]; 547 ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES); 548 for(Int i=0; i< 4; i++) 549 { 550 Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES; 551 clearQuantOffset[band] = quantOffsets[band]; 552 } 553 ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES); 554 } 555 break; 556 default: 557 { 558 printf("Not a supported type"); 559 assert(0); 560 exit(-1); 561 } 562 563 } 564 565 566 } 567 568 569 Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 570 { 571 Double minCost, cost; 572 Int rate; 573 UInt previousWrittenBits; 574 Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS]; 575 SAOOffset testOffset[NUM_SAO_COMPONENTS]; 576 Int compIdx; 577 Int invQuantOffset[MAX_NUM_SAO_CLASSES]; 578 579 modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0; 580 581 //pre-encode merge flags 582 modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF; 583 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 584 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true); 585 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 586 587 //------ luma --------// 588 compIdx = SAO_Y; 589 //"off" case as initial cost 590 modeParam[compIdx].modeIdc = SAO_MODE_OFF; 2222 591 m_pcRDGoOnSbacCoder->resetBits(); 2223 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr); 2224 2225 dCostPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ; 2226 copySaoUnit(saoLcuParam, &saoLcuParamRdo ); 2227 bestDist = 0; 2228 2229 2230 2231 for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++) 2232 { 2233 estDist = estSaoTypeDist(yCbCr, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2234 2235 if( typeIdx == SAO_BO ) 2236 { 2237 // Estimate Best Position 2238 Double currentRDCost = 0.0; 2239 2240 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 2241 { 2242 currentRDCost = 0.0; 2243 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 2244 { 2245 currentRDCost += currentRdCostTableBo[uj]; 2246 } 2247 2248 if( currentRDCost < bestRDCostTableBo) 2249 { 2250 bestRDCostTableBo = currentRDCost; 2251 bestClassTableBo = i; 2252 } 2253 } 2254 2255 // Re code all Offsets 2256 // Code Center 2257 estDist = 0; 2258 for(classIdx = bestClassTableBo; classIdx < bestClassTableBo+SAO_BO_LEN; classIdx++) 2259 { 2260 estDist += currentDistortionTableBo[classIdx]; 2261 } 2262 } 2263 resetSaoUnit(&saoLcuParamRdo); 2264 saoLcuParamRdo.length = m_iNumClass[typeIdx]; 2265 saoLcuParamRdo.typeIdx = typeIdx; 2266 saoLcuParamRdo.mergeLeftFlag = 0; 2267 saoLcuParamRdo.mergeUpFlag = 0; 2268 saoLcuParamRdo.subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo : 0; 2269 for (classIdx = 0; classIdx < saoLcuParamRdo.length; classIdx++) 2270 { 2271 saoLcuParamRdo.offset[classIdx] = (Int)m_iOffset[yCbCr][typeIdx][classIdx+saoLcuParamRdo.subTypeIdx+1]; 2272 } 2273 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 592 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]); 593 modeDist[compIdx] = 0; 594 minCost= m_lambda[compIdx]*((Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits()); 595 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 596 if(sliceEnabled[compIdx]) 597 { 598 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 599 { 600 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 601 testOffset[compIdx].typeIdc = typeIdc; 602 603 //derive coded offset 604 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 605 606 //inversed quantized offsets 607 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 608 609 //get distortion 610 dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 611 612 //get rate 613 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 614 m_pcRDGoOnSbacCoder->resetBits(); 615 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 616 rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 617 cost = (Double)dist[compIdx] + m_lambda[compIdx]*((Double)rate); 618 if(cost < minCost) 619 { 620 minCost = cost; 621 modeDist[compIdx] = dist[compIdx]; 622 modeParam[compIdx]= testOffset[compIdx]; 623 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 624 } 625 } 626 } 627 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 628 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 629 630 //------ chroma --------// 631 //"off" case as initial cost 632 cost = 0; 633 previousWrittenBits = 0; 634 m_pcRDGoOnSbacCoder->resetBits(); 635 for (Int component = SAO_Cb; component < NUM_SAO_COMPONENTS; component++) 636 { 637 modeParam[component].modeIdc = SAO_MODE_OFF; 638 modeDist [component] = 0; 639 640 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(component, modeParam[component], sliceEnabled[component]); 641 642 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 643 cost += m_lambda[component] * (currentWrittenBits - previousWrittenBits); 644 previousWrittenBits = currentWrittenBits; 645 } 646 647 minCost = cost; 648 649 //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function 650 651 for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++) 652 { 653 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]); 2274 654 m_pcRDGoOnSbacCoder->resetBits(); 2275 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo, yCbCr); 2276 2277 estRate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2278 m_dCost[yCbCr][typeIdx] = (Double)((Double)estDist + lambda * (Double) estRate); 2279 2280 if(m_dCost[yCbCr][typeIdx] < dCostPartBest) 2281 { 2282 dCostPartBest = m_dCost[yCbCr][typeIdx]; 2283 copySaoUnit(saoLcuParam, &saoLcuParamRdo ); 2284 bestDist = estDist; 2285 } 2286 } 2287 compDistortion[0] += ((Double)bestDist/lambda); 2288 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2289 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam, yCbCr); 2290 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 2291 2292 2293 // merge left or merge up 2294 2295 for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++) 2296 { 2297 saoLcuParamNeighbor = NULL; 2298 if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0) 2299 { 2300 saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrLeft]); 2301 } 2302 else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1) 2303 { 2304 saoLcuParamNeighbor = &(saoParam->saoLcuParam[yCbCr][addrUp]); 2305 } 2306 if (saoLcuParamNeighbor!=NULL) 2307 { 2308 estDist = 0; 2309 typeIdx = saoLcuParamNeighbor->typeIdx; 2310 if (typeIdx>=0) 2311 { 2312 Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor->subTypeIdx:0; 2313 Int merge_iOffset; 2314 for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++) 2315 { 2316 merge_iOffset = saoLcuParamNeighbor->offset[classIdx]; 2317 estDist += estSaoDist(m_iCount [yCbCr][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[yCbCr][typeIdx][classIdx+mergeBandPosition+1], shift); 2318 } 2319 } 2320 else 2321 { 2322 estDist = 0; 2323 } 2324 2325 copySaoUnit(&compSaoParam[idxNeighbor], saoLcuParamNeighbor ); 2326 compSaoParam[idxNeighbor].mergeUpFlag = idxNeighbor; 2327 compSaoParam[idxNeighbor].mergeLeftFlag = !idxNeighbor; 2328 2329 compDistortion[idxNeighbor+1] += ((Double)estDist/lambda); 2330 } 2331 } 2332 } 2333 Void TEncSampleAdaptiveOffset::sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion) 2334 { 2335 Int typeIdx; 2336 2337 Int64 estDist[2]; 2338 Int classIdx; 2339 Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); 2340 Int64 bestDist = 0; 2341 2342 SaoLcuParam* saoLcuParam[2] = {&(saoParam->saoLcuParam[1][addr]), &(saoParam->saoLcuParam[2][addr])}; 2343 SaoLcuParam* saoLcuParamNeighbor[2] = {NULL, NULL}; 2344 SaoLcuParam* saoMergeParam[2][2]; 2345 saoMergeParam[0][0] = &crSaoParam[0]; 2346 saoMergeParam[0][1] = &crSaoParam[1]; 2347 saoMergeParam[1][0] = &cbSaoParam[0]; 2348 saoMergeParam[1][1] = &cbSaoParam[1]; 2349 2350 resetSaoUnit(saoLcuParam[0]); 2351 resetSaoUnit(saoLcuParam[1]); 2352 resetSaoUnit(saoMergeParam[0][0]); 2353 resetSaoUnit(saoMergeParam[0][1]); 2354 resetSaoUnit(saoMergeParam[1][0]); 2355 resetSaoUnit(saoMergeParam[1][1]); 2356 2357 2358 Double costPartBest = MAX_DOUBLE; 2359 2360 Double bestRDCostTableBo; 2361 Int bestClassTableBo[2] = {0, 0}; 2362 Int currentDistortionTableBo[MAX_NUM_SAO_CLASS]; 2363 Double currentRdCostTableBo[MAX_NUM_SAO_CLASS]; 2364 2365 SaoLcuParam saoLcuParamRdo[2]; 2366 Double estRate = 0; 2367 2368 resetSaoUnit(&saoLcuParamRdo[0]); 2369 resetSaoUnit(&saoLcuParamRdo[1]); 2370 2371 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 655 previousWrittenBits = 0; 656 cost = 0; 657 658 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 659 { 660 if(!sliceEnabled[compIdx]) 661 { 662 testOffset[compIdx].modeIdc = SAO_MODE_OFF; 663 dist[compIdx]= 0; 664 continue; 665 } 666 testOffset[compIdx].modeIdc = SAO_MODE_NEW; 667 testOffset[compIdx].typeIdc = typeIdc; 668 669 //derive offset & get distortion 670 deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo); 671 invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset); 672 dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]); 673 674 m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]); 675 676 const UInt currentWrittenBits = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 677 cost += dist[compIdx] + (m_lambda[compIdx] * (currentWrittenBits - previousWrittenBits)); 678 previousWrittenBits = currentWrittenBits; 679 } 680 681 if(cost < minCost) 682 { 683 minCost = cost; 684 for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++) 685 { 686 modeDist [compIdx] = dist [compIdx]; 687 modeParam[compIdx] = testOffset[compIdx]; 688 } 689 } 690 } 691 692 693 //----- re-gen rate & normalized cost----// 694 modeNormCost = 0; 695 for(UInt component = SAO_Y; component < NUM_SAO_COMPONENTS; component++) 696 { 697 modeNormCost += (Double)modeDist[component] / m_lambda[component]; 698 } 699 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 2372 700 m_pcRDGoOnSbacCoder->resetBits(); 2373 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[0], 1); 2374 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[1], 2); 2375 2376 costPartBest = m_pcEntropyCoder->getNumberOfWrittenBits()*lambda ; 2377 copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] ); 2378 copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] ); 2379 2380 for (typeIdx=0; typeIdx<MAX_NUM_SAO_TYPE; typeIdx++) 2381 { 2382 if( typeIdx == SAO_BO ) 2383 { 2384 // Estimate Best Position 2385 for(Int compIdx = 0; compIdx < 2; compIdx++) 2386 { 2387 Double currentRDCost = 0.0; 2388 bestRDCostTableBo = MAX_DOUBLE; 2389 estDist[compIdx] = estSaoTypeDist(compIdx+1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2390 for(Int i=0; i< SAO_MAX_BO_CLASSES -SAO_BO_LEN +1; i++) 2391 { 2392 currentRDCost = 0.0; 2393 for(UInt uj = i; uj < i+SAO_BO_LEN; uj++) 701 m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 702 modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 703 704 } 705 706 Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel) 707 { 708 Int mergeListSize = (Int)mergeList.size(); 709 modeNormCost = MAX_DOUBLE; 710 711 Double cost; 712 SAOBlkParam testBlkParam; 713 714 for(Int mergeType=0; mergeType< mergeListSize; mergeType++) 715 { 716 if(mergeList[mergeType] == NULL) 717 { 718 continue; 719 } 720 721 testBlkParam = *(mergeList[mergeType]); 722 //normalized distortion 723 Double normDist=0; 724 for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++) 725 { 726 testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE; 727 testBlkParam[compIdx].typeIdc = mergeType; 728 729 SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx]; 730 731 if( mergedOffsetParam.modeIdc != SAO_MODE_OFF) 732 { 733 //offsets have been reconstructed. Don't call inversed quantization function. 734 normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc])) 735 /m_lambda[compIdx] 736 ); 737 } 738 739 } 740 741 //rate 742 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]); 743 m_pcRDGoOnSbacCoder->resetBits(); 744 m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false); 745 Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits(); 746 747 cost = normDist+(Double)rate; 748 749 if(cost < modeNormCost) 750 { 751 modeNormCost = cost; 752 modeParam = testBlkParam; 753 m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 754 } 755 } 756 757 m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]); 758 759 760 } 761 762 Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams) 763 { 764 Bool isAllBlksDisabled = false; 765 if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr]) 766 { 767 isAllBlksDisabled = true; 768 } 769 770 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]); 771 772 SAOBlkParam modeParam; 773 Double minCost, modeCost; 774 775 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 776 { 777 if(isAllBlksDisabled) 778 { 779 codedParams[ctu].reset(); 780 continue; 781 } 782 783 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]); 784 785 //get merge list 786 std::vector<SAOBlkParam*> mergeList; 787 getMergeList(pic, ctu, reconParams, mergeList); 788 789 minCost = MAX_DOUBLE; 790 for(Int mode=0; mode < NUM_SAO_MODES; mode++) 791 { 792 switch(mode) 793 { 794 case SAO_MODE_OFF: 795 { 796 continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case. 797 } 798 break; 799 case SAO_MODE_NEW: 800 { 801 deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 802 803 } 804 break; 805 case SAO_MODE_MERGE: 806 { 807 deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR); 808 } 809 break; 810 default: 811 { 812 printf("Not a supported SAO mode\n"); 813 assert(0); 814 exit(-1); 815 } 816 } 817 818 if(modeCost < minCost) 819 { 820 minCost = modeCost; 821 codedParams[ctu] = modeParam; 822 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 823 824 } 825 } //mode 826 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]); 827 828 //apply reconstructed offsets 829 reconParams[ctu] = codedParams[ctu]; 830 reconstructBlkSAOParam(reconParams[ctu], mergeList); 831 offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic); 832 } //ctu 833 834 #if SAO_ENCODING_CHOICE 835 Int picTempLayer = pic->getSlice(0)->getDepth(); 836 Int numLcusForSAOOff[NUM_SAO_COMPONENTS]; 837 numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0; 838 839 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 840 { 841 for(Int ctu=0; ctu< m_numCTUsPic; ctu++) 842 { 843 if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF) 844 { 845 numLcusForSAOOff[compIdx]++; 846 } 847 } 848 } 849 #if SAO_ENCODING_CHOICE_CHROMA 850 for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++) 851 { 852 m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic; 853 } 854 #else 855 if (picTempLayer == 0) 856 { 857 m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3); 858 } 859 #endif 860 #endif 861 } 862 863 864 Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 865 , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height 866 , Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 867 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 868 , Bool isCalculatePreDeblockSamples 869 #endif 870 ) 871 { 872 if(m_lineBufWidth != m_maxCUWidth) 873 { 874 m_lineBufWidth = m_maxCUWidth; 875 876 if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL; 877 m_signLineBuf1 = new Char[m_lineBufWidth+1]; 878 879 if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL; 880 m_signLineBuf2 = new Char[m_lineBufWidth+1]; 881 } 882 883 Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX; 884 Char signLeft, signRight, signDown; 885 Int64 *diff, *count; 886 Pel *srcLine, *orgLine; 887 Int* skipLinesR = m_skipLinesR[compIdx]; 888 Int* skipLinesB = m_skipLinesB[compIdx]; 889 890 for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++) 891 { 892 SAOStatData& statsData= statsDataTypes[typeIdx]; 893 statsData.reset(); 894 895 srcLine = srcBlk; 896 orgLine = orgBlk; 897 diff = statsData.diff; 898 count = statsData.count; 899 switch(typeIdx) 900 { 901 case SAO_TYPE_EO_0: 902 { 903 diff +=2; 904 count+=2; 905 endY = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height; 906 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 907 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 908 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 909 ; 910 #else 911 startX = isLeftAvail ? 0 : 1; 912 #endif 913 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 914 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 915 : (isRightAvail ? width : (width - 1)) 916 ; 917 #else 918 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 919 #endif 920 for (y=0; y<endY; y++) 921 { 922 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 923 for (x=startX; x<endX; x++) 2394 924 { 2395 currentRDCost += currentRdCostTableBo[uj]; 925 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 926 edgeType = signRight + signLeft; 927 signLeft = -signRight; 928 929 diff [edgeType] += (orgLine[x] - srcLine[x]); 930 count[edgeType] ++; 2396 931 } 2397 2398 if( currentRDCost < bestRDCostTableBo) 932 srcLine += srcStride; 933 orgLine += orgStride; 934 } 935 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 936 if(isCalculatePreDeblockSamples) 937 { 938 if(isBelowAvail) 2399 939 { 2400 bestRDCostTableBo = currentRDCost; 2401 bestClassTableBo[compIdx] = i; 940 startX = isLeftAvail ? 0 : 1; 941 endX = isRightAvail ? width : (width -1); 942 943 for(y=0; y<skipLinesB[typeIdx]; y++) 944 { 945 signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]]; 946 for (x=startX; x<endX; x++) 947 { 948 signRight = (Char)m_sign[srcLine[x] - srcLine[x+1]]; 949 edgeType = signRight + signLeft; 950 signLeft = -signRight; 951 952 diff [edgeType] += (orgLine[x] - srcLine[x]); 953 count[edgeType] ++; 954 } 955 srcLine += srcStride; 956 orgLine += orgStride; 957 } 2402 958 } 2403 959 } 2404 2405 // Re code all Offsets 2406 // Code Center 2407 estDist[compIdx] = 0; 2408 for(classIdx = bestClassTableBo[compIdx]; classIdx < bestClassTableBo[compIdx]+SAO_BO_LEN; classIdx++) 2409 { 2410 estDist[compIdx] += currentDistortionTableBo[classIdx]; 2411 } 2412 } 2413 } 2414 else 2415 { 2416 estDist[0] = estSaoTypeDist(1, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2417 estDist[1] = estSaoTypeDist(2, typeIdx, shift, lambda, currentDistortionTableBo, currentRdCostTableBo); 2418 } 2419 2420 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2421 m_pcRDGoOnSbacCoder->resetBits(); 2422 2423 for(Int compIdx = 0; compIdx < 2; compIdx++) 2424 { 2425 resetSaoUnit(&saoLcuParamRdo[compIdx]); 2426 saoLcuParamRdo[compIdx].length = m_iNumClass[typeIdx]; 2427 saoLcuParamRdo[compIdx].typeIdx = typeIdx; 2428 saoLcuParamRdo[compIdx].mergeLeftFlag = 0; 2429 saoLcuParamRdo[compIdx].mergeUpFlag = 0; 2430 saoLcuParamRdo[compIdx].subTypeIdx = (typeIdx == SAO_BO) ? bestClassTableBo[compIdx] : 0; 2431 for (classIdx = 0; classIdx < saoLcuParamRdo[compIdx].length; classIdx++) 2432 { 2433 saoLcuParamRdo[compIdx].offset[classIdx] = (Int)m_iOffset[compIdx+1][typeIdx][classIdx+saoLcuParamRdo[compIdx].subTypeIdx+1]; 2434 } 2435 2436 m_pcEntropyCoder->encodeSaoOffset(&saoLcuParamRdo[compIdx], compIdx+1); 2437 } 2438 estRate = m_pcEntropyCoder->getNumberOfWrittenBits(); 2439 m_dCost[1][typeIdx] = (Double)((Double)(estDist[0] + estDist[1]) + lambda * (Double) estRate); 2440 2441 if(m_dCost[1][typeIdx] < costPartBest) 2442 { 2443 costPartBest = m_dCost[1][typeIdx]; 2444 copySaoUnit(saoLcuParam[0], &saoLcuParamRdo[0] ); 2445 copySaoUnit(saoLcuParam[1], &saoLcuParamRdo[1] ); 2446 bestDist = (estDist[0]+estDist[1]); 2447 } 2448 } 2449 2450 distortion[0] += ((Double)bestDist/lambda); 2451 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[0][CI_TEMP_BEST]); 2452 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[0], 1); 2453 m_pcEntropyCoder->encodeSaoOffset(saoLcuParam[1], 2); 2454 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[0][CI_TEMP_BEST] ); 2455 2456 // merge left or merge up 2457 2458 for (Int idxNeighbor=0;idxNeighbor<2;idxNeighbor++) 2459 { 2460 for(Int compIdx = 0; compIdx < 2; compIdx++) 2461 { 2462 saoLcuParamNeighbor[compIdx] = NULL; 2463 if (allowMergeLeft && addrLeft>=0 && idxNeighbor ==0) 2464 { 2465 saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrLeft]); 2466 } 2467 else if (allowMergeUp && addrUp>=0 && idxNeighbor ==1) 2468 { 2469 saoLcuParamNeighbor[compIdx] = &(saoParam->saoLcuParam[compIdx+1][addrUp]); 2470 } 2471 if (saoLcuParamNeighbor[compIdx]!=NULL) 2472 { 2473 estDist[compIdx] = 0; 2474 typeIdx = saoLcuParamNeighbor[compIdx]->typeIdx; 2475 if (typeIdx>=0) 2476 { 2477 Int mergeBandPosition = (typeIdx == SAO_BO)?saoLcuParamNeighbor[compIdx]->subTypeIdx:0; 2478 Int merge_iOffset; 2479 for(classIdx = 0; classIdx < m_iNumClass[typeIdx]; classIdx++) 960 #endif 961 } 962 break; 963 case SAO_TYPE_EO_90: 964 { 965 diff +=2; 966 count+=2; 967 Char *signUpLine = m_signLineBuf1; 968 969 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 970 startX = (!isCalculatePreDeblockSamples) ? 0 971 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 972 ; 973 #endif 974 startY = isAboveAvail ? 0 : 1; 975 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 976 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width) 977 : width 978 ; 979 #else 980 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : width ; 981 #endif 982 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 983 if (!isAboveAvail) 984 { 985 srcLine += srcStride; 986 orgLine += orgStride; 987 } 988 989 Pel* srcLineAbove = srcLine - srcStride; 990 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 991 for (x=startX; x<endX; x++) 992 #else 993 for (x=0; x< endX; x++) 994 #endif 995 { 996 signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]]; 997 } 998 999 Pel* srcLineBelow; 1000 for (y=startY; y<endY; y++) 1001 { 1002 srcLineBelow = srcLine + srcStride; 1003 1004 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1005 for (x=startX; x<endX; x++) 1006 #else 1007 for (x=0; x<endX; x++) 1008 #endif 2480 1009 { 2481 merge_iOffset = saoLcuParamNeighbor[compIdx]->offset[classIdx]; 2482 estDist[compIdx] += estSaoDist(m_iCount [compIdx+1][typeIdx][classIdx+mergeBandPosition+1], merge_iOffset, m_iOffsetOrg[compIdx+1][typeIdx][classIdx+mergeBandPosition+1], shift); 1010 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x]]; 1011 edgeType = signDown + signUpLine[x]; 1012 signUpLine[x]= -signDown; 1013 1014 diff [edgeType] += (orgLine[x] - srcLine[x]); 1015 count[edgeType] ++; 2483 1016 } 2484 } 2485 else 2486 { 2487 estDist[compIdx] = 0; 2488 } 2489 2490 copySaoUnit(saoMergeParam[compIdx][idxNeighbor], saoLcuParamNeighbor[compIdx] ); 2491 saoMergeParam[compIdx][idxNeighbor]->mergeUpFlag = idxNeighbor; 2492 saoMergeParam[compIdx][idxNeighbor]->mergeLeftFlag = !idxNeighbor; 2493 distortion[idxNeighbor+1] += ((Double)estDist[compIdx]/lambda); 2494 } 2495 } 2496 } 1017 srcLine += srcStride; 1018 orgLine += orgStride; 1019 } 1020 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1021 if(isCalculatePreDeblockSamples) 1022 { 1023 if(isBelowAvail) 1024 { 1025 startX = 0; 1026 endX = width; 1027 1028 for(y=0; y<skipLinesB[typeIdx]; y++) 1029 { 1030 srcLineBelow = srcLine + srcStride; 1031 srcLineAbove = srcLine - srcStride; 1032 1033 for (x=startX; x<endX; x++) 1034 { 1035 edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]]; 1036 diff [edgeType] += (orgLine[x] - srcLine[x]); 1037 count[edgeType] ++; 1038 } 1039 srcLine += srcStride; 1040 orgLine += orgStride; 1041 } 1042 } 1043 } 1044 #endif 1045 1046 } 1047 break; 1048 case SAO_TYPE_EO_135: 1049 { 1050 diff +=2; 1051 count+=2; 1052 Char *signUpLine, *signDownLine, *signTmpLine; 1053 1054 signUpLine = m_signLineBuf1; 1055 signDownLine= m_signLineBuf2; 1056 1057 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1058 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1059 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1060 ; 1061 #else 1062 startX = isLeftAvail ? 0 : 1 ; 1063 #endif 1064 1065 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1066 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1)) 1067 : (isRightAvail ? width : (width - 1)) 1068 ; 1069 #else 1070 endX = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1); 1071 #endif 1072 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1073 1074 //prepare 2nd line's upper sign 1075 Pel* srcLineBelow = srcLine + srcStride; 1076 for (x=startX; x<endX+1; x++) 1077 { 1078 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]]; 1079 } 1080 1081 //1st line 1082 Pel* srcLineAbove = srcLine - srcStride; 1083 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1084 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0 : 1) : startX; 1085 firstLineEndX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? endX : 1) : endX; 1086 #else 1087 firstLineStartX = isAboveLeftAvail ? 0 : 1; 1088 firstLineEndX = isAboveAvail ? endX : 1; 1089 #endif 1090 for(x=firstLineStartX; x<firstLineEndX; x++) 1091 { 1092 edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1]; 1093 diff [edgeType] += (orgLine[x] - srcLine[x]); 1094 count[edgeType] ++; 1095 } 1096 srcLine += srcStride; 1097 orgLine += orgStride; 1098 1099 1100 //middle lines 1101 for (y=1; y<endY; y++) 1102 { 1103 srcLineBelow = srcLine + srcStride; 1104 1105 for (x=startX; x<endX; x++) 1106 { 1107 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ; 1108 edgeType = signDown + signUpLine[x]; 1109 diff [edgeType] += (orgLine[x] - srcLine[x]); 1110 count[edgeType] ++; 1111 1112 signDownLine[x+1] = -signDown; 1113 } 1114 signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]]; 1115 1116 signTmpLine = signUpLine; 1117 signUpLine = signDownLine; 1118 signDownLine = signTmpLine; 1119 1120 srcLine += srcStride; 1121 orgLine += orgStride; 1122 } 1123 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1124 if(isCalculatePreDeblockSamples) 1125 { 1126 if(isBelowAvail) 1127 { 1128 startX = isLeftAvail ? 0 : 1 ; 1129 endX = isRightAvail ? width : (width -1); 1130 1131 for(y=0; y<skipLinesB[typeIdx]; y++) 1132 { 1133 srcLineBelow = srcLine + srcStride; 1134 srcLineAbove = srcLine - srcStride; 1135 1136 for (x=startX; x< endX; x++) 1137 { 1138 edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]]; 1139 diff [edgeType] += (orgLine[x] - srcLine[x]); 1140 count[edgeType] ++; 1141 } 1142 srcLine += srcStride; 1143 orgLine += orgStride; 1144 } 1145 } 1146 } 1147 #endif 1148 } 1149 break; 1150 case SAO_TYPE_EO_45: 1151 { 1152 diff +=2; 1153 count+=2; 1154 Char *signUpLine = m_signLineBuf1+1; 1155 1156 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1157 startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail ? 0 : 1) 1158 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1159 ; 1160 #else 1161 startX = isLeftAvail ? 0 : 1; 1162 #endif 1163 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1164 endX = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1)) 1165 : (isRightAvail ? width : (width - 1)) 1166 ; 1167 #else 1168 endX = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1); 1169 #endif 1170 endY = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1); 1171 1172 //prepare 2nd line upper sign 1173 Pel* srcLineBelow = srcLine + srcStride; 1174 for (x=startX-1; x<endX; x++) 1175 { 1176 signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]]; 1177 } 1178 1179 1180 //first line 1181 Pel* srcLineAbove = srcLine - srcStride; 1182 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1183 firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX) 1184 : startX 1185 ; 1186 firstLineEndX = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX) 1187 : endX 1188 ; 1189 #else 1190 firstLineStartX = isAboveAvail ? startX : endX; 1191 firstLineEndX = (!isRightAvail && isAboveRightAvail) ? width : endX; 1192 #endif 1193 for(x=firstLineStartX; x<firstLineEndX; x++) 1194 { 1195 edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1]; 1196 diff [edgeType] += (orgLine[x] - srcLine[x]); 1197 count[edgeType] ++; 1198 } 1199 1200 srcLine += srcStride; 1201 orgLine += orgStride; 1202 1203 //middle lines 1204 for (y=1; y<endY; y++) 1205 { 1206 srcLineBelow = srcLine + srcStride; 1207 1208 for(x=startX; x<endX; x++) 1209 { 1210 signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ; 1211 edgeType = signDown + signUpLine[x]; 1212 1213 diff [edgeType] += (orgLine[x] - srcLine[x]); 1214 count[edgeType] ++; 1215 1216 signUpLine[x-1] = -signDown; 1217 } 1218 signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]]; 1219 srcLine += srcStride; 1220 orgLine += orgStride; 1221 } 1222 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1223 if(isCalculatePreDeblockSamples) 1224 { 1225 if(isBelowAvail) 1226 { 1227 startX = isLeftAvail ? 0 : 1 ; 1228 endX = isRightAvail ? width : (width -1); 1229 1230 for(y=0; y<skipLinesB[typeIdx]; y++) 1231 { 1232 srcLineBelow = srcLine + srcStride; 1233 srcLineAbove = srcLine - srcStride; 1234 1235 for (x=startX; x<endX; x++) 1236 { 1237 edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]]; 1238 diff [edgeType] += (orgLine[x] - srcLine[x]); 1239 count[edgeType] ++; 1240 } 1241 srcLine += srcStride; 1242 orgLine += orgStride; 1243 } 1244 } 1245 } 1246 #endif 1247 } 1248 break; 1249 case SAO_TYPE_BO: 1250 { 1251 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1252 startX = (!isCalculatePreDeblockSamples)?0 1253 :( isRightAvail?(width- skipLinesR[typeIdx]):width) 1254 ; 1255 endX = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width ) 1256 :width 1257 ; 1258 #else 1259 endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width; 1260 #endif 1261 endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height; 1262 Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2; 1263 for (y=0; y< endY; y++) 1264 { 1265 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1266 for (x=startX; x< endX; x++) 1267 #else 1268 for (x=0; x< endX; x++) 1269 #endif 1270 { 1271 1272 Int bandIdx= srcLine[x] >> shiftBits; 1273 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1274 count[bandIdx] ++; 1275 } 1276 srcLine += srcStride; 1277 orgLine += orgStride; 1278 } 1279 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 1280 if(isCalculatePreDeblockSamples) 1281 { 1282 if(isBelowAvail) 1283 { 1284 startX = 0; 1285 endX = width; 1286 1287 for(y= 0; y< skipLinesB[typeIdx]; y++) 1288 { 1289 for (x=startX; x< endX; x++) 1290 { 1291 Int bandIdx= srcLine[x] >> shiftBits; 1292 diff [bandIdx] += (orgLine[x] - srcLine[x]); 1293 count[bandIdx] ++; 1294 } 1295 srcLine += srcStride; 1296 orgLine += orgStride; 1297 1298 } 1299 1300 } 1301 } 1302 #endif 1303 } 1304 break; 1305 default: 1306 { 1307 printf("Not a supported SAO types\n"); 1308 assert(0); 1309 exit(-1); 1310 } 1311 } 1312 } 2497 1313 } 2498 1314 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 3, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 54 54 // ==================================================================================================================== 55 55 56 enum SAOCabacStateLablesRDO //CABAC state labels 57 { 58 SAO_CABACSTATE_PIC_INIT =0, 59 SAO_CABACSTATE_BLK_CUR, 60 SAO_CABACSTATE_BLK_NEXT, 61 SAO_CABACSTATE_BLK_MID, 62 SAO_CABACSTATE_BLK_TEMP, 63 NUM_SAO_CABACSTATE_LABELS 64 }; 65 66 struct SAOStatData //data structure for SAO statistics 67 { 68 Int64 diff[MAX_NUM_SAO_CLASSES]; 69 Int64 count[MAX_NUM_SAO_CLASSES]; 70 71 SAOStatData(){} 72 ~SAOStatData(){} 73 Void reset() 74 { 75 ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 76 ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 77 } 78 const SAOStatData& operator=(const SAOStatData& src) 79 { 80 ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 81 ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES); 82 return *this; 83 } 84 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 85 const SAOStatData& operator+= (const SAOStatData& src) 86 { 87 for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++) 88 { 89 diff[i] += src.diff[i]; 90 count[i] += src.count[i]; 91 } 92 return *this; 93 } 94 #endif 95 }; 96 56 97 class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset 57 98 { 58 private:59 TEncEntropy* m_pcEntropyCoder;60 TEncSbac*** m_pppcRDSbacCoder; ///< for CABAC61 TEncSbac* m_pcRDGoOnSbacCoder;62 #if FAST_BIT_EST63 TEncBinCABACCounter*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation64 #else65 TEncBinCABAC*** m_pppcBinCoderCABAC; ///< temporal CABAC state storage for RD computation66 #endif67 68 Int64 ***m_iCount; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];69 Int64 ***m_iOffset; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];70 Int64 ***m_iOffsetOrg; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];71 Int64 ****m_count_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];72 Int64 ****m_offsetOrg_PreDblk; //[LCU][YCbCr][MAX_NUM_SAO_TYPE][MAX_NUM_SAO_CLASS];73 Int64 **m_iRate; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];74 Int64 **m_iDist; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];75 Double **m_dCost; //[MAX_NUM_SAO_PART][MAX_NUM_SAO_TYPE];76 Double *m_dCostPartBest; //[MAX_NUM_SAO_PART];77 Int64 *m_iDistOrg; //[MAX_NUM_SAO_PART];78 Int *m_iTypePartBest; //[MAX_NUM_SAO_PART];79 Int m_iOffsetThY;80 Int m_iOffsetThC;81 Bool m_bUseSBACRD;82 #if SAO_ENCODING_CHOICE83 #if SAO_ENCODING_CHOICE_CHROMA84 Double m_depthSaoRate[2][4];85 #else86 Double m_depth0SaoRate;87 #endif88 #endif89 90 99 public: 91 TEncSampleAdaptiveOffset 100 TEncSampleAdaptiveOffset(); 92 101 virtual ~TEncSampleAdaptiveOffset(); 93 102 94 Void startSaoEnc( TComPic* pcPic, TEncEntropy* pcEntropyCoder, TEncSbac*** pppcRDSbacCoder, TEncSbac* pcRDGoOnSbacCoder); 95 Void endSaoEnc(); 96 Void resetStats(); 97 #if SAO_CHROMA_LAMBDA 103 //interface 104 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 105 Void createEncData(Bool isPreDBFSamplesUsed); 106 #else 107 Void createEncData(); 108 #endif 109 Void destroyEncData(); 110 Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ; 111 Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas 112 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 113 , Bool isPreDBFSamplesUsed 114 #endif 115 ); 116 public: //methods 117 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 118 Void getPreDBFStatistics(TComPic* pPic); 119 #endif 120 private: //methods 121 Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic 122 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 123 , Bool isCalculatePreDeblockSamples = false 124 #endif 125 ); 126 Void decidePicParams(Bool* sliceEnabled, Int picTempLayer); 127 Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams); 128 Void getBlkStats(Int compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail, Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail 129 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 130 , Bool isCalculatePreDeblockSamples 131 #endif 132 ); 133 Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 134 Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel); 135 Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData); 136 Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo); 137 inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift); 138 inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh ); 139 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 140 Void addPreDBFStatistics(SAOStatData*** blkStats); 141 #endif 142 private: //members 143 //for RDO 144 TEncSbac** m_pppcRDSbacCoder; 145 TEncSbac* m_pcRDGoOnSbacCoder; 146 TEncBinCABACCounter** m_pppcBinCoderCABAC; 147 Double m_lambda[NUM_SAO_COMPONENTS]; 148 149 //statistics 150 SAOStatData*** m_statData; //[ctu][comp][classes] 151 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 152 SAOStatData*** m_preDBFstatData; 153 #endif 98 154 #if SAO_ENCODING_CHOICE 99 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth); 100 #else 101 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma); 155 Double m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER]; 102 156 #endif 103 #else 104 Void SAOProcess(SAOParam *pcSaoParam, Double dLambda); 105 #endif 106 107 Void runQuadTreeDecision(SAOQTPart *psQTPart, Int iPartIdx, Double &dCostFinal, Int iMaxLevel, Double dLambda, Int yCbCr); 108 Void rdoSaoOnePart(SAOQTPart *psQTPart, Int iPartIdx, Double dLambda, Int yCbCr); 109 110 Void disablePartTree(SAOQTPart *psQTPart, Int iPartIdx); 111 Void getSaoStats(SAOQTPart *psQTPart, Int iYCbCr); 112 Void calcSaoStatsCu(Int iAddr, Int iPartIdx, Int iYCbCr); 113 Void calcSaoStatsBlock( Pel* pRecStart, Pel* pOrgStart, Int stride, Int64** ppStats, Int64** ppCount, UInt width, UInt height, Bool* pbBorderAvail, Int iYCbCr); 114 Void calcSaoStatsCuOrg(Int iAddr, Int iPartIdx, Int iYCbCr); 115 Void calcSaoStatsCu_BeforeDblk( TComPic* pcPic ); 116 Void destroyEncBuffer(); 117 Void createEncBuffer(); 118 Void assignSaoUnitSyntax(SaoLcuParam* saoLcuParam, SAOQTPart* saoPart, Bool &oneUnitFlag, Int yCbCr); 119 Void checkMerge(SaoLcuParam * lcuParamCurr,SaoLcuParam * lcuParamCheck, Int dir); 120 #if SAO_ENCODING_CHOICE 121 Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma, Int depth); 122 #else 123 Void rdoSaoUnitAll(SAOParam *saoParam, Double lambda, Double lambdaChroma); 124 #endif 125 Void saoComponentParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Int yCbCr, Double lambda, SaoLcuParam *compSaoParam, Double *distortion); 126 Void sao2ChromaParamDist(Int allowMergeLeft, Int allowMergeUp, SAOParam *saoParam, Int addr, Int addrUp, Int addrLeft, Double lambda, SaoLcuParam *crSaoParam, SaoLcuParam *cbSaoParam, Double *distortion); 127 inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 offsetOrg, Int shift); 128 inline Int64 estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int64 offsetInput, Int64 count, Int64 offsetOrg, Int shift, Int bitIncrease, Int *currentDistortionTableBo, Double *currentRdCostTableBo, Int offsetTh ); 129 inline Int64 estSaoTypeDist(Int compIdx, Int typeIdx, Int shift, Double lambda, Int *currentDistortionTableBo, Double *currentRdCostTableBo); 130 Void setMaxNumOffsetsPerPic(Int iVal) {m_maxNumOffsetsPerPic = iVal; } 131 Int getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; } 157 Int m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 158 Int m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES]; 132 159 }; 133 134 160 //! \} 135 161 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSbac.cpp
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 84 84 , m_cCUAbsSCModel ( 1, 1, NUM_ABS_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 85 85 , m_cMVPIdxSCModel ( 1, 1, NUM_MVP_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) 86 , m_cCUAMPSCModel ( 1, 1, NUM_CU_AMP_CTX , m_contextModels + m_numContextModels, m_numContextModels)87 86 , m_cSaoMergeSCModel ( 1, 1, NUM_SAO_MERGE_FLAG_CTX , m_contextModels + m_numContextModels, m_numContextModels) 88 87 , m_cSaoTypeIdxSCModel ( 1, 1, NUM_SAO_TYPE_IDX_CTX , m_contextModels + m_numContextModels, m_numContextModels) … … 153 152 #endif 154 153 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 155 m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );156 154 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 157 155 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); … … 254 252 #endif 255 253 curCost += m_cCUPartSizeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PART_SIZE ); 256 curCost += m_cCUAMPSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_CU_AMP_POS );257 254 curCost += m_cCUPredModeSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_PRED_MODE ); 258 255 curCost += m_cCUIntraPredSCModel.calcCost ( curSliceType, qp, (UChar*)INIT_INTRA_PRED_MODE ); … … 326 323 #endif 327 324 m_cCUPartSizeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PART_SIZE ); 328 m_cCUAMPSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_CU_AMP_POS );329 325 m_cCUPredModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_PRED_MODE ); 330 326 m_cCUIntraPredSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_INTRA_PRED_MODE ); … … 348 344 m_cTransformSkipSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_TRANSFORMSKIP_FLAG ); 349 345 m_CUTransquantBypassFlagSCModel.initBuffer( eSliceType, iQp, (UChar*)INIT_CU_TRANSQUANT_BYPASS_FLAG ); 350 351 346 #if H_3D_DIM 352 347 m_cDepthIntraModeSCModel.initBuffer ( eSliceType, iQp, (UChar*)INIT_DEPTH_INTRA_MODE ); … … 794 789 if (eSize == SIZE_2NxN) 795 790 { 796 m_pcBinIf->encodeBin(1, m_cCU AMPSCModel.get( 0, 0, 0));791 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 797 792 } 798 793 else 799 794 { 800 m_pcBinIf->encodeBin(0, m_cCU AMPSCModel.get( 0, 0, 0 ));795 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 801 796 m_pcBinIf->encodeBinEP((eSize == SIZE_2NxnU? 0: 1)); 802 797 } … … 818 813 if (eSize == SIZE_Nx2N) 819 814 { 820 m_pcBinIf->encodeBin(1, m_cCU AMPSCModel.get( 0, 0, 0));815 m_pcBinIf->encodeBin(1, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 821 816 } 822 817 else 823 818 { 824 m_pcBinIf->encodeBin(0, m_cCU AMPSCModel.get( 0, 0, 0));819 m_pcBinIf->encodeBin(0, m_cCUPartSizeSCModel.get( 0, 0, 3 )); 825 820 m_pcBinIf->encodeBinEP((eSize == SIZE_nLx2N? 0: 1)); 826 821 } -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSbac.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 111 111 Void codeScalingList ( TComScalingList* /*scalingList*/ ){ assert (0); return;}; 112 112 113 Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled); 114 Void codeSAOBlkParam(SAOBlkParam& saoBlkParam 115 , Bool* sliceEnabled 116 , Bool leftMergeAvail 117 , Bool aboveMergeAvail 118 , Bool onlyEstMergeInfo = false 119 ); 120 113 121 private: 114 122 Void xWriteUnarySymbol ( UInt uiSymbol, ContextModel* pcSCModel, Int iOffset ); … … 245 253 ContextModel3DBuffer m_cMVPIdxSCModel; 246 254 247 ContextModel3DBuffer m_cCUAMPSCModel;248 255 ContextModel3DBuffer m_cSaoMergeSCModel; 249 256 ContextModel3DBuffer m_cSaoTypeIdxSCModel; 250 257 ContextModel3DBuffer m_cTransformSkipSCModel; 251 258 ContextModel3DBuffer m_CUTransquantBypassFlagSCModel; 252 253 #if H_3D_DIM254 ContextModel3DBuffer m_cDepthIntraModeSCModel;255 ContextModel3DBuffer m_cDdcFlagSCModel;256 ContextModel3DBuffer m_cDdcDataSCModel;257 #if QC_GENERIC_SDC_G0122258 ContextModel3DBuffer m_cAngleFlagSCModel;259 #if !QC_SDC_UNIFY_G0130260 ContextModel3DBuffer m_cIntraSdcFlagSCModel;261 #endif262 #endif263 #if H_3D_DIM_DMM264 ContextModel3DBuffer m_cDmm1DataSCModel;265 #endif266 #if H_3D_DIM_SDC267 ContextModel3DBuffer m_cSDCResidualFlagSCModel;268 ContextModel3DBuffer m_cSDCResidualSCModel;269 #endif270 #endif271 #if H_3D_INTER_SDC && !QC_SDC_UNIFY_G0130272 ContextModel3DBuffer m_cInterSDCFlagSCModel;273 ContextModel3DBuffer m_cInterSDCResidualSCModel;274 ContextModel3DBuffer m_cInterSDCResidualSignFlagSCModel;275 #endif276 #if QC_SDC_UNIFY_G0130277 ContextModel3DBuffer m_cSDCFlagSCModel;278 #endif279 #if H_3D_DBBP280 ContextModel3DBuffer m_cDBBPFlagSCModel;281 #endif282 259 }; 283 260 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSearch.cpp
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 202 202 m_pppcRDSbacCoder = pppcRDSbacCoder; 203 203 m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder; 204 205 m_bUseSBACRD = pppcRDSbacCoder ? true : false;206 204 207 205 for (Int iDir = 0; iDir < 2; iDir++) … … 745 743 piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr(); 746 744 if ( horVal == 2 && ( verVal & 1 ) == 0 ) 745 { 747 746 piRefPos += 1; 747 } 748 748 if ( ( horVal & 1 ) == 0 && verVal == 2 ) 749 { 749 750 piRefPos += iRefStride; 751 } 750 752 cMvTest = pcMvRefine[i]; 751 753 cMvTest += rcMvFrac; … … 787 789 UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth; 788 790 789 {790 791 if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 ) 791 792 { … … 812 813 } 813 814 } 814 }815 815 816 816 if ( bChroma ) … … 819 819 { 820 820 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) ) 821 { 821 822 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth ); 823 } 822 824 if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) ) 825 { 823 826 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth ); 824 827 } 828 } 825 829 } 826 830 … … 835 839 } 836 840 837 {838 841 //===== Cbfs ===== 839 842 if( bLuma ) … … 842 845 } 843 846 } 844 }845 847 846 848 Void … … 1212 1214 { 1213 1215 Int scalingListType = 0 + g_eTTable[(Int)TEXT_LUMA]; 1214 assert(scalingListType < 6);1216 assert(scalingListType < SCALING_LIST_NUM); 1215 1217 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,pcCU->getLumaIntraDir( uiAbsPartIdx ), piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkip ); 1216 1218 } … … 1412 1414 1413 1415 #if RDOQ_CHROMA_LAMBDA 1414 m_pcTrQuant->selectLambda (TEXT_CHROMA);1416 m_pcTrQuant->selectLambda(eText); 1415 1417 #endif 1416 1418 m_pcTrQuant->transformNxN ( pcCU, piResi, uiStride, pcCoeff, … … 1425 1427 { 1426 1428 Int scalingListType = 0 + g_eTTable[(Int)eText]; 1427 assert(scalingListType < 6);1429 assert(scalingListType < SCALING_LIST_NUM); 1428 1430 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA, REG_DCT, piResi, uiStride, pcCoeff, uiWidth, uiHeight, scalingListType, useTransformSkipChroma ); 1429 1431 } … … 1464 1466 1465 1467 //===== update distortion ===== 1466 #if WEIGHTED_CHROMA_DISTORTION1467 1468 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText ); 1468 #else1469 ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );1470 #endif1471 1469 } 1472 1470 … … 1553 1551 checkTransformSkip &= (widthTransformSkip == 4 && heightTransformSkip == 4); 1554 1552 checkTransformSkip &= (!pcCU->getCUTransquantBypass(0)); 1555 checkTransformSkip &= (!((pcCU->getQP( 0 ) == 0) && (pcCU->getSlice()->getSPS()->getUseLossless())));1556 1553 if ( m_pcEncCfg->getUseTransformSkipFast() ) 1557 1554 { … … 1563 1560 { 1564 1561 //----- store original entropy coding status ----- 1565 if( m_bUseSBACRD)1566 {1567 1562 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1568 }1569 1563 #if H_3D_VSO 1570 1564 Dist singleDistYTmp = 0; … … 1641 1635 { 1642 1636 xStoreIntraResultQT(pcCU, uiTrDepth, uiAbsPartIdx,bLumaOnly ); 1643 if( m_bUseSBACRD)1644 {1645 1637 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 1646 1638 } 1647 1639 } 1648 }1649 1640 if(modeId == firstCheckId) 1650 1641 { … … 1667 1658 } 1668 1659 } 1669 if(m_bUseSBACRD)1670 {1671 1660 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 1672 1661 } 1673 }1674 1662 1675 1663 if( !bLumaOnly ) … … 1696 1684 pcCU ->setTransformSkipSubParts ( 0, TEXT_LUMA, uiAbsPartIdx, uiFullDepth ); 1697 1685 //----- store original entropy coding status ----- 1698 if( m_bUseSBACRD &&bCheckSplit )1686 if( bCheckSplit ) 1699 1687 { 1700 1688 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); … … 1742 1730 { 1743 1731 //----- store full entropy coding status, load original entropy coding status ----- 1744 if( m_bUseSBACRD )1745 {1746 1732 if( bCheckFull ) 1747 1733 { … … 1753 1739 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1754 1740 } 1755 } 1741 1756 1742 //----- code splitted block ----- 1757 1743 Double dSplitCost = 0.0; … … 1798 1784 } 1799 1785 //----- restore context states ----- 1800 if( m_bUseSBACRD )1801 {1802 1786 m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_ROOT ] ); 1803 } 1787 1804 1788 //----- determine rate and r-d cost ----- 1805 1789 UInt uiSplitBits = xGetIntraBitsQT( pcCU, uiTrDepth, uiAbsPartIdx, true, !bLumaOnly, false ); … … 1821 1805 } 1822 1806 //----- set entropy coding status ----- 1823 if( m_bUseSBACRD )1824 {1825 1807 m_pcRDGoOnSbacCoder->load ( m_pppcRDSbacCoder[ uiFullDepth ][ CI_QT_TRAFO_TEST ] ); 1826 }1827 1808 1828 1809 //--- set transform index and Cbf values --- … … 2718 2699 { 2719 2700 //use RDO to decide whether Cr/Cb takes TS 2720 if( m_bUseSBACRD )2721 {2722 2701 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); 2723 }2724 2702 2725 2703 for(Int chromaId = 0; chromaId < 2; chromaId ++) … … 2772 2750 { 2773 2751 xStoreIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); 2774 if( m_bUseSBACRD)2775 {2776 2752 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 2777 2753 } 2778 2754 } 2779 }2780 2755 if(chromaModeId == firstCheckId) 2781 2756 { … … 2788 2763 xLoadIntraResultChromaQT(pcCU, uiTrDepth, uiAbsPartIdx,chromaId); 2789 2764 pcCU->setCbfSubParts ( singleCbfC << uiTrDepth, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth(0) + actualTrDepth ); 2790 if(m_bUseSBACRD)2791 {2792 2765 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiFullDepth ][ CI_TEMP_BEST ] ); 2793 2766 } 2794 }2795 2767 pcCU ->setTransformSkipSubParts( bestModeId, (TextType)(chromaId + 2), uiAbsPartIdx, pcCU->getDepth( 0 ) + actualTrDepth ); 2796 2768 ruiDist += singleDistC; … … 2798 2770 if(chromaId == 0) 2799 2771 { 2800 if( m_bUseSBACRD )2801 {2802 2772 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[uiFullDepth][CI_QT_TRAFO_ROOT] ); 2803 2773 } 2804 2774 } 2805 2775 } 2806 }2807 2776 else 2808 2777 { … … 3217 3186 #endif 3218 3187 // set context models 3219 if( m_bUseSBACRD )3220 {3221 3188 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3222 }3223 3189 3224 3190 // determine residual for partition … … 3350 3316 3351 3317 // set context models 3352 if( m_bUseSBACRD )3353 {3354 3318 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3355 }3356 3319 3357 3320 // determine residual for partition … … 3521 3484 3522 3485 //===== reset context models ===== 3523 if(m_bUseSBACRD)3524 {3525 3486 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 3526 }3527 3487 3528 3488 //===== set distortion (rate and r-d costs are determined later) ===== … … 3556 3516 { 3557 3517 //----- restore context models ----- 3558 if( m_bUseSBACRD )3559 {3560 3518 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3561 }3562 3519 3563 3520 //----- chroma coding ----- … … 3565 3522 pcCU->setChromIntraDirSubParts ( uiModeList[uiMode], 0, uiDepth ); 3566 3523 xRecurIntraChromaCodingQT ( pcCU, 0, 0, pcOrgYuv, pcPredYuv, pcResiYuv, uiDist ); 3567 if( m_bUseSBACRD &&pcCU->getSlice()->getPPS()->getUseTransformSkip() )3524 if( pcCU->getSlice()->getPPS()->getUseTransformSkip() ) 3568 3525 { 3569 3526 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); … … 3597 3554 3598 3555 //----- restore context models ----- 3599 if( m_bUseSBACRD )3600 {3601 3556 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 3602 3557 } 3603 }3604 3558 3605 3559 /** Function for encoding and reconstructing luma/chroma samples of a PCM mode CU. … … 3761 3715 dCost = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); 3762 3716 3763 if(m_bUseSBACRD)3764 {3765 3717 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 3766 }3767 3718 3768 3719 pcCU->getTotalBits() = uiBits; … … 3789 3740 pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(), 3790 3741 m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(), 3791 #if NS_HAD3792 iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );3793 #else3794 3742 iWidth, iHeight, m_pcEncCfg->getUseHADME() ); 3795 #endif3796 3743 #if H_3D_IC 3797 3744 cDistParam.bUseIC = false; … … 3942 3889 for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand ) 3943 3890 { 3944 {3945 3891 UInt uiCostCand = MAX_UINT; 3946 3892 UInt uiBitsCand = 0; … … 4044 3990 } 4045 3991 } 4046 }4047 3992 4048 3993 /** convert bi-pred merge candidates to uni-pred … … 4181 4126 4182 4127 UInt uiCostTempL0[MAX_NUM_REF]; 4183 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT; 4128 for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) 4129 { 4130 uiCostTempL0[iNumRef] = MAX_UINT; 4131 } 4184 4132 UInt uiBitsTempL0[MAX_NUM_REF]; 4185 4133 … … 4594 4542 { 4595 4543 uiLastMode = 2; 4596 {4597 4544 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4598 4545 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4599 4546 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4600 4547 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4601 } 4602 { 4548 4603 4549 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]]; 4604 4550 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4605 } 4606 { 4551 4607 4552 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]]; 4608 4553 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4609 }4610 4554 4611 4555 pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); … … 4623 4567 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4624 4568 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4625 {4626 4569 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 4627 4570 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4628 }4629 4571 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4630 4572 … … 4639 4581 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4640 4582 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4641 {4642 4583 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 4643 4584 pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd ( TempMv, ePartSize, uiPartAddr, 0, iPartIdx ); 4644 }4645 4585 pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) ); 4646 4586 … … 4729 4669 pcCU->setDvInfoSubParts(inheritedVSPDisInfo[uiMRGIndex].m_acDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4730 4670 #endif 4731 4732 4671 #if MTK_DDD_G0063 4733 4672 if( uiMRGIndex == pcCU->getUseDDDCandIdx() ) … … 4743 4682 } 4744 4683 #endif 4745 4746 4684 #if H_3D_SPIVMP 4747 4685 pcCU->setSPIVMPFlagSubParts(bSPIVMPFlag[uiMRGIndex], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); … … 4749 4687 { 4750 4688 UInt uiSPAddr; 4751 4752 4689 Int iNumSPInOneLine, iNumSP, iSPWidth, iSPHeight; 4753 4754 4690 pcCU->getSPPara(iRoiWidth, iRoiHeight, iNumSP, iNumSPInOneLine, iSPWidth, iSPHeight); 4755 4756 4691 for (Int iPartitionIdx = 0; iPartitionIdx < iNumSP; iPartitionIdx++) 4757 4692 { … … 4761 4696 pcCU->getCUMvField( REF_PIC_LIST_1 )->setMvFieldSP(pcCU, uiSPAddr, pcMvFieldSP[2*iPartitionIdx + 1], iSPWidth, iSPHeight); 4762 4697 } 4763 4764 4698 if ( pcCU->getInterDir(uiPartAddr) == 3 && pcCU->isBipredRestriction(iPartIdx) ) 4765 4699 { … … 4768 4702 pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr )); 4769 4703 } 4770 4771 4704 } 4772 4705 else … … 4783 4716 Int width, height; 4784 4717 pcCU->getPartIndexAndSize( iPartIdx, partAddrTemp, width, height ); // true or pcCU->getTotalNumPart()==256 4785 4786 4718 if( uiMRGInterDir & 0x01 ) 4787 4719 { … … 4806 4738 else 4807 4739 #endif 4808 {4809 4740 pcCU->setInterDirSubParts ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4810 {4811 4741 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4812 4742 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4813 }4814 }4815 4743 4816 4744 pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd ( cMvZero, ePartSize, uiPartAddr, 0, iPartIdx ); … … 4827 4755 pcCU->setSPIVMPFlagSubParts(0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4828 4756 #endif 4829 4830 4757 #if MTK_DDD_G0063 4831 4758 pcCU->setUseDDD( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); … … 4838 4765 pcCU->setDvInfoSubParts(OriginalDvInfo, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) ); 4839 4766 #endif 4840 {4841 4767 pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx ); 4842 4768 pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx ); 4843 4769 } 4844 }4845 4770 #if H_3D_SPIVMP 4846 4771 delete[] pcMvFieldSP; … … 4997 4922 4998 4923 if (iNum == 1) 4924 { 4999 4925 return 0; 4926 } 5000 4927 5001 4928 UInt uiLength = 1; … … 5177 5104 pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), 5178 5105 pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), 5179 #if NS_HAD5180 iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );5181 #else5182 5106 iSizeX, iSizeY, m_pcEncCfg->getUseHADME() ); 5183 #endif5184 5107 ruiDist = cDistParam.DistFunc( &cDistParam ); 5185 5108 uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] ); 5186 5109 #else 5187 #if WEIGHTED_CHROMA_DISTORTION5188 5110 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD ); 5189 #else5190 uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );5191 #endif5192 5111 uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD ); 5193 5112 #endif … … 5288 5207 m_pcRdCost->setCostScale ( 1 ); 5289 5208 5290 { 5291 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost 5292 ,bBi 5293 ); 5294 } 5209 xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi ); 5295 5210 5296 5211 … … 5696 5611 #endif 5697 5612 5698 if( m_bUseSBACRD )5699 5613 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]); 5700 5614 … … 5729 5643 pcCU->getTotalCost() = m_pcRdCost->calcRdCost( uiBits, uiDistortion ); 5730 5644 5731 if( m_bUseSBACRD )5732 5645 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]); 5733 5646 … … 5771 5684 uiBits = 0; 5772 5685 uiDistortion = 0; 5773 if( m_bUseSBACRD )5774 {5775 5686 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_CURR_BEST ] ); 5776 }5777 5687 5778 5688 #if H_3D_VSO // M16 // M18 … … 5836 5746 } 5837 5747 5838 if( m_bUseSBACRD )5839 {5840 5748 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 5841 }5842 5749 #if 0 // check 5843 5750 { … … 5845 5752 m_pcEntropyCoder->encodeCoeff( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0) ); 5846 5753 const UInt uiBitsForCoeff = m_pcEntropyCoder->getNumberOfWrittenBits(); 5847 if( m_bUseSBACRD )5848 {5849 5754 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST] ); 5850 }5851 5755 if( uiBitsForCoeff != uiBits ) 5852 5756 assert( 0 ); … … 5904 5808 dCostBest = dCost; 5905 5809 qpBest = qp; 5906 if( m_bUseSBACRD )5907 {5908 5810 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 5909 5811 } … … 5917 5819 } 5918 5820 #endif 5919 }5920 5821 5921 5822 assert ( dCostBest != MAX_DOUBLE ); … … 5923 5824 if( qpMin != qpMax && qpBest != qpMax ) 5924 5825 { 5925 if( m_bUseSBACRD )5926 {5927 5826 assert( 0 ); // check 5928 5827 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ pcCU->getDepth( 0 ) ][ CI_TEMP_BEST ] ); 5929 }5930 5828 // copy best cbf and trIdx to pcCU 5931 5829 const UInt uiQPartNum = pcCU->getPic()->getNumPartInCU() >> (pcCU->getDepth(0) << 1); … … 5957 5855 #endif 5958 5856 // update with clipped distortion and cost (qp estimation loop uses unclipped values) 5959 #if WEIGHTED_CHROMA_DISTORTION5960 5857 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight ) 5961 5858 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U ) 5962 5859 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V ); 5963 #else5964 uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(), pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(), uiWidth, uiHeight )5965 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )5966 + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(), rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(), pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );5967 #endif5968 5860 #if H_3D_VSO // M23 5969 5861 } … … 5984 5876 5985 5877 pcCU->setQPSubParts( qpBest, 0, pcCU->getDepth(0) ); 5986 5987 5878 #if H_3D_VSO // M24 // necessary?? 5988 5879 if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() ) … … 6216 6107 Bool bCheckFull; 6217 6108 if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) ) 6109 { 6218 6110 bCheckFull = false; 6111 } 6219 6112 else 6113 { 6220 6114 bCheckFull = ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() ); 6115 } 6221 6116 6222 6117 const Bool bCheckSplit = ( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ); … … 6247 6142 UInt uiBestTransformMode[3] = {0}; 6248 6143 6249 if( m_bUseSBACRD )6250 {6251 6144 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6252 }6253 6145 6254 6146 if( bCheckFull ) … … 6316 6208 6317 6209 #if RDOQ_CHROMA_LAMBDA 6318 m_pcTrQuant->selectLambda(TEXT_CHROMA );6210 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 6319 6211 #endif 6320 6212 … … 6327 6219 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 6328 6220 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 6221 6222 #if RDOQ_CHROMA_LAMBDA 6223 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 6224 #endif 6225 6329 6226 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 6330 6227 #if ADAPTIVE_QP_SELECTION … … 6339 6236 m_pcEntropyCoder->resetBits(); 6340 6237 6341 {6342 6238 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 6343 }6344 6239 6345 6240 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); … … 6350 6245 if( bCodeChroma ) 6351 6246 { 6352 {6353 6247 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode ); 6354 }6355 6248 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U ); 6356 6249 uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY; 6357 6250 6358 {6359 6251 m_pcEntropyCoder->encodeQtCbf ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode ); 6360 }6361 6252 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V ); 6362 6253 uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU ); … … 6400 6291 6401 6292 Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; 6402 assert(scalingListType < 6);6293 assert(scalingListType < SCALING_LIST_NUM); 6403 6294 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 6404 6295 … … 6423 6314 } 6424 6315 #else 6425 const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); 6316 const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), 6317 pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight ); 6426 6318 #endif 6427 6319 if (pcCU->isLosslessCoded(0)) … … 6500 6392 { 6501 6393 uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6502 #if WEIGHTED_CHROMA_DISTORTION6503 6394 , TEXT_CHROMA_U 6504 #endif6505 6395 ); // initialized with zero residual destortion 6506 6396 if ( puiZeroDist ) … … 6516 6406 6517 6407 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; 6518 assert(scalingListType < 6);6408 assert(scalingListType < SCALING_LIST_NUM); 6519 6409 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType ); 6520 6410 6521 6411 const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6522 6412 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6523 #if WEIGHTED_CHROMA_DISTORTION6524 6413 , TEXT_CHROMA_U 6525 #endif6526 6414 ); 6527 6415 … … 6559 6447 { 6560 6448 m_pcEntropyCoder->resetBits(); 6561 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode C);6449 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode ); 6562 6450 const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits(); 6563 6451 minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU ); … … 6575 6463 6576 6464 uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6577 #if WEIGHTED_CHROMA_DISTORTION6578 6465 , TEXT_CHROMA_V 6579 #endif6580 6466 ); // initialized with zero residual destortion 6581 6467 if ( puiZeroDist ) … … 6590 6476 6591 6477 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; 6592 assert(scalingListType < 6);6478 assert(scalingListType < SCALING_LIST_NUM); 6593 6479 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType ); 6594 6480 6595 6481 const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6596 6482 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6597 #if WEIGHTED_CHROMA_DISTORTION6598 6483 , TEXT_CHROMA_V 6599 #endif6600 6484 ); 6601 6485 if (pcCU->isLosslessCoded(0)) … … 6632 6516 { 6633 6517 m_pcEntropyCoder->resetBits(); 6634 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode C);6518 m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode ); 6635 6519 const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits(); 6636 6520 minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV ); … … 6681 6565 } 6682 6566 6683 if( m_bUseSBACRD )6684 {6685 6567 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6686 }6687 6568 6688 6569 pcCU->setTransformSkipSubParts ( 1, TEXT_LUMA, uiAbsPartIdx, uiDepth ); … … 6715 6596 6716 6597 Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA]; 6717 assert(scalingListType < 6);6598 assert(scalingListType < SCALING_LIST_NUM); 6718 6599 6719 6600 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(), pcCoeffCurrY, trWidth, trHeight, scalingListType, true ); … … 6794 6675 } 6795 6676 6796 if( m_bUseSBACRD )6797 {6798 6677 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6799 }6800 6678 6801 6679 pcCU->setTransformSkipSubParts ( 1, TEXT_CHROMA_U, uiAbsPartIdx, pcCU->getDepth(0)+uiTrModeC ); … … 6811 6689 6812 6690 #if RDOQ_CHROMA_LAMBDA 6813 m_pcTrQuant->selectLambda(TEXT_CHROMA );6691 m_pcTrQuant->selectLambda(TEXT_CHROMA_U); 6814 6692 #endif 6815 6693 … … 6821 6699 curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr(); 6822 6700 m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset ); 6701 #if RDOQ_CHROMA_LAMBDA 6702 m_pcTrQuant->selectLambda(TEXT_CHROMA_V); 6703 #endif 6823 6704 m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV, 6824 6705 #if ADAPTIVE_QP_SELECTION … … 6844 6725 6845 6726 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_U]; 6846 assert(scalingListType < 6);6727 assert(scalingListType < SCALING_LIST_NUM); 6847 6728 6848 6729 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrU, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrU, trWidthC, trHeightC, scalingListType, true ); … … 6850 6731 uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6851 6732 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC 6852 #if WEIGHTED_CHROMA_DISTORTION6853 6733 , TEXT_CHROMA_U 6854 #endif6855 6734 ); 6856 6735 … … 6888 6767 6889 6768 Int scalingListType = 3 + g_eTTable[(Int)TEXT_CHROMA_V]; 6890 assert(scalingListType < 6);6769 assert(scalingListType < SCALING_LIST_NUM); 6891 6770 6892 6771 m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_CHROMA,REG_DCT, pcResiCurrV, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), pcCoeffCurrV, trWidthC, trHeightC, scalingListType, true ); … … 6894 6773 uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(), 6895 6774 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC 6896 #if WEIGHTED_CHROMA_DISTORTION6897 6775 , TEXT_CHROMA_V 6898 #endif6899 6776 ); 6900 6777 … … 6926 6803 } 6927 6804 6928 if( m_bUseSBACRD )6929 {6930 6805 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 6931 }6932 6933 6806 m_pcEntropyCoder->resetBits(); 6934 6807 6935 {6936 6808 if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 6937 6809 { 6938 6810 m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize ); 6939 6811 } 6940 } 6941 6942 { 6812 6943 6813 if( bCodeChroma ) 6944 6814 { … … 6948 6818 6949 6819 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 6950 }6951 6820 6952 6821 m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight, uiDepth, TEXT_LUMA ); … … 6972 6841 if( bCheckSplit ) 6973 6842 { 6974 if( m_bUseSBACRD &&bCheckFull )6843 if( bCheckFull ) 6975 6844 { 6976 6845 m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); … … 7012 6881 } 7013 6882 7014 if( m_bUseSBACRD )7015 {7016 6883 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_ROOT ] ); 7017 }7018 6884 m_pcEntropyCoder->resetBits(); 7019 6885 7020 {7021 6886 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true, TEXT_LUMA ); 7022 6887 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA ); 7023 6888 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U ); 7024 6889 xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V ); 7025 }7026 6890 7027 6891 uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits(); … … 7050 6914 } 7051 6915 assert( bCheckFull ); 7052 if( m_bUseSBACRD ) 7053 { 7054 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); 7055 } 7056 } 7057 6916 6917 m_pcRDGoOnSbacCoder->load( m_pppcRDSbacCoder[ uiDepth ][ CI_QT_TRAFO_TEST ] ); 6918 } 7058 6919 #if H_3D_VSO // M33 7059 6920 if( m_pcRdCost->getUseRenModel() && !m_pcRdCost->getUseEstimatedVSD() ) … … 7061 6922 UInt uiWidth = 1<< uiLog2TrSize; 7062 6923 UInt uiHeight = 1<< uiLog2TrSize; 7063 7064 6924 Pel* piSrc; 7065 6925 UInt uiSrcStride; 7066 7067 6926 if ( uiAbsSumY ) 7068 6927 { … … 7077 6936 uiSrcStride = pcPred->getStride (); 7078 6937 } 7079 7080 6938 m_pcRdCost->setRenModelData( pcCU, uiAbsPartIdx, piSrc, (Int) uiSrcStride, (Int) uiWidth, (Int) uiHeight ); 7081 6939 } 7082 6940 #endif 7083 7084 6941 rdCost += dSingleCost; 7085 6942 ruiBits += uiSingleBits; … … 7106 6963 const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2; 7107 6964 7108 {7109 6965 if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) 7110 6966 { 7111 6967 m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize ); 7112 6968 } 7113 } 7114 7115 { 6969 7116 6970 assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA ); 7117 6971 if( bSubdivAndCbf ) … … 7135 6989 } 7136 6990 } 7137 }7138 6991 7139 6992 if( !bSubdiv ) … … 7159 7012 if( bSubdivAndCbf ) 7160 7013 { 7161 {7162 7014 m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA, uiTrMode ); 7163 7015 } 7164 }7165 7016 else 7166 7017 { … … 7229 7080 if( bCodeChroma ) 7230 7081 { 7231 {7232 7082 m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC ); 7233 7083 } 7234 7084 } 7235 }7236 7085 else 7237 7086 { … … 7279 7128 UInt TEncSearch::xModeBitsIntra( TComDataCU* pcCU, UInt uiMode, UInt uiPU, UInt uiPartOffset, UInt uiDepth, UInt uiInitTrDepth ) 7280 7129 { 7281 if( m_bUseSBACRD )7282 {7283 7130 // Reload only contexts required for coding intra mode information 7284 7131 m_pcRDGoOnSbacCoder->loadIntraDirModeLuma( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); … … 7286 7133 m_pcRDGoOnSbacCoder->loadIntraDepthMode( m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST] ); 7287 7134 #endif 7288 }7289 7135 7290 7136 pcCU->setLumaIntraDirSubParts ( uiMode, uiPartOffset, uiDepth + uiInitTrDepth ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSearch.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 114 114 TEncSbac*** m_pppcRDSbacCoder; 115 115 TEncSbac* m_pcRDGoOnSbacCoder; 116 Bool m_bUseSBACRD;117 116 DistParam m_cDistParam; 118 117 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
r773 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 266 266 267 267 eSliceType=B_SLICE; 268 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;268 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 269 269 270 270 rpcSlice->setSliceType ( eSliceType ); … … 296 296 if(eSliceType!=I_SLICE) 297 297 { 298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->get SPS()->getUseLossless())))298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag()))) 299 299 { 300 300 #if H_MV … … 312 312 dQP += pdQPs[ rpcSlice->getPOC() ]; 313 313 } 314 #if !RATE_CONTROL_LAMBDA_DOMAIN315 if ( m_pcCfg->getUseRateCtrl())316 {317 dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());318 }319 #endif320 314 // ------------------------------------------------------------------------------------------------------------------ 321 315 // Lambda computation … … 399 393 // store lambda 400 394 m_pcRdCost ->setLambda( dLambda ); 401 402 #if H_3D_VSO403 m_pcRdCost->setUseLambdaScaleVSO ( (m_pcCfg->getUseVSO() || m_pcCfg->getForceLambdaScaleVSO()) && m_pcCfg->getIsDepth() );404 m_pcRdCost->setLambdaVSO ( dLambda * m_pcCfg->getLambdaScaleVSO() );405 406 // Should be moved to TEncTop407 408 // SAIT_VSO_EST_A0033409 m_pcRdCost->setDisparityCoeff( m_pcCfg->getDispCoeff() );410 411 // LGE_WVSO_A0119412 if( m_pcCfg->getUseWVSO() && m_pcCfg->getIsDepth() )413 {414 m_pcRdCost->setDWeight ( m_pcCfg->getDWeight() );415 m_pcRdCost->setVSOWeight( m_pcCfg->getVSOWeight() );416 m_pcRdCost->setVSDWeight( m_pcCfg->getVSDWeight() );417 }418 419 #endif420 421 #if WEIGHTED_CHROMA_DISTORTION422 395 // for RDO 423 396 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 424 Double weight = 1.0;397 Double weight[2] = { 1.0, 1.0 }; 425 398 Int qpc; 426 399 Int chromaQPOffset; … … 428 401 chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb(); 429 402 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 430 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset431 m_pcRdCost->setCbDistortionWeight(weight );403 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 404 m_pcRdCost->setCbDistortionWeight(weight[0]); 432 405 433 406 chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr(); 434 407 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 435 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 436 m_pcRdCost->setCrDistortionWeight(weight); 437 #endif 408 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 409 m_pcRdCost->setCrDistortionWeight(weight[1]); 410 411 const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])}; 438 412 439 413 #if RDOQ_CHROMA_LAMBDA 440 414 // for RDOQ 441 m_pcTrQuant->setLambda ( dLambda, dLambda / weight );415 m_pcTrQuant->setLambdas( lambdaArray ); 442 416 #else 443 417 m_pcTrQuant->setLambda( dLambda ); 444 418 #endif 445 419 446 #if SAO_CHROMA_LAMBDA447 420 // For SAO 448 rpcSlice ->setLambda( dLambda, dLambda / weight ); 449 #else 450 rpcSlice ->setLambda( dLambda ); 451 #endif 421 rpcSlice->setLambdas( lambdaArray ); 452 422 453 423 #if HB_LAMBDA_FOR_LDC … … 460 430 } 461 431 #else 462 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;432 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 463 433 #endif 464 434 … … 570 540 } 571 541 572 #if RATE_CONTROL_LAMBDA_DOMAIN573 542 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda ) 574 543 { … … 579 548 slice->setSliceQpBase ( sliceQP ); 580 549 m_pcRdCost ->setLambda( lambda ); 581 #if WEIGHTED_CHROMA_DISTORTION582 550 // for RDO 583 551 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 584 Double weight ;552 Double weight[2] = { 1.0, 1.0 }; 585 553 Int qpc; 586 554 Int chromaQPOffset; … … 588 556 chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb(); 589 557 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 590 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset591 m_pcRdCost->setCbDistortionWeight(weight );558 weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 559 m_pcRdCost->setCbDistortionWeight(weight[0]); 592 560 593 561 chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr(); 594 562 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 595 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset596 m_pcRdCost->setCrDistortionWeight(weight );597 #endif 563 weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 564 m_pcRdCost->setCrDistortionWeight(weight[1]); 565 598 566 599 567 #if RDOQ_CHROMA_LAMBDA 600 568 // for RDOQ 601 m_pcTrQuant->setLambda ( lambda, lambda / weight);569 m_pcTrQuant->setLambdas( lambdaArray ); 602 570 #else 603 571 m_pcTrQuant->setLambda( lambda ); 604 572 #endif 605 573 606 #if SAO_CHROMA_LAMBDA607 574 // For SAO 608 slice ->setLambda( lambda, lambda / weight ); 609 #else 610 slice ->setLambda( lambda ); 611 #endif 575 slice->setLambdas( lambdaArray ); 612 576 } 613 #else614 /**615 - lambda re-computation based on rate control QP616 */617 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)618 {619 Int qp;620 Double recalQP= (Double)changeQP;621 Double origQP = (Double)recalQP;622 Double lambda;623 624 // pre-compute lambda and QP values for all possible QP candidates625 for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )626 {627 // compute QP value628 recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);629 630 // compute lambda value631 Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );632 Int SHIFT_QP = 12;633 Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );634 #if FULL_NBIT635 Int bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);636 #else637 Int bitdepth_luma_qp_scale = 0;638 #endif639 Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;640 #if FULL_NBIT641 Double qp_temp_orig = (Double) recalQP - SHIFT_QP;642 #endif643 // Case #1: I or P-slices (key-frame)644 Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;645 if ( eSliceType==I_SLICE )646 {647 dQPFactor=0.57*dLambda_scale;648 }649 lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );650 651 if ( depth>0 )652 {653 #if FULL_NBIT654 lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )655 #else656 lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )657 #endif658 }659 660 // if hadamard is used in ME process661 if ( !m_pcCfg->getUseHADME() )662 {663 lambda *= 0.95;664 }665 666 qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );667 668 m_pdRdPicLambda[deltqQpIdx] = lambda;669 m_pdRdPicQp [deltqQpIdx] = recalQP;670 m_piRdPicQp [deltqQpIdx] = qp;671 }672 673 // obtain dQP = 0 case674 lambda = m_pdRdPicLambda[0];675 recalQP = m_pdRdPicQp [0];676 qp = m_piRdPicQp [0];677 678 if( pcSlice->getSliceType( ) != I_SLICE )679 {680 lambda *= m_pcCfg->getLambdaModifier( depth );681 }682 683 // store lambda684 m_pcRdCost ->setLambda( lambda );685 #if WEIGHTED_CHROMA_DISTORTION686 // for RDO687 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.688 Double weight = 1.0;689 Int qpc;690 Int chromaQPOffset;691 692 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();693 qpc = Clip3( 0, 57, qp + chromaQPOffset);694 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset695 m_pcRdCost->setCbDistortionWeight(weight);696 697 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();698 qpc = Clip3( 0, 57, qp + chromaQPOffset);699 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset700 m_pcRdCost->setCrDistortionWeight(weight);701 #endif702 703 #if RDOQ_CHROMA_LAMBDA704 // for RDOQ705 m_pcTrQuant->setLambda( lambda, lambda / weight );706 #else707 m_pcTrQuant->setLambda( lambda );708 #endif709 710 #if SAO_CHROMA_LAMBDA711 // For SAO712 pcSlice ->setLambda( lambda, lambda / weight );713 #else714 pcSlice ->setLambda( lambda );715 #endif716 }717 #endif718 577 // ==================================================================================================================== 719 578 // Public member functions … … 755 614 } 756 615 757 #if RATE_CONTROL_LAMBDA_DOMAIN758 616 if ( m_pcCfg->getUseRateCtrl() ) 759 617 { … … 761 619 assert(0); 762 620 } 763 #endif764 621 765 622 TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx()); … … 793 650 #endif 794 651 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 795 #if WEIGHTED_CHROMA_DISTORTION796 652 // for RDO 797 653 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 798 654 Int iQP = m_piRdPicQp [uiQpIdx]; 799 Double weight = 1.0;655 Double weight[2] = { 1.0, 1.0 }; 800 656 Int qpc; 801 657 Int chromaQPOffset; … … 803 659 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 804 660 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 805 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset806 m_pcRdCost->setCbDistortionWeight(weight );661 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 662 m_pcRdCost->setCbDistortionWeight(weight[0]); 807 663 808 664 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 809 665 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 810 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset811 m_pcRdCost->setCrDistortionWeight(weight );812 #endif 813 666 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 667 m_pcRdCost->setCrDistortionWeight(weight[1]); 668 669 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])}; 814 670 #if RDOQ_CHROMA_LAMBDA 815 671 // for RDOQ 816 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight);672 m_pcTrQuant->setLambdas( lambdaArray ); 817 673 #else 818 674 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 819 675 #endif 820 #if SAO_CHROMA_LAMBDA821 676 // For SAO 822 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 823 #else 824 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 825 #endif 677 pcSlice->setLambdas( lambdaArray ); 826 678 827 679 // try compress … … 857 709 #endif 858 710 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 859 #if WEIGHTED_CHROMA_DISTORTION860 711 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 861 712 Int iQP = m_piRdPicQp [uiQpIdxBest]; 862 Double weight = 1.0;713 Double weight[2] = { 1.0, 1.0 }; 863 714 Int qpc; 864 715 Int chromaQPOffset; … … 866 717 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 867 718 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 868 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset869 m_pcRdCost->setCbDistortionWeight(weight );719 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 720 m_pcRdCost->setCbDistortionWeight(weight[0]); 870 721 871 722 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 872 723 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 873 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset874 m_pcRdCost->setCrDistortionWeight(weight );875 #endif 876 724 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 725 m_pcRdCost->setCrDistortionWeight(weight[1]); 726 727 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])}; 877 728 #if RDOQ_CHROMA_LAMBDA 878 729 // for RDOQ 879 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );730 m_pcTrQuant->setLambdas( lambdaArray ); 880 731 #else 881 732 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 882 733 #endif 883 #if SAO_CHROMA_LAMBDA884 734 // For SAO 885 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 886 #else 887 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 888 #endif 735 pcSlice->setLambdas( lambdaArray ); 889 736 } 890 737 891 738 /** \param rpcPic picture class 892 739 */ 893 #if RATE_CONTROL_INTRA894 740 Void TEncSlice::calCostSliceI(TComPic*& rpcPic) 895 741 { … … 925 771 m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice); 926 772 } 927 #endif928 773 929 774 Void TEncSlice::compressSlice( TComPic*& rpcPic ) … … 943 788 944 789 // set entropy coder 945 if( m_pcCfg->getUseSBACRD() )946 {947 790 m_pcSbacCoder->init( m_pcBinCABAC ); 948 791 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); … … 952 795 pppcRDSbacCoder->setBinCountingEnableFlag( false ); 953 796 pppcRDSbacCoder->setBinsCoded( 0 ); 954 }955 else956 {957 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );958 m_pcEntropyCoder->resetEntropy ();959 m_pcEntropyCoder->setBitstream ( m_pcBitCounter );960 }961 797 962 798 //------------------------------------------------------------------------------ … … 1016 852 } 1017 853 #endif 1018 if( m_pcCfg->getUseSBACRD() )1019 {1020 854 iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); 1021 855 uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1; … … 1037 871 ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1038 872 } 1039 }1040 //if( m_pcCfg->getUseSBACRD() )1041 {1042 873 delete[] m_pcBufferLowLatSbacCoders; 1043 874 delete[] m_pcBufferLowLatBinCoderCABACs; … … 1050 881 for (UInt ui = 0; ui < uiTilesAcross; ui++) 1051 882 m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); //init. state 1052 } 883 1053 884 UInt uiWidthInLCUs = rpcPic->getPicSym()->getFrameWidthInCU(); 1054 885 //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU(); … … 1121 952 } 1122 953 #endif 1123 #if !RATE_CONTROL_LAMBDA_DOMAIN1124 if(m_pcCfg->getUseRateCtrl())1125 {1126 #if KWU_RC_MADPRED_E02271127 if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())1128 {1129 Double zn, zf, focallength, position, camshift;1130 Double basepos;1131 Bool bInterpolated;1132 Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();1133 1134 pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);1135 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);1136 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);1137 1138 m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));1139 }1140 #endif1141 if(m_pcRateCtrl->calculateUnitQP())1142 {1143 xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );1144 }1145 }1146 #endif1147 954 // inherit from TR if necessary, select substream to use. 1148 if( m_pcCfg->getUseSBACRD() )1149 {1150 955 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1151 956 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1192 997 } 1193 998 m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code 1194 }1195 999 1196 1000 // reset the entropy coder … … 1210 1014 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); 1211 1015 } 1212 // if RD based on SBAC is used 1213 if( m_pcCfg->getUseSBACRD() ) 1214 { 1016 1215 1017 // set go-on entropy coder 1216 1018 m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice ); … … 1219 1021 ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true); 1220 1022 1221 #if RATE_CONTROL_LAMBDA_DOMAIN1222 1023 Double oldLambda = m_pcRdCost->getLambda(); 1223 1024 if ( m_pcCfg->getUseRateCtrl() ) … … 1227 1028 Double bpp = -1.0; 1228 1029 1229 #if M0036_RC_IMPROVEMENT1230 1030 if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() ) 1231 #else1232 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )1233 #endif1234 1031 { 1235 1032 estQP = pcSlice->getSliceQp(); … … 1255 1052 { 1256 1053 #endif 1257 #if RATE_CONTROL_INTRA1258 1054 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType()); 1259 1055 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE) … … 1266 1062 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() ); 1267 1063 } 1268 #else1269 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();1270 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );1271 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );1272 #endif1273 #if KWU_RC_MADPRED_E02271274 }1275 #endif1276 1064 #if KWU_RC_MADPRED_E0227 1277 1065 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp ); … … 1281 1069 1282 1070 m_pcRdCost->setLambda(estLambda); 1283 #if M0036_RC_IMPROVEMENT1284 1071 #if RDOQ_CHROMA_LAMBDA 1285 1072 // set lambda for RDOQ 1286 1073 Double weight=m_pcRdCost->getChromaWeight(); 1287 m_pcTrQuant->setLambda( estLambda, estLambda / weight ); 1074 const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) }; 1075 m_pcTrQuant->setLambdas( lambdaArray ); 1288 1076 #else 1289 1077 m_pcTrQuant->setLambda( estLambda ); 1290 #endif1291 1078 #endif 1292 1079 } … … 1295 1082 pcCU->getSlice()->setSliceQpBase( estQP ); 1296 1083 } 1297 #endif1298 1084 1299 1085 // run CU encoder 1300 1086 m_pcCuEncoder->compressCU( pcCU ); 1301 1087 1302 #if !TICKET_1090_FIX1303 #if RATE_CONTROL_LAMBDA_DOMAIN1304 if ( m_pcCfg->getUseRateCtrl() )1305 {1306 #if !M0036_RC_IMPROVEMENT1307 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD();1308 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1309 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1310 Double MAD = (Double)SAD / (Double)(height * width);1311 MAD = MAD * MAD;1312 ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;1313 #endif1314 1315 Int actualQP = g_RCInvalidQPValue;1316 Double actualLambda = m_pcRdCost->getLambda();1317 Int actualBits = pcCU->getTotalBits();1318 Int numberOfEffectivePixels = 0;1319 for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )1320 {1321 if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )1322 {1323 numberOfEffectivePixels = numberOfEffectivePixels + 16;1324 break;1325 }1326 }1327 1328 if ( numberOfEffectivePixels == 0 )1329 {1330 actualQP = g_RCInvalidQPValue;1331 }1332 else1333 {1334 actualQP = pcCU->getQP( 0 );1335 }1336 m_pcRdCost->setLambda(oldLambda);1337 #if RATE_CONTROL_INTRA1338 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,1339 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );1340 #else1341 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1342 #endif1343 }1344 #endif1345 #endif1346 1347 1088 // restore entropy coder to an initial stage 1348 1089 m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice ); … … 1366 1107 break; 1367 1108 } 1368 if( m_pcCfg->getUseSBACRD() )1369 {1370 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );1371 1109 1110 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] ); 1372 1111 //Store probabilties of second LCU in line into buffer 1373 1112 if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro()) … … 1375 1114 m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]); 1376 1115 } 1377 } 1378 1379 #if TICKET_1090_FIX 1380 #if RATE_CONTROL_LAMBDA_DOMAIN 1116 1381 1117 if ( m_pcCfg->getUseRateCtrl() ) 1382 1118 { 1383 #if !M0036_RC_IMPROVEMENT ||KWU_RC_MADPRED_E02271119 #if KWU_RC_MADPRED_E0227 1384 1120 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD(); 1385 1121 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() ); … … 1413 1149 m_pcRdCost->setLambda(oldLambda); 1414 1150 1415 #if RATE_CONTROL_INTRA1416 1151 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 1417 1152 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() ); 1418 #else1419 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1420 #endif1421 }1422 #endif1423 #endif1424 }1425 // other case: encodeCU is not called1426 else1427 {1428 m_pcCuEncoder->compressCU( pcCU );1429 m_pcCuEncoder->encodeCU( pcCU );1430 if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)1431 {1432 pcSlice->setNextSlice( true );1433 break;1434 }1435 if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())1436 {1437 pcSlice->setNextSliceSegment( true );1438 break;1439 }1440 1153 } 1441 1154 … … 1443 1156 m_dPicRdCost += pcCU->getTotalCost(); 1444 1157 m_uiPicDist += pcCU->getTotalDistortion(); 1445 #if !RATE_CONTROL_LAMBDA_DOMAIN1446 if(m_pcCfg->getUseRateCtrl())1447 {1448 m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));1449 m_pcRateCtrl->updataRCUnitStatus();1450 }1451 #endif1452 1158 } 1453 1159 if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled) … … 1455 1161 pcSlice->setNextSlice( true ); 1456 1162 } 1163 if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES) 1164 { 1165 if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr()) 1166 { 1167 pcSlice->setNextSlice( true ); 1168 } 1169 else 1170 { 1171 pcSlice->setNextSliceSegment( true ); 1172 } 1173 } 1457 1174 if( depSliceSegmentsEnabled ) 1458 1175 { … … 1464 1181 } 1465 1182 xRestoreWPparam( pcSlice ); 1466 #if !RATE_CONTROL_LAMBDA_DOMAIN1467 if(m_pcCfg->getUseRateCtrl())1468 {1469 m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);1470 }1471 #endif1472 1183 } 1473 1184 … … 1582 1293 uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) ) 1583 1294 { 1584 if( m_pcCfg->getUseSBACRD() )1585 {1586 1295 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1587 1296 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1632 1341 } 1633 1342 m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]); //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder) 1634 } 1343 1635 1344 // reset the entropy coder 1636 1345 if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() && // must be first CU of tile … … 1676 1385 #endif 1677 1386 TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr ); 1678 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 1679 { 1680 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1681 Int iNumCuInWidth = saoParam->numCuInWidth; 1682 Int iCUAddrInSlice = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); 1683 Int iCUAddrUpInSlice = iCUAddrInSlice - iNumCuInWidth; 1684 Int rx = uiCUAddr % iNumCuInWidth; 1685 Int ry = uiCUAddr / iNumCuInWidth; 1686 Int allowMergeLeft = 1; 1687 Int allowMergeUp = 1; 1688 if (rx!=0) 1689 { 1690 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1691 { 1692 allowMergeLeft = 0; 1693 } 1694 } 1695 if (ry!=0) 1696 { 1697 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1698 { 1699 allowMergeUp = 0; 1700 } 1701 } 1702 Int addr = pcCU->getAddr(); 1703 allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0); 1704 allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0); 1705 if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] ) 1706 { 1707 Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag; 1708 Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag; 1709 if (allowMergeLeft) 1710 { 1711 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft); 1712 } 1713 else 1714 { 1715 mergeLeft = 0; 1716 } 1717 if(mergeLeft == 0) 1718 { 1719 if (allowMergeUp) 1720 { 1721 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp); 1722 } 1723 else 1724 { 1725 mergeUp = 0; 1726 } 1727 if(mergeUp == 0) 1728 { 1729 for (Int compIdx=0;compIdx<3;compIdx++) 1730 { 1731 if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1])) 1732 { 1733 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx); 1734 } 1735 } 1736 } 1737 } 1738 } 1739 } 1740 else if (pcSlice->getSPS()->getUseSAO()) 1741 { 1742 Int addr = pcCU->getAddr(); 1743 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1744 for (Int cIdx=0; cIdx<3; cIdx++) 1745 { 1746 SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]); 1747 if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma())) 1748 { 1749 saoLcuParam->mergeUpFlag = 0; 1750 saoLcuParam->mergeLeftFlag = 0; 1751 saoLcuParam->subTypeIdx = 0; 1752 saoLcuParam->typeIdx = -1; 1753 saoLcuParam->offset[0] = 0; 1754 saoLcuParam->offset[1] = 0; 1755 saoLcuParam->offset[2] = 0; 1756 saoLcuParam->offset[3] = 0; 1757 } 1387 if ( pcSlice->getSPS()->getUseSAO() ) 1388 { 1389 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 1390 { 1391 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr]; 1392 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1393 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 1394 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 1395 1396 Bool leftMergeAvail = false; 1397 Bool aboveMergeAvail= false; 1398 //merge left condition 1399 Int rx = (uiCUAddr % uiWidthInLCUs); 1400 if(rx > 0) 1401 { 1402 leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1); 1403 } 1404 1405 //merge up condition 1406 Int ry = (uiCUAddr / uiWidthInLCUs); 1407 if(ry > 0) 1408 { 1409 aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs); 1410 } 1411 1412 m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail); 1758 1413 } 1759 1414 } … … 1773 1428 g_bJustDoIt = g_bEncDecTraceDisable; 1774 1429 #endif 1775 if( m_pcCfg->getUseSBACRD() )1776 {1777 1430 pcSbacCoders[uiSubStrm].load(m_pcSbacCoder); //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder 1778 1431 … … 1784 1437 } 1785 1438 } 1786 #if H_3D_QTLPC1787 rpcPic->setReduceBitsFlag(false);1788 #endif1789 }1790 1439 if( depSliceSegmentsEnabled ) 1791 1440 { -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncSlice.h
r833 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 107 107 UInt m_uiSliceIdx; 108 108 std::vector<TEncSbac*> CTXMem; 109 110 109 #if MTK_DDD_G0063 111 110 Int m_iDDDScale; … … 129 128 Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField ); 130 129 #endif 131 #if RATE_CONTROL_LAMBDA_DOMAIN132 130 Void resetQP ( TComPic* pic, Int sliceQP, Double lambda ); 133 #else134 Void xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);135 #endif136 131 // compress and encode slice 137 132 Void precompressSlice ( TComPic*& rpcPic ); ///< precompress slice for multi-loop opt. 138 133 Void compressSlice ( TComPic*& rpcPic ); ///< analysis stage of slice 139 #if RATE_CONTROL_INTRA140 134 Void calCostSliceI ( TComPic*& rpcPic ); 141 #endif142 135 Void encodeSlice ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams ); 143 136 -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncTop.cpp
r773 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 106 106 if (m_bUseSAO) 107 107 { 108 m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary()); 109 m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization()); 110 m_cEncSAO.setMaxNumOffsetsPerPic(getMaxNumOffsetsPerPic()); 111 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight ); 112 m_cEncSAO.createEncBuffer(); 108 m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 109 #if SAO_ENCODE_ALLOW_USE_PREDEBLOCK 110 m_cEncSAO.createEncData(getSaoLcuBoundary()); 111 #else 112 m_cEncSAO.createEncData(); 113 #endif 113 114 } 114 115 #if ADAPTIVE_QP_SELECTION … … 120 121 m_cLoopFilter. create( g_uiMaxCUDepth ); 121 122 122 #if RATE_CONTROL_LAMBDA_DOMAIN123 123 if ( m_RCEnableRateControl ) 124 124 { … … 131 131 #endif 132 132 } 133 #else134 #if KWU_FIX_URQ135 if(m_enableRateCtrl)136 #endif137 m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);138 #endif139 // if SBAC-based RD optimization is used140 if( m_bUseSBACRD )141 {142 133 m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1]; 143 134 #if FAST_BIT_EST … … 168 159 } 169 160 } 170 }171 161 172 162 /** … … 195 185 m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] ); 196 186 } 197 if( m_bUseSBACRD ) 198 { 187 199 188 m_ppppcRDSbacCoders = new TEncSbac*** [iNumSubstreams]; 200 189 m_ppppcBinCodersCABAC = new TEncBinCABAC***[iNumSubstreams]; … … 218 207 } 219 208 } 220 }221 209 222 210 Void TEncTop::destroy () … … 228 216 if (m_cSPS.getUseSAO()) 229 217 { 218 m_cEncSAO.destroyEncData(); 230 219 m_cEncSAO.destroy(); 231 m_cEncSAO.destroyEncBuffer();232 220 } 233 221 m_cLoopFilter. destroy(); 234 222 m_cRateCtrl. destroy(); 235 // SBAC RD 236 if( m_bUseSBACRD ) 237 { 223 238 224 Int iDepth; 239 225 for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ ) … … 276 262 delete[] m_ppppcRDSbacCoders; 277 263 delete[] m_ppppcBinCodersCABAC; 278 }279 264 delete[] m_pcSbacCoders; 280 265 delete[] m_pcBinCoderCABACs; … … 439 424 #endif 440 425 441 #if RATE_CONTROL_LAMBDA_DOMAIN442 426 if ( m_RCEnableRateControl ) 443 427 { 444 428 m_cRateCtrl.initRCGOP( m_iNumPicRcvd ); 445 429 } 446 #endif447 448 430 #if H_MV 449 431 } … … 457 439 #endif 458 440 459 #if RATE_CONTROL_LAMBDA_DOMAIN460 441 if ( m_RCEnableRateControl ) 461 442 { 462 443 m_cRateCtrl.destroyRCGOP(); 463 444 } 464 #endif465 445 466 446 iNumEncoded = m_iNumPicRcvd; … … 510 490 TComPic *pcTopField; 511 491 xGetNewPicBuffer( pcTopField ); 512 pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);513 492 pcTopField->setReconMark (false); 514 493 … … 532 511 Pel * pcTopFieldV = pcTopField->getPicYuvOrg()->getCrAddr(); 533 512 534 // compute image characteristics535 if ( getUseAdaptiveQP() )536 {537 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );538 }539 540 513 /* -- Defield -- */ 541 514 … … 546 519 separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); 547 520 521 // compute image characteristics 522 if ( getUseAdaptiveQP() ) 523 { 524 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) ); 525 } 548 526 } 549 527 … … 562 540 TComPic* pcBottomField; 563 541 xGetNewPicBuffer( pcBottomField ); 564 pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);565 542 pcBottomField->setReconMark (false); 566 543 567 TComPicYuv* rpcPicYuvRec = new TComPicYuv;544 TComPicYuv* rpcPicYuvRec; 568 545 if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) 569 546 { … … 572 549 else 573 550 { 551 rpcPicYuvRec = new TComPicYuv; 574 552 rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth ); 575 553 } … … 595 573 Pel * pcBottomFieldV = pcBottomField->getPicYuvOrg()->getCrAddr(); 596 574 597 // Compute image characteristics598 if ( getUseAdaptiveQP() )599 {600 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );601 }602 603 575 /* -- Defield -- */ 604 576 … … 609 581 separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop); 610 582 583 // Compute image characteristics 584 if ( getUseAdaptiveQP() ) 585 { 586 m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) ); 587 } 611 588 } 612 589 … … 624 601 m_uiNumAllPicCoded += iNumEncoded; 625 602 } 626 #endif627 628 629 603 630 604 // ==================================================================================================================== … … 671 645 rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 672 646 m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics); 673 }674 if (getUseSAO())675 {676 rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);677 647 } 678 648 m_cListPic.pushBack( rpcPic ); … … 760 730 761 731 m_cSPS.setTMVPFlagsPresent(false); 762 m_cSPS.setUseLossless ( m_useLossless );763 732 764 733 m_cSPS.setMaxTrSize ( 1 << m_uiQuadtreeTULog2MaxSize ); … … 794 763 m_cSPS.setMaxTLayers( m_maxTempLayer ); 795 764 m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false ); 796 for ( i = 0; i < m _cSPS.getMaxTLayers(); i++ )765 for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ ) 797 766 { 798 767 m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i); … … 860 829 m_cPPS.setSPSId( getLayerIdInVps() ); 861 830 #endif 862 863 831 #if H_3D 864 832 m_cPPS.setDLT( getDLT() ); 865 833 #endif 866 867 834 m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred ); 868 835 Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false; 869 836 870 Int lowestQP = - m_cSPS.getQpBDOffsetY();871 872 if(getUseLossless())873 {874 if ((getMaxCuDQPDepth() == 0) && (getMaxDeltaQP() == 0 ) && (getQP() == lowestQP) )875 {876 bUseDQP = false;877 }878 else879 {880 bUseDQP = true;881 }882 }883 else884 {885 if(bUseDQP == false)886 {887 837 if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP()) 888 838 { 889 839 bUseDQP = true; 890 840 } 891 }892 }893 841 894 842 if(bUseDQP) … … 905 853 } 906 854 907 #if RATE_CONTROL_LAMBDA_DOMAIN908 855 if ( m_RCEnableRateControl ) 909 856 { … … 912 859 m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) ); 913 860 } 914 #endif915 #if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ916 if ( m_enableRateCtrl )917 {918 m_cPPS.setUseDQP(true);919 m_cPPS.setMaxCuDQPDepth( 0 );920 m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );921 }922 #endif923 861 924 862 m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset ); -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/TEncTop.h
r655 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 82 82 // encoder search 83 83 TEncSearch m_cSearch; ///< encoder search class 84 TEncEntropy* m_pcEntropyCoder; ///< entropy encoder84 //TEncEntropy* m_pcEntropyCoder; ///< entropy encoder 85 85 TEncCavlc* m_pcCavlcCoder; ///< CAVLC encoder 86 86 // coding tool -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * -
branches/HTM-10.0rc1-dev0/source/Lib/TLibEncoder/WeightPredAnalysis.h
r608 r837 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 *
Note: See TracChangeset for help on using the changeset viewer.