66 m_uhTotalDepth = uhTotalDepth + 1;
67 m_ppcBestCU =
new TComDataCU*[m_uhTotalDepth-1];
68 m_ppcTempCU =
new TComDataCU*[m_uhTotalDepth-1];
70 m_ppcPredYuvBest =
new TComYuv*[m_uhTotalDepth-1];
71 m_ppcResiYuvBest =
new TComYuv*[m_uhTotalDepth-1];
72 m_ppcRecoYuvBest =
new TComYuv*[m_uhTotalDepth-1];
73 m_ppcPredYuvTemp =
new TComYuv*[m_uhTotalDepth-1];
74 m_ppcResiYuvTemp =
new TComYuv*[m_uhTotalDepth-1];
75 m_ppcRecoYuvTemp =
new TComYuv*[m_uhTotalDepth-1];
76 m_ppcOrigYuv =
new TComYuv*[m_uhTotalDepth-1];
79 for( i=0 ; i<m_uhTotalDepth-1 ; i++)
81 uiNumPartitions = 1<<( ( m_uhTotalDepth - i - 1 )<<1 );
82 UInt uiWidth = uiMaxWidth >> i;
83 UInt uiHeight = uiMaxHeight >> i;
85 m_ppcBestCU[i] =
new TComDataCU; m_ppcBestCU[i]->
create( chromaFormat, uiNumPartitions, uiWidth, uiHeight,
false, uiMaxWidth >> (m_uhTotalDepth - 1) );
86 m_ppcTempCU[i] =
new TComDataCU; m_ppcTempCU[i]->
create( chromaFormat, uiNumPartitions, uiWidth, uiHeight,
false, uiMaxWidth >> (m_uhTotalDepth - 1) );
88 m_ppcPredYuvBest[i] =
new TComYuv; m_ppcPredYuvBest[i]->
create(uiWidth, uiHeight, chromaFormat);
89 m_ppcResiYuvBest[i] =
new TComYuv; m_ppcResiYuvBest[i]->
create(uiWidth, uiHeight, chromaFormat);
90 m_ppcRecoYuvBest[i] =
new TComYuv; m_ppcRecoYuvBest[i]->
create(uiWidth, uiHeight, chromaFormat);
92 m_ppcPredYuvTemp[i] =
new TComYuv; m_ppcPredYuvTemp[i]->
create(uiWidth, uiHeight, chromaFormat);
93 m_ppcResiYuvTemp[i] =
new TComYuv; m_ppcResiYuvTemp[i]->
create(uiWidth, uiHeight, chromaFormat);
94 m_ppcRecoYuvTemp[i] =
new TComYuv; m_ppcRecoYuvTemp[i]->
create(uiWidth, uiHeight, chromaFormat);
96 m_ppcOrigYuv [i] =
new TComYuv; m_ppcOrigYuv [i]->
create(uiWidth, uiHeight, chromaFormat);
100 m_stillToCodeChromaQpOffsetFlag =
false;
101 m_cuChromaQpOffsetIdxPlus1 = 0;
102 m_bFastDeltaQP =
false;
117 for( i=0 ; i<m_uhTotalDepth-1 ; i++)
121 m_ppcBestCU[i]->destroy();
delete m_ppcBestCU[i]; m_ppcBestCU[i] =
NULL;
125 m_ppcTempCU[i]->destroy();
delete m_ppcTempCU[i]; m_ppcTempCU[i] =
NULL;
127 if(m_ppcPredYuvBest[i])
129 m_ppcPredYuvBest[i]->destroy();
delete m_ppcPredYuvBest[i]; m_ppcPredYuvBest[i] =
NULL;
131 if(m_ppcResiYuvBest[i])
133 m_ppcResiYuvBest[i]->destroy();
delete m_ppcResiYuvBest[i]; m_ppcResiYuvBest[i] =
NULL;
135 if(m_ppcRecoYuvBest[i])
137 m_ppcRecoYuvBest[i]->destroy();
delete m_ppcRecoYuvBest[i]; m_ppcRecoYuvBest[i] =
NULL;
139 if(m_ppcPredYuvTemp[i])
141 m_ppcPredYuvTemp[i]->destroy();
delete m_ppcPredYuvTemp[i]; m_ppcPredYuvTemp[i] =
NULL;
143 if(m_ppcResiYuvTemp[i])
145 m_ppcResiYuvTemp[i]->destroy();
delete m_ppcResiYuvTemp[i]; m_ppcResiYuvTemp[i] =
NULL;
147 if(m_ppcRecoYuvTemp[i])
149 m_ppcRecoYuvTemp[i]->destroy();
delete m_ppcRecoYuvTemp[i]; m_ppcRecoYuvTemp[i] =
NULL;
153 m_ppcOrigYuv[i]->destroy();
delete m_ppcOrigYuv[i]; m_ppcOrigYuv[i] =
NULL;
158 delete [] m_ppcBestCU;
163 delete [] m_ppcTempCU;
169 delete [] m_ppcPredYuvBest;
170 m_ppcPredYuvBest =
NULL;
174 delete [] m_ppcResiYuvBest;
175 m_ppcResiYuvBest =
NULL;
179 delete [] m_ppcRecoYuvBest;
180 m_ppcRecoYuvBest =
NULL;
184 delete [] m_ppcPredYuvTemp;
185 m_ppcPredYuvTemp =
NULL;
189 delete [] m_ppcResiYuvTemp;
190 m_ppcResiYuvTemp =
NULL;
194 delete [] m_ppcRecoYuvTemp;
195 m_ppcRecoYuvTemp =
NULL;
199 delete [] m_ppcOrigYuv;
208 m_pcEncCfg = pcEncTop;
221 initLumaDeltaQpLUT();
243 #if ADAPTIVE_QP_SELECTION
244 if( m_pcEncCfg->getUseAdaptQpSelect() )
248 xCtuCollectARLStats( pCtu );
264 setCodeChromaQpAdjFlag(
true);
268 xEncodeCU( pCtu, 0, 0 );
286 Int lastDeltaQPValue=0;
287 std::size_t nextSparseIndex=0;
290 while (nextSparseIndex < mapping.
mapping.size() && index>=mapping.
mapping[nextSparseIndex].first)
292 lastDeltaQPValue=mapping.
mapping[nextSparseIndex].second;
295 m_lumaLevelToDeltaQPLUT[index]=lastDeltaQPValue;
323 for (
Int y = 0; y < height; y++)
325 for (
Int x = 0; x < width; x++)
331 avg = (
Double)sum/(width*height);
337 for (
Int y = 0; y < height; y++)
339 for (
Int x = 0; x < width; x++)
349 avg = (
Double)maxVal * m_pcEncCfg->getLumaLevelToDeltaQPMapping().maxMethodWeight;
353 Int QP = m_lumaLevelToDeltaQPLUT[lumaIdx];
383 bTestMergeAMP_Hor =
true;
384 bTestMergeAMP_Ver =
true;
391 bTestMergeAMP_Hor =
true;
395 bTestMergeAMP_Ver =
true;
401 bTestMergeAMP_Hor =
true;
402 bTestMergeAMP_Ver =
true;
407 bTestAMP_Hor =
false;
408 bTestAMP_Ver =
false;
420 bTestAMP_Hor =
false;
421 bTestAMP_Ver =
false;
452 Bool doNotBlockPu =
true;
453 Bool earlyDetectionSkipMode =
false;
456 const UInt uiRPelX = uiLPelX + rpcBestCU->
getWidth(0) - 1;
461 Int iBaseQP = xComputeQP( rpcBestCU, uiDepth );
464 Bool isAddLowestQP =
false;
470 Int idQP = m_pcEncCfg->getMaxDeltaQP();
476 iMinQP = rpcTempCU->
getQP(0);
477 iMaxQP = rpcTempCU->
getQP(0);
480 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
485 m_lumaQPOffset = calculateLumaDQP(rpcTempCU, 0, m_ppcOrigYuv[uiDepth]);
491 if ( m_pcEncCfg->getUseRateCtrl() )
493 iMinQP = m_pcRateCtrl->getRCQP();
494 iMaxQP = m_pcRateCtrl->getRCQP();
499 const Int lowestQP = iMinQP;
503 isAddLowestQP =
true;
505 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
517 for (
Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
519 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
525 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && uiDepth <= pps.
getMaxCuDQPDepth() )
527 getSliceEncoder()->updateLambda(pcSlice, iQP);
530 m_cuChromaQpOffsetIdxPlus1 = 0;
543 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
549 if(m_pcEncCfg->getUseEarlySkipDetection())
552 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
556 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
558 if(!m_pcEncCfg->getUseEarlySkipDetection())
562 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
563 if(m_pcEncCfg->getUseCbfFastMode())
576 if(!earlyDetectionSkipMode)
578 for (
Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
580 const Bool bIsLosslessMode = isAddLowestQP && (iQP == iMinQP);
587 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
599 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
606 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
615 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
626 Bool bTestAMP_Hor =
false, bTestAMP_Ver =
false;
629 Bool bTestMergeAMP_Hor =
false, bTestMergeAMP_Ver =
false;
631 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);
633 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver);
642 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
651 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
659 else if ( bTestMergeAMP_Hor )
664 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
673 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
688 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
697 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
701 else if ( bTestMergeAMP_Ver )
706 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
715 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
721 xCheckRDCostInter( rpcBestCU, rpcTempCU,
SIZE_2NxnU );
722 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
723 xCheckRDCostInter( rpcBestCU, rpcTempCU,
SIZE_2NxnD );
724 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
725 xCheckRDCostInter( rpcBestCU, rpcTempCU,
SIZE_nLx2N );
726 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
728 xCheckRDCostInter( rpcBestCU, rpcTempCU,
SIZE_nRx2N );
729 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
739 ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
747 ((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (
755 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
761 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
773 if((uiBestBits > uiRawBits) || (rpcBestCU->
getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))
775 xCheckIntraPCM (rpcBestCU, rpcTempCU);
776 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
789 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][
CI_NEXT_BEST]);
790 m_pcEntropyCoder->resetBits();
791 m_pcEntropyCoder->encodeSplitFlag( rpcBestCU, 0, uiDepth,
true );
792 rpcBestCU->
getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits();
795 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]);
802 xFillPCMBuffer(rpcBestCU, m_ppcOrigYuv[uiDepth]);
807 Int idQP = m_pcEncCfg->getMaxDeltaQP();
818 const Int iStartQP = rpcTempCU->
getQP(0);
823 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() )
829 if ( m_pcEncCfg->getUseRateCtrl() )
831 iMinQP = m_pcRateCtrl->getRCQP();
832 iMaxQP = m_pcRateCtrl->getRCQP();
835 if ( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
845 Double splitTotalCost = 0;
847 for (
Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
849 const Bool bIsLosslessMode =
false;
851 rpcTempCU->
initEstData( uiDepth, iQP, bIsLosslessMode );
853 UChar uhNextDepth = uiDepth+1;
854 TComDataCU* pcSubBestPartCU = m_ppcBestCU[uhNextDepth];
855 TComDataCU* pcSubTempPartCU = m_ppcTempCU[uhNextDepth];
858 for (
UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++ )
860 pcSubBestPartCU->
initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );
861 pcSubTempPartCU->
initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP );
865 if ( 0 == uiPartUnitIdx)
887 xCompressCU( pcSubBestPartCU, pcSubTempPartCU, uhNextDepth );
890 rpcTempCU->
copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
891 xCopyYuv2Tmp( pcSubBestPartCU->
getTotalNumPart()*uiPartUnitIdx, uhNextDepth );
892 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.
getMaxCuDQPDepth() >= 1 )
899 pcSubBestPartCU->
copyToPic( uhNextDepth );
900 rpcTempCU->
copyPartFrom( pcSubBestPartCU, uiPartUnitIdx, uhNextDepth );
904 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uhNextDepth][
CI_NEXT_BEST]);
907 m_pcEntropyCoder->resetBits();
908 m_pcEntropyCoder->encodeSplitFlag( rpcTempCU, 0, uiDepth,
true );
909 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.
getMaxCuDQPDepth() >= 1 )
911 Int splitBits = m_pcEntropyCoder->getNumberOfWrittenBits();
912 Double splitBitCost = m_pcRdCost->calcRdCost( splitBits, 0 );
913 splitTotalCost += splitBitCost;
916 rpcTempCU->
getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits();
920 if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() && pps.
getMaxCuDQPDepth() >= 1 )
931 Bool hasResidual =
false;
945 m_pcEntropyCoder->resetBits();
946 m_pcEntropyCoder->encodeQP( rpcTempCU, 0,
false );
947 rpcTempCU->
getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits();
951 Bool foundNonZeroCbf =
false;
953 assert( foundNonZeroCbf );
961 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][
CI_TEMP_BEST]);
978 if(isEndOfSlice||isEndOfSliceSegment)
1020 if ( isLastSubCUOfCtu )
1026 m_pcEntropyCoder->encodeTerminatingBit( 0 );
1040 if ( m_pcEncCfg->getUseAdaptiveQP() )
1045 UInt uiAQUPosX = pcCU->
getCUPelX() / pcAQLayer->getAQPartWidth();
1046 UInt uiAQUPosY = pcCU->
getCUPelY() / pcAQLayer->getAQPartHeight();
1047 UInt uiAQUStride = pcAQLayer->getAQPartStride();
1050 Double dMaxQScale = pow(2.0, m_pcEncCfg->getQPAdaptationRange()/6.0);
1051 Double dAvgAct = pcAQLayer->getAvgActivity();
1053 Double dNormAct = (dMaxQScale*dCUAct + dAvgAct) / (dCUAct + dMaxQScale*dAvgAct);
1054 Double dQpOffset = log(dNormAct) / log(2.0) * 6.0;
1055 iQpOffset =
Int(floor( dQpOffset + 0.49999 ));
1077 Bool bBoundary =
false;
1079 const UInt uiRPelX = uiLPelX + (maxCUWidth>>uiDepth) - 1;
1081 const UInt uiBPelY = uiTPelY + (maxCUHeight>>uiDepth) - 1;
1085 m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
1102 setCodeChromaQpAdjFlag(
true);
1105 for (
UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
1111 xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
1124 setCodeChromaQpAdjFlag(
true);
1129 m_pcEntropyCoder->encodeCUTransquantBypassFlag( pcCU, uiAbsPartIdx );
1134 m_pcEntropyCoder->encodeSkipFlag( pcCU, uiAbsPartIdx );
1139 m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx );
1140 finishCU(pcCU,uiAbsPartIdx);
1144 m_pcEntropyCoder->encodePredMode( pcCU, uiAbsPartIdx );
1145 m_pcEntropyCoder->encodePartSize( pcCU, uiAbsPartIdx, uiDepth );
1149 m_pcEntropyCoder->encodeIPCMInfo( pcCU, uiAbsPartIdx );
1154 finishCU(pcCU,uiAbsPartIdx);
1160 m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
1163 Bool bCodeDQP = getdQPFlag();
1164 Bool codeChromaQpAdj = getCodeChromaQpAdjFlag();
1165 m_pcEntropyCoder->encodeCoeff( pcCU, uiAbsPartIdx, uiDepth, bCodeDQP, codeChromaQpAdj );
1166 setCodeChromaQpAdjFlag( codeChromaQpAdj );
1167 setdQPFlag( bCodeDQP );
1170 finishCU(pcCU,uiAbsPartIdx);
1176 Int diff[64], m1[8][8], m2[8][8], m3[8][8], iSumHad = 0;
1178 for( k = 0; k < 64; k += 8 )
1180 diff[k+0] = piOrg[0] ;
1181 diff[k+1] = piOrg[1] ;
1182 diff[k+2] = piOrg[2] ;
1183 diff[k+3] = piOrg[3] ;
1184 diff[k+4] = piOrg[4] ;
1185 diff[k+5] = piOrg[5] ;
1186 diff[k+6] = piOrg[6] ;
1187 diff[k+7] = piOrg[7] ;
1189 piOrg += iStrideOrg;
1193 for (j=0; j < 8; j++)
1196 m2[j][0] = diff[jj ] + diff[jj+4];
1197 m2[j][1] = diff[jj+1] + diff[jj+5];
1198 m2[j][2] = diff[jj+2] + diff[jj+6];
1199 m2[j][3] = diff[jj+3] + diff[jj+7];
1200 m2[j][4] = diff[jj ] - diff[jj+4];
1201 m2[j][5] = diff[jj+1] - diff[jj+5];
1202 m2[j][6] = diff[jj+2] - diff[jj+6];
1203 m2[j][7] = diff[jj+3] - diff[jj+7];
1205 m1[j][0] = m2[j][0] + m2[j][2];
1206 m1[j][1] = m2[j][1] + m2[j][3];
1207 m1[j][2] = m2[j][0] - m2[j][2];
1208 m1[j][3] = m2[j][1] - m2[j][3];
1209 m1[j][4] = m2[j][4] + m2[j][6];
1210 m1[j][5] = m2[j][5] + m2[j][7];
1211 m1[j][6] = m2[j][4] - m2[j][6];
1212 m1[j][7] = m2[j][5] - m2[j][7];
1214 m2[j][0] = m1[j][0] + m1[j][1];
1215 m2[j][1] = m1[j][0] - m1[j][1];
1216 m2[j][2] = m1[j][2] + m1[j][3];
1217 m2[j][3] = m1[j][2] - m1[j][3];
1218 m2[j][4] = m1[j][4] + m1[j][5];
1219 m2[j][5] = m1[j][4] - m1[j][5];
1220 m2[j][6] = m1[j][6] + m1[j][7];
1221 m2[j][7] = m1[j][6] - m1[j][7];
1225 for (i=0; i < 8; i++)
1227 m3[0][i] = m2[0][i] + m2[4][i];
1228 m3[1][i] = m2[1][i] + m2[5][i];
1229 m3[2][i] = m2[2][i] + m2[6][i];
1230 m3[3][i] = m2[3][i] + m2[7][i];
1231 m3[4][i] = m2[0][i] - m2[4][i];
1232 m3[5][i] = m2[1][i] - m2[5][i];
1233 m3[6][i] = m2[2][i] - m2[6][i];
1234 m3[7][i] = m2[3][i] - m2[7][i];
1236 m1[0][i] = m3[0][i] + m3[2][i];
1237 m1[1][i] = m3[1][i] + m3[3][i];
1238 m1[2][i] = m3[0][i] - m3[2][i];
1239 m1[3][i] = m3[1][i] - m3[3][i];
1240 m1[4][i] = m3[4][i] + m3[6][i];
1241 m1[5][i] = m3[5][i] + m3[7][i];
1242 m1[6][i] = m3[4][i] - m3[6][i];
1243 m1[7][i] = m3[5][i] - m3[7][i];
1245 m2[0][i] = m1[0][i] + m1[1][i];
1246 m2[1][i] = m1[0][i] - m1[1][i];
1247 m2[2][i] = m1[2][i] + m1[3][i];
1248 m2[3][i] = m1[2][i] - m1[3][i];
1249 m2[4][i] = m1[4][i] + m1[5][i];
1250 m2[5][i] = m1[4][i] - m1[5][i];
1251 m2[6][i] = m1[6][i] + m1[7][i];
1252 m2[7][i] = m1[6][i] - m1[7][i];
1255 for (i = 0; i < 8; i++)
1257 for (j = 0; j < 8; j++)
1259 iSumHad += abs(m2[i][j]);
1262 iSumHad -= abs(m2[0][0]);
1263 iSumHad =(iSumHad+2)>>2;
1270 const Int iBlkSize = 8;
1277 for ( yBl=0; (yBl+iBlkSize)<=height; yBl+= iBlkSize)
1279 for ( xBl=0; (xBl+iBlkSize)<=width; xBl+= iBlkSize)
1281 pOrg = pOrgInit + iStrideOrig*yBl + xBl;
1296 if(getFastDeltaQp())
1302 Int numValidMergeCand = 0;
1307 uhInterDirNeighbours[ui] = 0;
1312 UInt numSpatialMergeCandidates = 0;
1313 rpcTempCU->
getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
1319 for(
UInt ui = 0; ui < numValidMergeCand; ++ui )
1321 mergeCandBuffer[ui] = 0;
1326 numValidMergeCand = numSpatialMergeCandidates;
1330 Bool bestIsSkip =
false;
1343 for(
UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
1345 for(
UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
1347 if(!(uiNoResidual==1 && mergeCandBuffer[uiMergeCand]==1))
1349 if( !(bestIsSkip && uiNoResidual == 0) )
1364 if ( m_pcEncCfg->getTMCTSSEITileConstraint () && (!(m_pcPredSearch->checkTMctsMvp(rpcTempCU))))
1371 m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
1373 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU,
1374 m_ppcOrigYuv [uhDepth],
1375 m_ppcPredYuvTemp[uhDepth],
1376 m_ppcResiYuvTemp[uhDepth],
1377 m_ppcResiYuvBest[uhDepth],
1378 m_ppcRecoYuvTemp[uhDepth],
1382 DebugInterPredResiReco(tmpStr, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->
getPredictionMode(0)));
1385 if ((uiNoResidual == 0) && (rpcTempCU->
getQtRootCbf(0) == 0))
1388 mergeCandBuffer[uiMergeCand] = 1;
1392 xCheckDQP( rpcTempCU );
1395 rpcTempCU->
initEstData( uhDepth, orgQP, bTransquantBypassFlag );
1397 if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
1405 if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection())
1411 *earlyDetectionSkipMode =
true;
1416 for (
UInt uiRefListIdx = 0; uiRefListIdx < 2; uiRefListIdx++ )
1423 absoulte_MV+=iHor+iVer;
1427 if(absoulte_MV == 0)
1429 *earlyDetectionSkipMode =
true;
1447 if(getFastDeltaQp())
1470 m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth]
DEBUG_STRING_PASS_INTO(sTest),
false, bUseMRG );
1472 m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
1489 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth],
false DEBUG_STRING_PASS_INTO(sTest) );
1493 DebugInterPredResiReco(sTest, *(m_ppcPredYuvTemp[uhDepth]), *(m_ppcResiYuvBest[uhDepth]), *(m_ppcRecoYuvTemp[uhDepth]), DebugStringGetPredModeMask(rpcTempCU->
getPredictionMode(0)));
1496 xCheckDQP( rpcTempCU );
1507 if(getFastDeltaQp())
1511 if(rpcTempCU->
getWidth( 0 ) > fastDeltaQPCuMaxSize)
1527 m_pcPredSearch->estIntraPredLumaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma
DEBUG_STRING_PASS_INTO(sTest) );
1533 m_pcPredSearch->estIntraPredChromaQT( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth], resiLuma
DEBUG_STRING_PASS_INTO(sTest) );
1536 m_pcEntropyCoder->resetBits();
1540 m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,
true );
1543 m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,
true );
1544 m_pcEntropyCoder->encodePredMode( rpcTempCU, 0,
true );
1545 m_pcEntropyCoder->encodePartSize( rpcTempCU, 0, uiDepth,
true );
1546 m_pcEntropyCoder->encodePredInfo( rpcTempCU, 0 );
1547 m_pcEntropyCoder->encodeIPCMInfo(rpcTempCU, 0,
true );
1550 Bool bCodeDQP = getdQPFlag();
1551 Bool codeChromaQpAdjFlag = getCodeChromaQpAdjFlag();
1552 m_pcEntropyCoder->encodeCoeff( rpcTempCU, 0, uiDepth, bCodeDQP, codeChromaQpAdjFlag );
1553 setCodeChromaQpAdjFlag( codeChromaQpAdjFlag );
1554 setdQPFlag( bCodeDQP );
1556 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][
CI_TEMP_BEST]);
1558 rpcTempCU->
getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1562 xCheckDQP( rpcTempCU );
1577 if(getFastDeltaQp())
1581 if (rpcTempCU->
getWidth( 0 ) > fastDeltaQPCuMaxPCMSize)
1598 m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]);
1600 m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][
CI_CURR_BEST]);
1602 m_pcEntropyCoder->resetBits();
1606 m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0,
true );
1609 m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0,
true );
1610 m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0,
true );
1611 m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth,
true );
1612 m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0,
true );
1614 m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][
CI_TEMP_BEST]);
1616 rpcTempCU->
getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits();
1620 xCheckDQP( rpcTempCU );
1638 rpcBestCU = rpcTempCU;
1642 pcYuv = m_ppcPredYuvBest[uiDepth];
1643 m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth];
1644 m_ppcPredYuvTemp[uiDepth] = pcYuv;
1647 pcYuv = m_ppcRecoYuvBest[uiDepth];
1648 m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth];
1649 m_ppcRecoYuvTemp[uiDepth] = pcYuv;
1661 if ((DebugOptionList::DebugString_Structure.getInt()&DebugStringGetPredModeMask(predMode)) && bAddSizeInfo)
1663 std::stringstream ss(stringstream::out);
1680 m_pcEntropyCoder->resetBits();
1681 m_pcEntropyCoder->encodeQP( pcCU, 0,
false );
1682 pcCU->
getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits();
1695 pDst->
iN = pSrc->
iN;
1696 for (
Int i = 0; i < pSrc->
iN; i++)
1708 UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX;
1709 m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->
getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1711 m_ppcPredYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->
getPicYuvPred (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx);
1716 UInt uiCurrDepth = uiNextDepth - 1;
1717 m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx );
1718 m_ppcPredYuvBest[uiNextDepth]->copyToPartYuv( m_ppcPredYuvBest[uiCurrDepth], uiPartUnitIdx);
1729 for (
UInt componentIndex = 0; componentIndex < numberValidComponents; componentIndex++)
1736 Pel *source = pOrgYuv->
getAddr(component, 0, width);
1741 for (
Int line = 0; line < height; line++)
1743 for (
Int column = 0; column < width; column++)
1745 destination[column] = source[column];
1748 source += sourceStride;
1749 destination += width;
1754 #if ADAPTIVE_QP_SELECTION
1759 for(
Int n = 0; n < NumCoeffInCU; n++ )
1761 TCoeff u = abs( rpcCoeff[ n ] );
1762 TCoeff absc = rpcArlCoeff[ n ];
1768 cSum[ u ] += (
Double )absc;
1793 const UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth;
1805 xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples);
1808 pCoeffY += uiMinNumCoeffInCU;
1809 pArlCoeffY += uiMinNumCoeffInCU;
1814 m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ;
1815 m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ;
1821 Void copyPartFrom(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth)
Void xCheckIntraPCM(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU)
Void deriveTestModeAMP(TComDataCU *pcBestCU, PartSize eParentPartSize, Bool &bTestAMP_Hor, Bool &bTestAMP_Ver, Bool &bTestMergeAMP_Hor, Bool &bTestMergeAMP_Ver)
Derive small set of test modes for AMP encoder speed-up.
Void initEstData(const UInt uiDepth, const Int qp, const Bool bTransquantBypass)
Void setIPCMFlag(UInt uiIdx, Bool b)
TEncSbac *** getRDSbacCoder()
Int getLog2MinCodingBlockSize() const
Void xFillPCMBuffer(TComDataCU *pCU, TComYuv *pOrgYuv)
Void setSkipFlagSubParts(Bool skip, UInt absPartIdx, UInt depth)
SChar * getPartitionSize()
UInt getCtuTsToRsAddrMap(Int ctuTsAddr) const
static const Int ARL_C_PRECISION
G382: 7-bit arithmetic precision.
SliceType getSliceType() const
TCoeff * getArlCoeff(ComponentID component)
Void encodeCtu(TComDataCU *pCtu)
CTU encoding function.
encoder analyzer class (header)
TEncRateCtrl * getRateCtrl()
Int updateCtuDataISlice(TComDataCU *pCtu, Int width, Int height)
SliceConstraint getSliceMode() const
picture class (symbol + YUV buffers)
Void initSubCU(TComDataCU *pcCU, UInt uiPartUnitIdx, UInt uiDepth, Int qp)
std::vector< std::pair< Int, Int > > mapping
first=luma level, second=delta QP.
Void getInterMergeCandidates(UInt uiAbsPartIdx, UInt uiPUIdx, TComMvField *pcMFieldNeighbours, UChar *puhInterDirNeighbours, Int &numValidMergeCand, UInt &numSpatialMergeCandidates, Int mrgCandIdx=-1) const
Construct a list of merging candidates.
const TComPPSRExt & getPpsRangeExtension() const
Int getStride(const ComponentID id) const
Void destroy()
destroy internal buffers
static const Int MRG_MAX_NUM_CANDS
MERGE.
Void setMergeFlagSubParts(Bool bMergeFlag, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
UChar * getTransformIdx()
UChar getQtRootCbf(UInt uiIdx) const
Void xCopyAMVPInfo(AMVPInfo *pSrc, AMVPInfo *pDst)
Coding Unit (CU) encoder class (header)
Void xCheckBestMode(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt uiDepth)
TComSlice * getSlice(Int i)
class for motion vector with reference index
Bool getUseChromaQpAdj() const
Void xCtuCollectARLStats(TComDataCU *pCtu)
Collect ARL statistics from one CTU.
Void xCheckDQP(TComDataCU *pcCU)
Int xTuCollectARLStats(TCoeff *rpcCoeff, TCoeff *rpcArlCoeff, Int NumCoeffInCU, Double *cSum, UInt *numSamples)
Bool isLastColumnCTUInTile() const
SliceConstraint getSliceSegmentMode() const
SChar * getPredictionMode()
UInt getNumPartitionsInCtu() const
static const Int LEVEL_RANGE
G382: max coefficient level in statistics collection.
Void setQPSubCUs(Int qp, UInt absPartIdx, UInt depth, Bool &foundNonZeroCbf)
Bool getTMctsMvpIsValid()
UInt getPCMLog2MaxSize() const
symmetric motion partition, 2Nx N
UInt getMaxCUHeight() const
UInt getStride(const ComponentID id) const
Int getNumberValidComponents() const
TComMv const & getMvd(Int iIdx) const
UChar getCbf(UInt uiIdx, ComponentID eType) const
Picture class including local image characteristics information for QP adaptation.
TEncEntropy * getEntropyCoder()
#define DEBUG_STRING_SWAP(srt1, str2)
Int recon[MAX_NUM_CHANNEL_TYPE]
the bit depth as indicated in the SPS
Bool getTransquantBypassEnabledFlag() const
Int getChromaQpOffsetListLen() const
Int getNumRefIdx(RefPicList e) const
UInt getCtuRsToTsAddrMap(Int ctuRsAddr) const
Void xCheckRDCostIntra(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, PartSize ePartSize)
TComMv m_acMvCand[AMVP_MAX_NUM_CANDS]
array of motion vector predictor candidates
UInt getDiffCuChromaQpOffsetDepth() const
UInt getZorderIdxInCtu() const
Distortion & getTotalDistortion()
Void setCUTransquantBypassSubParts(Bool flag, UInt uiAbsPartIdx, UInt uiDepth)
Bool isInter(UInt uiPartIdx) const
Void setInterDirSubParts(UInt uiDir, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TComPicYuv * getPicYuvRec()
TEncSbac * getRDGoOnSbacCoder()
class for motion information in one CU
Void xEncodeCU(TComDataCU *pcCU, UInt uiAbsPartIdx, UInt uiDepth)
UInt getMaxTotalCUDepth() const
Int calculateLumaDQP(TComDataCU *pCU, const UInt absPartIdx, const TComYuv *pOrgYuv)
Void setChromaQpAdjSubParts(UChar val, Int absPartIdx, Int depth)
PartSize
supported partition shape
UInt getNumPartInCtuWidth() const
Limit maximum number of bytes in a slice / slice segment.
Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
UInt getMaxNumMergeCand() const
Int iN
number of motion vector predictor candidates
symmetric motion partition, 2Nx2N
Int getQpBDOffset(ChannelType type) const
Void setAllMvField(TComMvField const &mvField, PartSize eMbMode, Int iPartAddr, UInt uiDepth, Int iPartIdx=0)
Bool isIntra(UInt uiPartIdx) const
Void setPartSizeSubParts(PartSize eMode, UInt uiAbsPartIdx, UInt uiDepth)
Void setTMctsMvpIsValid(Bool b)
Void xCopyYuv2Pic(TComPic *rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth)
Void initRasterToPelXY(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
Bool isLosslessCoded(UInt absPartIdx) const
asymmetric motion partition, 2Nx( N/2) + 2Nx(3N/2)
asymmetric motion partition, (3N/2)x2N + ( N/2)x2N
UInt getPicHeightInLumaSamples() const
UInt getSliceBits() const
UInt getPCMLog2MinSize() const
TComTrQuant * getTrQuant()
Void create(const UInt iWidth, const UInt iHeight, const ChromaFormat chromaFormatIDC)
Create YUV buffer.
UInt getSliceSegmentBits() const
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Void initRasterToZscan(UInt uiMaxCUWidth, UInt uiMaxCUHeight, UInt uiMaxDepth)
#define DEBUG_STRING_APPEND(str1, str2)
TComPicYuv * getPicYuvOrg()
Int TCoeff
transform coefficient
Void compressCtu(TComDataCU *pCtu)
CTU analysis function.
Pel * getAddr(const ComponentID id)
RefPicList
reference list index
UInt getMaxCuDQPDepth() const
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Void init(TEncTop *pcEncTop)
copy parameters from encoder class
UInt getQuadtreeTULog2MinSize() const
Void finishCU(TComDataCU *pcCU, UInt uiAbsPartIdx)
Local image characteristics for CUs on a specific depth.
const BitDepths & getBitDepths() const
UInt getSliceSegmentCurStartCtuTsAddr() const
Bool isSkipped(UInt uiPartIdx) const
returns true, if the partiton is skipped
UInt g_auiZscanToRaster[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
const TComPPS * getPPS() const
UInt getPicWidthInLumaSamples() const
Void setQPSubParts(Int qp, UInt uiAbsPartIdx, UInt uiDepth)
Void copyToPic(UChar uiDepth)
static const UInt LUMA_LEVEL_TO_DQP_LUT_MAXSIZE
max LUT size for QP offset based on luma
#define DEBUG_STRING_PASS_INTO(name)
UInt getSliceArgument() const
UInt getSliceSegmentArgument() const
ChromaFormat getChromaFormat() const
Void setIPCMFlagSubParts(Bool bIpcmFlag, UInt uiAbsPartIdx, UInt uiDepth)
UInt getCurrSliceIdx() const
Int getLog2DiffMaxMinCodingBlockSize() const
Bool * getCUTransquantBypass()
UInt getSliceCurStartCtuTsAddr() const
asymmetric motion partition, ( N/2)x2N + (3N/2)x2N
TComPicYuv * getPicYuvPred()
Void xCheckRDCostMerge2Nx2N(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, Bool *earlyDetectionSkipMode)
Void create(ChromaFormat chromaFormatIDC, UInt uiNumPartition, UInt uiWidth, UInt uiHeight, Bool bDecSubCu, Int unitSize, TCoeff *pParentARLBuffer=0)
#define DEBUG_STRING_FN_DECLARE(name)
TEncPicQPAdaptationLayer * getAQLayer(UInt uiDepth)
static const Int MAX_CU_SIZE
= 1<<(MAX_CU_DEPTH)
Void xCompressCU(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, const UInt uiDepth, PartSize eParentPartSize=NUMBER_OF_PART_SIZES)
static const Double MAX_DOUBLE
max. value of Double-type value
Pel * getAddr(const ComponentID ch)
Void initZscanToRaster(Int iMaxDepth, Int iDepth, UInt uiStartVal, UInt *&rpuiCurrIdx)
Void xCopyYuv2Tmp(UInt uhPartUnitIdx, UInt uiDepth)
UInt getSliceSegmentCurEndCtuTsAddr() const
Void xCheckRDCostInter(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, PartSize ePartSize, Bool bUseMRG=false)
TComCUMvField * getCUMvField(RefPicList e)
TCoeff * getCoeff(ComponentID component)
Bool isLastSubCUOfCtu(const UInt absPartIdx) const
PredMode
supported prediction type
Void setPredModeSubParts(PredMode eMode, UInt uiAbsPartIdx, UInt uiDepth)
Void setMergeIndexSubParts(UInt uiMergeIndex, UInt uiAbsPartIdx, UInt uiPartIdx, UInt uiDepth)
TEncSearch * getPredSearch()
Unit block for storing image characteristics.
SChar getRefQP(UInt uiCurrAbsIdxInCtu) const
asymmetric motion partition, 2Nx(3N/2) + 2Nx( N/2)
symmetric motion partition, Nx N
Pel * getPCMSample(ComponentID component)
UInt g_auiRasterToPelX[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
Void initLumaDeltaQpLUT()
TEncBinCABAC * getBinCABAC()
Void create(UChar uhTotalDepth, UInt iMaxWidth, UInt iMaxHeight, ChromaFormat chromaFormat)
create internal buffers
#define DEBUG_STRING_OUTPUT(os, name)
symmetric motion partition, Nx2N
#define DEBUG_STRING_NEW(name)
Int xComputeQP(TComDataCU *pcCU, UInt uiDepth)
Defines types and objects for environment-variable-based debugging and feature control.
UInt g_auiRasterToPelY[MAX_NUM_PART_IDXS_IN_CTU_WIDTH *MAX_NUM_PART_IDXS_IN_CTU_WIDTH]
UInt getMaxCUWidth() const
const TComSPS * getSPS() const
Void setTrIdxSubParts(UInt uiTrIdx, UInt uiAbsPartIdx, UInt uiDepth)