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