87 UChar combinedSubTUCBF = 0;
89 for (
UInt subTU = 0; subTU < 2; subTU++)
91 const UInt subTUAbsPartIdx = uiAbsPartIdx + (subTU * partIdxesPerSubTU);
93 subTUCBF[subTU] = pcCU->
getCbf(subTUAbsPartIdx, compID, uiTrDepth);
94 combinedSubTUCBF |= subTUCBF[subTU];
97 for (
UInt subTU = 0; subTU < 2; subTU++)
99 const UInt subTUAbsPartIdx = uiAbsPartIdx + (subTU * partIdxesPerSubTU);
100 const UChar compositeCBF = (subTUCBF[subTU] << 1) | combinedSubTUCBF;
102 pcCU->
setCbfPartRange((compositeCBF << uiTrDepth), compID, subTUAbsPartIdx, partIdxesPerSubTU);
108 : m_puhQTTempTrIdx(
NULL)
109 , m_pcQTTempTComYuv(
NULL)
113 , m_pcEntropyCoder (
NULL)
115 , m_bipredSearchRange (0)
117 , m_pppcRDSbacCoder (
NULL)
118 , m_pcRDGoOnSbacCoder (
NULL)
120 , m_isInitialized (false)
125 #if ADAPTIVE_QP_SELECTION
132 #if ADAPTIVE_QP_SELECTION
166 for (
UInt layer = 0; layer < uiNumLayersAllocated; layer++)
169 #if ADAPTIVE_QP_SELECTION
175 #if ADAPTIVE_QP_SELECTION
180 for(
UInt layer = 0; layer < uiNumLayersAllocated; layer++ )
193 #if ADAPTIVE_QP_SELECTION
219 Int bipredSearchRange,
221 const UInt maxCUWidth,
222 const UInt maxCUHeight,
223 const UInt maxTotalCUDepth,
272 const UInt uiNumPartitions = 1<<(maxTotalCUDepth<<1);
278 #if ADAPTIVE_QP_SELECTION
283 for (
UInt layer = 0; layer < uiNumLayersToAllocate; layer++)
286 #if ADAPTIVE_QP_SELECTION
294 #if ADAPTIVE_QP_SELECTION
301 for(
UInt ui = 0; ui < uiNumLayersToAllocate; ++ui )
315 const Pel*
const piRefSrch = rcStruct.
piRefY + iSearchY * rcStruct.
iYStride + iSearchX;
353 if((uiTempSad + uiBitCost) < rcStruct.
uiBestSad)
363 if(((uiSad << isubShift) + uiBitCost) > rcStruct.
uiBestSad)
377 rcStruct.
iBestX = iSearchX;
378 rcStruct.
iBestY = iSearchY;
411 rcStruct.
iBestX = iSearchX;
412 rcStruct.
iBestY = iSearchY;
424 Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
425 Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
426 Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
427 Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
438 if ( (iStartX - 1) >= iSrchRngHorLeft )
440 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY, 0, 2 );
442 if ( (iStartY - 1) >= iSrchRngVerTop )
444 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY - 1, 0, 2 );
450 if ( (iStartY - 1) >= iSrchRngVerTop )
452 if ( (iStartX - 1) >= iSrchRngHorLeft )
454 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY - 1, 0, 2 );
456 if ( (iStartX + 1) <= iSrchRngHorRight )
458 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY - 1, 0, 2 );
465 if ( (iStartY - 1) >= iSrchRngVerTop )
467 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY - 1, 0, 2 );
469 if ( (iStartX + 1) <= iSrchRngHorRight )
471 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY, 0, 2 );
477 if ( (iStartX - 1) >= iSrchRngHorLeft )
479 if ( (iStartY + 1) <= iSrchRngVerBottom )
481 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY + 1, 0, 2 );
483 if ( (iStartY - 1) >= iSrchRngVerTop )
485 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY - 1, 0, 2 );
492 if ( (iStartX + 1) <= iSrchRngHorRight )
494 if ( (iStartY - 1) >= iSrchRngVerTop )
496 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY - 1, 0, 2 );
498 if ( (iStartY + 1) <= iSrchRngVerBottom )
500 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY + 1, 0, 2 );
507 if ( (iStartX - 1) >= iSrchRngHorLeft )
509 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY , 0, 2 );
511 if ( (iStartY + 1) <= iSrchRngVerBottom )
513 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY + 1, 0, 2 );
519 if ( (iStartY + 1) <= iSrchRngVerBottom )
521 if ( (iStartX - 1) >= iSrchRngHorLeft )
523 xTZSearchHelp( pcPatternKey, rcStruct, iStartX - 1, iStartY + 1, 0, 2 );
525 if ( (iStartX + 1) <= iSrchRngHorRight )
527 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY + 1, 0, 2 );
534 if ( (iStartX + 1) <= iSrchRngHorRight )
536 xTZSearchHelp( pcPatternKey, rcStruct, iStartX + 1, iStartY, 0, 2 );
538 if ( (iStartY + 1) <= iSrchRngVerBottom )
540 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iStartY + 1, 0, 2 );
557 const Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
558 const Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
559 const Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
560 const Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
565 assert( iDist != 0 );
566 const Int iTop = iStartY - iDist;
567 const Int iBottom = iStartY + iDist;
568 const Int iLeft = iStartX - iDist;
569 const Int iRight = iStartX + iDist;
572 if ( iTop >= iSrchRngVerTop )
574 if ( iLeft >= iSrchRngHorLeft )
576 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iTop, 1, iDist );
579 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
581 if ( iRight <= iSrchRngHorRight )
583 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iTop, 3, iDist );
586 if ( iLeft >= iSrchRngHorLeft )
588 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
590 if ( iRight <= iSrchRngHorRight )
592 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
594 if ( iBottom <= iSrchRngVerBottom )
596 if ( iLeft >= iSrchRngHorLeft )
598 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iBottom, 6, iDist );
601 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
603 if ( iRight <= iSrchRngHorRight )
605 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iBottom, 8, iDist );
615 const TComMv*
const pcMvSrchRngLT,
616 const TComMv*
const pcMvSrchRngRB,
620 const Bool bCheckCornersAtDist1 )
622 const Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
623 const Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
624 const Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
625 const Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
630 assert ( iDist != 0 );
631 const Int iTop = iStartY - iDist;
632 const Int iBottom = iStartY + iDist;
633 const Int iLeft = iStartX - iDist;
634 const Int iRight = iStartX + iDist;
639 if ( iTop >= iSrchRngVerTop )
641 if (bCheckCornersAtDist1)
643 if ( iLeft >= iSrchRngHorLeft)
645 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iTop, 1, iDist );
647 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
648 if ( iRight <= iSrchRngHorRight )
650 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iTop, 3, iDist );
655 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
658 if ( iLeft >= iSrchRngHorLeft )
660 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
662 if ( iRight <= iSrchRngHorRight )
664 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
666 if ( iBottom <= iSrchRngVerBottom )
668 if (bCheckCornersAtDist1)
670 if ( iLeft >= iSrchRngHorLeft)
672 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iBottom, 6, iDist );
674 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
675 if ( iRight <= iSrchRngHorRight )
677 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iBottom, 8, iDist );
682 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
690 const Int iTop_2 = iStartY - (iDist>>1);
691 const Int iBottom_2 = iStartY + (iDist>>1);
692 const Int iLeft_2 = iStartX - (iDist>>1);
693 const Int iRight_2 = iStartX + (iDist>>1);
695 if ( iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft &&
696 iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom )
698 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
699 xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iTop_2, 1, iDist>>1 );
700 xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2, 3, iDist>>1 );
701 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
702 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
703 xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iBottom_2, 6, iDist>>1 );
704 xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, iDist>>1 );
705 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
709 if ( iTop >= iSrchRngVerTop )
711 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
713 if ( iTop_2 >= iSrchRngVerTop )
715 if ( iLeft_2 >= iSrchRngHorLeft )
717 xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iTop_2, 1, (iDist>>1) );
719 if ( iRight_2 <= iSrchRngHorRight )
721 xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2, 3, (iDist>>1) );
724 if ( iLeft >= iSrchRngHorLeft )
726 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
728 if ( iRight <= iSrchRngHorRight )
730 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
732 if ( iBottom_2 <= iSrchRngVerBottom )
734 if ( iLeft_2 >= iSrchRngHorLeft )
736 xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iBottom_2, 6, (iDist>>1) );
738 if ( iRight_2 <= iSrchRngHorRight )
740 xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, (iDist>>1) );
743 if ( iBottom <= iSrchRngVerBottom )
745 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
751 if ( iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft &&
752 iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom )
754 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 0, iDist );
755 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 0, iDist );
756 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 0, iDist );
757 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist );
758 for (
Int index = 1; index < 4; index++ )
760 const Int iPosYT = iTop + ((iDist>>2) * index);
761 const Int iPosYB = iBottom - ((iDist>>2) * index);
762 const Int iPosXL = iStartX - ((iDist>>2) * index);
763 const Int iPosXR = iStartX + ((iDist>>2) * index);
764 xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist );
765 xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist );
766 xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist );
767 xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist );
772 if ( iTop >= iSrchRngVerTop )
774 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 0, iDist );
776 if ( iLeft >= iSrchRngHorLeft )
778 xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 0, iDist );
780 if ( iRight <= iSrchRngHorRight )
782 xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 0, iDist );
784 if ( iBottom <= iSrchRngVerBottom )
786 xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist );
788 for (
Int index = 1; index < 4; index++ )
790 const Int iPosYT = iTop + ((iDist>>2) * index);
791 const Int iPosYB = iBottom - ((iDist>>2) * index);
792 const Int iPosXL = iStartX - ((iDist>>2) * index);
793 const Int iPosXR = iStartX + ((iDist>>2) * index);
795 if ( iPosYT >= iSrchRngVerTop )
797 if ( iPosXL >= iSrchRngHorLeft )
799 xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist );
801 if ( iPosXR <= iSrchRngHorRight )
803 xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist );
806 if ( iPosYB <= iSrchRngVerBottom )
808 if ( iPosXL >= iSrchRngHorLeft )
810 xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist );
812 if ( iPosXR <= iSrchRngHorRight )
814 xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist );
826 Bool bAllowUseOfHadamard
830 Distortion uiDistBest = std::numeric_limits<Distortion>::max();
831 UInt uiDirecBest = 0;
841 UInt maxRefinements = 9;
845 const UInt LumaLTSampleOffset = 3;
846 const UInt LumaRBSampleOffset = 4;
862 for (
UInt i = 0; i < maxRefinements; i++)
864 for (
UInt i = 0; i < 9; i++)
867 TComMv cMvTest = pcMvRefine[i];
868 cMvTest += baseRefMv;
873 if ( horVal == 2 && ( verVal & 1 ) == 0 )
877 if ( ( horVal & 1 ) == 0 && verVal == 2 )
879 piRefPos += iRefStride;
881 cMvTest = pcMvRefine[i];
891 if ( uiDist < uiDistBest )
899 rcMvFrac = pcMvRefine[uiDirecBest];
915 const UInt uiSubdiv = ( uiTrMode > uiTrDepth ? 1 : 0 );
987 const UInt uiSubdiv = ( uiTrMode > uiTrDepth ? 1 : 0 );
994 xEncCoeffQT( tuRecurseChild, component, bRealCoeff );
1027 if( uiAbsPartIdx == 0 )
1053 if (uiAbsPartIdx==0)
1061 if (uiTrDepth>0 && (uiAbsPartIdx%uiQNumParts)==0)
1080 assert(uiTrDepth>0);
1081 if ((uiAbsPartIdx%uiQNumParts)==0)
1133 const Bool checkCrossCPrediction,
1138 ,
Int default0Save1Load2
1141 if (!rTu.ProcessComponentSection(compID))
1148 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
1151 const UInt uiTrDepth = rTu.GetTransformDepthRelAdj(compID);
1152 const UInt uiFullDepth = rTu.GetTransformDepthTotal();
1153 const UInt uiLog2TrSize = rTu.GetLog2LumaTrSize();
1161 Pel *piOrg = pcOrgYuv ->
getAddr( compID, uiAbsPartIdx );
1162 Pel *piPred = pcPredYuv->
getAddr( compID, uiAbsPartIdx );
1163 Pel *piResi = pcResiYuv->
getAddr( compID, uiAbsPartIdx );
1164 Pel *piReco = pcPredYuv->
getAddr( compID, uiAbsPartIdx );
1174 #if ADAPTIVE_QP_SELECTION
1190 Pel *
const lumaResidualForEstimate = bUseReconstructedResidualForEstimate ? reconstructedLumaResidual : encoderLumaResidual;
1193 const Int debugPredModeMask=DebugStringGetPredModeMask(
MODE_INTRA);
1200 if( default0Save1Load2 != 2 )
1208 predIntraAng( compID, uiChFinalMode, piOrg, uiStride, piPred, uiStride, rTu, bUseFilteredPredictions );
1211 if( default0Save1Load2 == 1 )
1213 Pel* pPred = piPred;
1216 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1218 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1220 pPredBuf[ k ++ ] = pPred[ uiX ];
1230 Pel* pPred = piPred;
1233 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1235 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1237 pPred[ uiX ] = pPredBuf[ k ++ ];
1248 Pel* pPred = piPred;
1249 Pel* pResi = piResi;
1251 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1253 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1255 pResi[ uiX ] = pOrg[ uiX ] - pPred[ uiX ];
1266 if (bUseCrossCPrediction)
1272 TComTrQuant::crossComponentPrediction ( rTu, compID, reconstructedLumaResidual, piResi, piResi, uiWidth, uiHeight, MAX_CU_SIZE, uiStride, uiStride,
false );
1274 else if (
isLuma(compID) && !bUseReconstructedResidualForEstimate)
1295 const QpParam cQP(*pcCU, compID);
1297 #if RDOQ_CHROMA_LAMBDA
1311 if ( (uiAbsSum > 0) || (DebugOptionList::DebugString_InvTran.getInt()&debugPredModeMask) )
1320 Pel* pResi = piResi;
1321 memset( pcCoeff, 0,
sizeof(
TCoeff ) * uiWidth * uiHeight );
1322 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1324 memset( pResi, 0,
sizeof(
Pel ) * uiWidth );
1332 Pel* pPred = piPred;
1333 Pel* pResi = piResi;
1334 Pel* pReco = piReco;
1335 Pel* pRecQt = piRecQt;
1336 Pel* pRecIPred = piRecIPred;
1340 if (bUseCrossCPrediction)
1342 TComTrQuant::crossComponentPrediction( rTu, compID, reconstructedLumaResidual, piResi, piResi, uiWidth, uiHeight, MAX_CU_SIZE, uiStride, uiStride,
true );
1351 std::stringstream ss(stringstream::out);
1356 if (bDebugPred || bDebugResi || bDebugReco)
1358 ss <<
"###: " <<
"CompID: " << compID <<
" pred mode (ch/fin): " << uiChPredMode <<
"/" << uiChFinalMode <<
" absPartIdx: " << rTu.GetAbsPartIdxTU() <<
"\n";
1359 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1365 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1367 ss << pPred[ uiX ] <<
", ";
1374 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1378 ss << pResi[ uiX ] <<
", ";
1380 pReco [ uiX ] =
Pel(ClipBD<Int>(
Int(pPred[uiX]) +
Int(pResi[uiX]), bitDepth ));
1381 pRecQt [ uiX ] = pReco[ uiX ];
1382 pRecIPred[ uiX ] = pReco[ uiX ];
1387 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1389 ss << pReco[ uiX ] <<
", ";
1395 pRecQt += uiRecQtStride;
1396 pRecIPred += uiRecIPredStride;
1405 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1407 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1409 pReco [ uiX ] =
Pel(ClipBD<Int>(
Int(pPred[uiX]) +
Int(pResi[uiX]), bitDepth ));
1410 pRecQt [ uiX ] = pReco[ uiX ];
1411 pRecIPred[ uiX ] = pReco[ uiX ];
1416 pRecQt += uiRecQtStride;
1417 pRecIPred += uiRecIPredStride;
1423 ruiDist +=
m_pcRdCost->
getDistPart( bitDepth, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, compID );
1443 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
1444 const UInt uiFullDepth = rTu.GetTransformDepthTotal();
1445 const UInt uiTrDepth = rTu.GetTransformDepthRel();
1446 const UInt uiLog2TrSize = rTu.GetLog2LumaTrSize();
1456 bMaintainResidual[residualTypeIndex] =
true;
1461 #if HHI_RQT_INTRA_SPEEDUP
1465 Bool noSplitIntraMaxTuSize = bCheckFull;
1469 noSplitIntraMaxTuSize = ( uiLog2TrSize <= min(maxTuSize,4) );
1474 bCheckFull = ( uiLog2TrSize <= min(maxTuSize,4));
1477 if( bCheckFirst && noSplitIntraMaxTuSize )
1480 bCheckSplit =
false;
1488 bCheckFull = ( uiLog2TrSize <= min(maxTuSize,4));
1493 UInt uiSingleCbfLuma = 0;
1499 assert (rTu.ProcessComponentSection(
COMPONENT_Y));
1500 const UInt totalAdjustedDepthChan = rTu.GetTransformDepthTotalAdj(
COMPONENT_Y);
1509 if(checkTransformSkip ==
true)
1515 UInt singleCbfTmpLuma = 0;
1516 Double singleCostTmp = 0;
1517 Int firstCheckId = 0;
1519 for(
Int modeId = firstCheckId; modeId < 2; modeId ++)
1522 Int default0Save1Load2 = 0;
1523 singleDistTmpLuma=0;
1524 if(modeId == firstCheckId)
1526 default0Save1Load2 = 1;
1530 default0Save1Load2 = 2;
1540 if(modeId == 1 && singleCbfTmpLuma == 0)
1550 if(singleCostTmp < dSingleCost)
1553 dSingleCost = singleCostTmp;
1554 uiSingleDistLuma = singleDistTmpLuma;
1555 uiSingleCbfLuma = singleCbfTmpLuma;
1570 if (bMaintainResidual[storedResidualIndex])
1577 if (modeId == firstCheckId)
1585 if(bestModeId[COMPONENT_Y] == firstCheckId)
1588 pcCU->
setCbfSubParts ( uiSingleCbfLuma << uiTrDepth, COMPONENT_Y, uiAbsPartIdx, rTu.GetTransformDepthTotalAdj(COMPONENT_Y) );
1615 uiSingleBits=uiSingleBits*4;
1626 if (bMaintainResidual[storedResidualIndex])
1650 UInt uiSplitCbfLuma = 0;
1657 #if HHI_RQT_INTRA_SPEEDUP
1666 UInt uiPartsDiv = rTu.GetAbsPartIdxNumParts();
1670 const UInt flag=1<<uiTrDepth;
1672 for(
UInt uiOffs = 0; uiOffs < uiPartsDiv; uiOffs++ )
1674 pBase[ uiAbsPartIdx + uiOffs ] |= flag;
1686 if( dSplitCost < dSingleCost )
1690 ruiDistY += uiSplitDistLuma;
1691 dRDCost += dSplitCost;
1699 if (bMaintainResidual[storedResidualIndex])
1728 for(
UInt uiY = 0; uiY < uiHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride )
1730 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1732 piDes[ uiX ] = piSrc[ uiX ];
1736 ruiDistY += uiSingleDistLuma;
1737 dRDCost += dSingleCost;
1748 if( uiTrMode == uiTrDepth )
1759 if (numCoeffInBlock!=0)
1763 ::memcpy( destCoeff, srcCoeff,
sizeof(
TCoeff)*numCoeffInBlock );
1764 #if ADAPTIVE_QP_SELECTION
1767 ::memcpy( destArlCoeff, srcArlCoeff,
sizeof(
TCoeff ) * numCoeffInBlock );
1791 if ( compID==
COMPONENT_Y || uiTrMode == uiTrDepth )
1793 assert(uiTrMode == uiTrDepth);
1806 ::memcpy( pcCoeffDst, pcCoeffSrc,
sizeof(
TCoeff ) * uiNumCoeff );
1807 #if ADAPTIVE_QP_SELECTION
1810 ::memcpy( pcArlCoeffDst, pcArlCoeffSrc,
sizeof(
TCoeff ) * uiNumCoeff );
1826 if ( compID==
COMPONENT_Y || uiTrMode == uiTrDepth )
1828 assert(uiTrMode == uiTrDepth);
1842 ::memcpy( pcCoeffDst, pcCoeffSrc,
sizeof(
TCoeff ) * uiNumCoeff );
1843 #if ADAPTIVE_QP_SELECTION
1846 ::memcpy( pcArlCoeffDst, pcArlCoeffSrc,
sizeof(
TCoeff ) * uiNumCoeff );
1857 Pel* pRecQt = piRecQt;
1858 Pel* pRecIPred = piRecIPred;
1859 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1861 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1863 pRecIPred[ uiX ] = pRecQt [ uiX ];
1865 pRecQt += uiRecQtStride;
1866 pRecIPred += uiRecIPredStride;
1874 const Pel *pResiSrc,
1878 const Int strideDst,
1879 const Int strideSrc )
1881 const Pel *pSrc = pResiSrc + yOffset * strideSrc + xOffset;
1882 Pel *pDst = pResiDst + yOffset * strideDst + xOffset;
1902 const Pel *pResiL = piResiL;
1903 const Pel *pResiC = piResiC;
1913 for(
UInt uiY = 0; uiY < height; uiY++ )
1915 for(
UInt uiX = 0; uiX < width; uiX++ )
1917 const Pel scaledResiL =
rightShift( pResiL[ uiX ], diffBitDepth );
1918 SSxy += ( scaledResiL * pResiC[ uiX ] );
1919 SSxx += ( scaledResiL * scaledResiL );
1929 alpha =
SChar(Clip3<Int>(-16, 16, (
Int)(dAlpha * 16)));
1931 static const SChar alphaQuant[17] = {0, 1, 1, 2, 2, 2, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8};
1933 alpha = (alpha < 0) ? -alphaQuant[
Int(-alpha)] : alphaQuant[
Int(alpha)];
1950 const UInt uiTrDepth = rTu.GetTransformDepthRel();
1951 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
1956 if( uiTrMode == uiTrDepth )
1963 const UInt uiFullDepth = rTu.GetTransformDepthTotal();
1972 if (checkTransformSkip)
1975 const UInt maxAbsPartIdxSub=uiAbsPartIdx + (rTu.ProcessingAllQuadrants(
COMPONENT_Cb)?1:4);
1976 for(
UInt absPartIdxSub = uiAbsPartIdx; absPartIdxSub < maxAbsPartIdxSub; absPartIdxSub ++)
1980 checkTransformSkip &= (nbLumaSkip > 0);
1993 const Bool splitIntoSubTUs = rTu.getRect(compID).width != rTu.getRect(compID).height;
2006 UInt singleCbfC = 0;
2008 Double singleCostTmp = 0;
2009 UInt singleCbfCTmp = 0;
2010 SChar bestCrossCPredictionAlpha = 0;
2011 Int bestTransformSkipMode = 0;
2017 const Int crossCPredictionModesToTest = checkCrossComponentPrediction ? 2 : 1;
2018 const Int transformSkipModesToTest = checkTransformSkip ? 2 : 1;
2019 const Int totalModesToTest = crossCPredictionModesToTest * transformSkipModesToTest;
2021 Int default0Save1Load2 = 0;
2023 for(
Int transformSkipModeId = 0; transformSkipModeId < transformSkipModesToTest; transformSkipModeId++)
2025 for(
Int crossCPredictionModeId = 0; crossCPredictionModeId < crossCPredictionModesToTest; crossCPredictionModeId++)
2032 const Bool isOneMode = (totalModesToTest == 1);
2033 const Bool isLastMode = (currModeId == totalModesToTest);
2037 default0Save1Load2 = 0;
2039 else if (!isOneMode && (transformSkipModeId == 0) && (crossCPredictionModeId == 0))
2041 default0Save1Load2 = 1;
2045 default0Save1Load2 = 2;
2051 singleCbfCTmp = pcCU->
getCbf( subTUAbsPartIdx, compID, uiTrDepth);
2054 || ((transformSkipModeId == 1) && (singleCbfCTmp == 0)))
2058 else if (!isOneMode)
2064 if(singleCostTmp < dSingleCost)
2067 dSingleCost = singleCostTmp;
2068 singleDistC = singleDistCTmp;
2070 bestTransformSkipMode = transformSkipModeId;
2071 bestModeId = currModeId;
2072 singleCbfC = singleCbfCTmp;
2074 if (!isOneMode && !isLastMode)
2081 if (!isOneMode && !isLastMode)
2088 if(bestModeId < totalModesToTest)
2091 pcCU->
setCbfPartRange( singleCbfC << uiTrDepth, compID, subTUAbsPartIdx, partIdxesPerSubTU );
2099 ruiDist += singleDistC;
2102 if (splitIntoSubTUs)
2125 uiSplitCbf[ch] |= pcCU->
getCbf( uiAbsPartIdxSub,
ComponentID(ch), uiTrDepthChild );
2130 UInt uiPartsDiv = rTu.GetAbsPartIdxNumParts();
2135 const UInt flag=1<<uiTrDepth;
2138 for(
UInt uiOffs = 0; uiOffs < uiPartsDiv; uiOffs++ )
2140 pBase[ uiAbsPartIdx + uiOffs ] |= flag;
2161 if( uiTrMode == uiTrDepth )
2177 ::memcpy( dest, src,
sizeof(
TCoeff)*uiNumCoeffC );
2178 #if ADAPTIVE_QP_SELECTION
2181 ::memcpy( pcArlCoeffDst, pcArlCoeffSrc,
sizeof(
TCoeff ) * uiNumCoeffC );
2213 const UInt uiNumPU = 1<<(2*uiInitTrDepth);
2228 bMaintainResidual[residualTypeIndex] =
true;
2267 Int numModesAvailable = 35;
2275 Bool doFastSearch = (numModesForFullRD != numModesAvailable);
2278 assert(numModesForFullRD < numModesAvailable);
2280 for(
Int i=0; i < numModesForFullRD; i++ )
2296 for(
Int modeIdx = 0; modeIdx < numModesAvailable; modeIdx++ )
2298 UInt uiMode = modeIdx;
2306 uiSad+=distParam.
DistFunc(&distParam);
2315 #if DEBUG_INTRA_SEARCH_COSTS
2316 std::cout <<
"1st pass mode " << uiMode <<
" SAD = " << uiSad <<
", mode bits = " << iModeBits <<
", cost = " << cost <<
"\n";
2319 CandNum +=
xUpdateCandList( uiMode, cost, numModesForFullRD, uiRdModeList, CandCostList );
2331 for(
Int j=0; j < numCand; j++)
2333 Bool mostProbableModeIncluded =
false;
2334 Int mostProbableMode = uiPreds[j];
2336 for(
Int i=0; i < numModesForFullRD; i++)
2338 mostProbableModeIncluded |= (mostProbableMode == uiRdModeList[i]);
2340 if (!mostProbableModeIncluded)
2342 uiRdModeList[numModesForFullRD++] = mostProbableMode;
2349 for(
Int i=0; i < numModesForFullRD; i++)
2351 uiRdModeList[i] = i;
2356 #if HHI_RQT_INTRA_SPEEDUP_MOD
2361 UInt uiBestPUMode = 0;
2365 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
2366 UInt max=numModesForFullRD;
2372 for (
UInt uiMode = 0; uiMode < max; uiMode++)
2374 for(
UInt uiMode = 0; uiMode < numModesForFullRD; uiMode++ )
2378 UInt uiOrgMode = uiRdModeList[uiMode];
2389 #if HHI_RQT_INTRA_SPEEDUP
2395 #if DEBUG_INTRA_SEARCH_COSTS
2400 if( dPUCost < dBestPUCost )
2403 #if HHI_RQT_INTRA_SPEEDUP_MOD
2404 uiSecondBestMode = uiBestPUMode;
2405 dSecondBestPUCost = dBestPUCost;
2407 uiBestPUMode = uiOrgMode;
2408 uiBestPUDistY = uiPUDistY;
2409 dBestPUCost = dPUCost;
2419 if (bMaintainResidual[storedResidualIndex])
2429 for (
UInt component = 0; component < numberValidComponents; component++)
2436 #if HHI_RQT_INTRA_SPEEDUP_MOD
2437 else if( dPUCost < dSecondBestPUCost )
2439 uiSecondBestMode = uiOrgMode;
2440 dSecondBestPUCost = dPUCost;
2445 #if HHI_RQT_INTRA_SPEEDUP
2446 #if HHI_RQT_INTRA_SPEEDUP_MOD
2447 for(
UInt ui =0; ui < 2; ++ui )
2450 #if HHI_RQT_INTRA_SPEEDUP_MOD
2451 UInt uiOrgMode = ui ? uiSecondBestMode : uiBestPUMode;
2457 UInt uiOrgMode = uiBestPUMode;
2460 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
2480 if( dPUCost < dBestPUCost )
2483 uiBestPUMode = uiOrgMode;
2484 uiBestPUDistY = uiPUDistY;
2485 dBestPUCost = dPUCost;
2495 if (bMaintainResidual[storedResidualIndex])
2505 for (
UInt component = 0; component < numberValidComponents; component++)
2518 uiOverallDistY += uiBestPUDistY;
2523 for (
UInt component = 0; component < numberValidComponents; component++)
2543 for(
UInt uiY = 0; uiY < uiCompHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride )
2545 for(
UInt uiX = 0; uiX < uiCompWidth; uiX++ )
2547 piDes[ uiX ] = piSrc[ uiX ];
2554 }
while (tuRecurseWithPU.
nextSection(tuRecurseCU));
2559 UInt uiCombCbfY = 0;
2560 UInt uiCombCbfU = 0;
2561 UInt uiCombCbfV = 0;
2563 for(
UInt uiPart = 0; uiPart < 4; uiPart++, uiPartIdx += uiQNumParts )
2569 for(
UInt uiOffs = 0; uiOffs < 4 * uiQNumParts; uiOffs++ )
2606 UInt uiBestMode = 0;
2614 const UInt uiQPartNum = uiQNumParts;
2623 #if ENVIRONMENT_VARIABLE_DEBUG_AND_TEST
2627 if (uiModeList[uiMinMode]==34)
2631 uiMaxMode=uiMinMode+1;
2637 for(
UInt uiMode = uiMinMode; uiMode < uiMaxMode; uiMode++ )
2657 if( dCost < dBestCost )
2661 uiBestDist = uiDist;
2662 uiBestMode = uiModeList[uiMode];
2665 for (
UInt componentIndex =
COMPONENT_Cb; componentIndex < numberValidComponents; componentIndex++)
2678 for (
UInt componentIndex =
COMPONENT_Cb; componentIndex < numberValidComponents; componentIndex++)
2698 const Pel* piSrc = pcRecoYuv->
getAddr( compID, uiPartOffset );
2701 for(
UInt uiY = 0; uiY < uiCompHeight; uiY++, piSrc += uiSrcStride, piDes += uiDesStride )
2703 for(
UInt uiX = 0; uiX < uiCompWidth; uiX++ )
2705 piDes[ uiX ] = piSrc[ uiX ];
2715 }
while (tuRecurseWithPU.
nextSection(tuRecurseCU));
2719 if( uiInitTrDepth != 0 )
2721 UInt uiCombCbfU = 0;
2722 UInt uiCombCbfV = 0;
2724 for(
UInt uiPart = 0; uiPart < 4; uiPart++, uiPartIdx += uiQNumParts )
2729 for(
UInt uiOffs = 0; uiOffs < 4 * uiQNumParts; uiOffs++ )
2755 Void TEncSearch::xEncPCM (
TComDataCU* pcCU,
UInt uiAbsPartIdx,
Pel* pOrg,
Pel* pPCM,
Pel* pPred,
Pel* pResi,
Pel* pReco,
UInt uiStride,
UInt uiWidth,
UInt uiHeight,
const ComponentID compID )
2762 const Int pcmShiftRight=(channelBitDepth -
Int(uiPCMBitDepth));
2764 assert(pcmShiftRight >= 0);
2766 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
2768 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
2774 pPCM[uiX] = (pOrg[uiX]>>pcmShiftRight);
2776 pReco [uiX] = (pPCM[uiX]<<(pcmShiftRight));
2777 pRecoPic[uiX] = pReco[uiX];
2784 pRecoPic += uiReconStride;
2805 Pel * pOrig = pcOrgYuv->
getAddr (compID, 0, width);
2806 Pel * pResi = pcResiYuv->
getAddr(compID, 0, width);
2807 Pel * pPred = pcPredYuv->
getAddr(compID, 0, width);
2808 Pel * pReco = pcRecoYuv->
getAddr(compID, 0, width);
2811 xEncPCM ( pcCU, 0, pOrig, pPCM, pPred, pResi, pReco, stride, width, height, compID );
2837 UInt uiAbsPartIdx = 0;
2852 ruiErr = cDistParam.
DistFunc( &cDistParam );
2858 UInt uiAbsPartIdx = 0;
2872 UInt numSpatialMergeCandidates = 0;
2873 pcCU->
getInterMergeCandidates( 0, 0, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
2876 numValidMergeCand = numSpatialMergeCandidates;
2887 UInt numSpatialMergeCandidates = 0;
2888 pcCU->
getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, numSpatialMergeCandidates );
2891 numValidMergeCand = numSpatialMergeCandidates;
2894 pcCU->
getInterMergeCandidates( uiAbsPartIdx, iPUIdx, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
2900 ruiCost = std::numeric_limits<Distortion>::max();
2901 for(
UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
2903 Distortion uiCostCand = std::numeric_limits<Distortion>::max();
2904 UInt uiBitsCand = 0;
2912 uiBitsCand = uiMergeCand + 1;
2918 if ( uiCostCand < ruiCost )
2920 ruiCost = uiCostCand;
2921 pacMvField[0] = cMvFieldNeighbours[0 + 2*uiMergeCand];
2922 pacMvField[1] = cMvFieldNeighbours[1 + 2*uiMergeCand];
2923 uiInterDir = uhInterDirNeighbours[uiMergeCand];
2924 uiMergeIndex = uiMergeCand;
2941 for(
UInt mergeCand = 0; mergeCand < numValidMergeCand; ++mergeCand )
2943 if ( interDirNeighbours[mergeCand] == 3 )
2945 interDirNeighbours[mergeCand] = 1;
2946 mvFieldNeighbours[(mergeCand << 1) + 1].setMvField(
TComMv(0,0), -1);
2989 Int aaiMvpIdxBi[2][33];
2991 Int aaiMvpIdx[2][33];
2992 Int aaiMvpNum[2][33];
2996 Int iRefIdx[2]={0,0};
3000 Int iRoiWidth, iRoiHeight;
3002 UInt uiMbBits[3] = {1, 1, 0};
3004 UInt uiLastMode = 0;
3005 Int iRefStart, iRefEnd;
3009 Int bestBiPRefIdxL1 = 0;
3010 Int bestBiPMvpL1 = 0;
3011 Distortion biPDistTemp = std::numeric_limits<Distortion>::max();
3015 Int numValidMergeCand = 0 ;
3017 for (
Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
3019 Distortion uiCost[2] = { std::numeric_limits<Distortion>::max(), std::numeric_limits<Distortion>::max() };
3020 Distortion uiCostBi = std::numeric_limits<Distortion>::max();
3025 Distortion bestBiPDist = std::numeric_limits<Distortion>::max();
3030 uiCostTempL0[iNumRef] = std::numeric_limits<Distortion>::max();
3035 Int refIdxValidList1 = 0;
3037 Distortion costValidList1 = std::numeric_limits<Distortion>::max();
3044 Bool bTestNormalMC =
true;
3046 if ( bUseMRG && pcCU->
getWidth( 0 ) > 8 && iNumPart == 2 )
3048 bTestNormalMC =
false;
3056 for (
Int iRefList = 0; iRefList < iNumPredDir; iRefList++ )
3062 uiBitsTemp = uiMbBits[iRefList];
3065 uiBitsTemp += iRefIdxTemp+1;
3071 xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp],
false, &biPDistTemp);
3072 aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->
getMVPIdx(eRefPicList, uiPartAddr);
3073 aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->
getMVPNum(eRefPicList, uiPartAddr);
3077 bestBiPDist = biPDistTemp;
3078 bestBiPMvpL1 = aaiMvpIdx[iRefList][iRefIdxTemp];
3079 bestBiPRefIdxL1 = iRefIdxTemp;
3100 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
3105 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
3108 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
3110 if ( iRefList == 0 )
3112 uiCostTempL0[iRefIdxTemp] = uiCostTemp;
3113 uiBitsTempL0[iRefIdxTemp] = uiBitsTemp;
3115 if ( uiCostTemp < uiCost[iRefList] )
3117 uiCost[iRefList] = uiCostTemp;
3118 uiBits[iRefList] = uiBitsTemp;
3121 cMv[iRefList] = cMvTemp[iRefList][iRefIdxTemp];
3122 iRefIdx[iRefList] = iRefIdxTemp;
3125 if ( iRefList == 1 && uiCostTemp < costValidList1 && pcCU->getSlice()->getList1IdxToList0Idx( iRefIdxTemp ) < 0 )
3127 costValidList1 = uiCostTemp;
3128 bitsValidList1 = uiBitsTemp;
3131 mvValidList1 = cMvTemp[iRefList][iRefIdxTemp];
3132 refIdxValidList1 = iRefIdxTemp;
3141 cMvBi[0] = cMv[0]; cMvBi[1] = cMv[1];
3142 iRefIdxBi[0] = iRefIdx[0]; iRefIdxBi[1] = iRefIdx[1];
3144 ::memcpy(cMvPredBi, cMvPred,
sizeof(cMvPred));
3145 ::memcpy(aaiMvpIdxBi, aaiMvpIdx,
sizeof(aaiMvpIdx));
3153 aaiMvpIdxBi[1][bestBiPRefIdxL1] = bestBiPMvpL1;
3156 cMvBi[1] = cMvPredBi[1][bestBiPRefIdxL1];
3157 iRefIdxBi[1] = bestBiPRefIdxL1;
3163 uiMotBits[0] = uiBits[0] - uiMbBits[0];
3164 uiMotBits[1] = uiMbBits[1];
3168 uiMotBits[1] += bestBiPRefIdxL1+1;
3177 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
3179 cMvTemp[1][bestBiPRefIdxL1] = cMvBi[1];
3183 uiMotBits[0] = uiBits[0] - uiMbBits[0];
3184 uiMotBits[1] = uiBits[1] - uiMbBits[1];
3185 uiBits[2] = uiMbBits[2] + uiMotBits[0] + uiMotBits[1];
3197 for (
Int iIter = 0; iIter < iNumIter; iIter++ )
3199 Int iRefList = iIter % 2;
3203 if( uiCost[0] <= uiCost[1] )
3212 else if ( iIter == 0 )
3232 Bool bChanged =
false;
3237 for (
Int iRefIdxTemp = iRefStart; iRefIdxTemp <= iRefEnd; iRefIdxTemp++ )
3239 uiBitsTemp = uiMbBits[2] + uiMotBits[1-iRefList];
3242 uiBitsTemp += iRefIdxTemp+1;
3250 xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPredBi[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp,
true );
3253 xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPredBi[iRefList][iRefIdxTemp], aaiMvpIdxBi[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
3255 if ( uiCostTemp < uiCostBi )
3259 cMvBi[iRefList] = cMvTemp[iRefList][iRefIdxTemp];
3260 iRefIdxBi[iRefList] = iRefIdxTemp;
3262 uiCostBi = uiCostTemp;
3263 uiMotBits[iRefList] = uiBitsTemp - uiMbBits[2] - uiMotBits[1-iRefList];
3264 uiBits[2] = uiBitsTemp;
3269 pcCU->
getCUMvField( eRefPicList )->
setAllMv( cMvBi[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
3280 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1] )
3311 cMv[1] = mvValidList1;
3312 iRefIdx[1] = refIdxValidList1;
3313 uiBits[1] = bitsValidList1;
3314 uiCost[1] = costValidList1;
3320 if ( uiCostBi <= uiCost[0] && uiCostBi <= uiCost[1])
3328 TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
3331 TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
3341 uiMEBits = uiBits[2];
3343 else if ( uiCost[0] <= uiCost[1] )
3349 TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
3357 uiMEBits = uiBits[0];
3365 TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
3373 uiMEBits = uiBits[1];
3381 UInt uiMRGInterDir = 0;
3383 UInt uiMRGIndex = 0;
3385 UInt uiMEInterDir = 0;
3392 Distortion uiMEError = std::numeric_limits<Distortion>::max();
3393 Distortion uiMECost = std::numeric_limits<Distortion>::max();
3402 Distortion uiMEError = std::numeric_limits<Distortion>::max();
3412 Distortion uiMRGCost = std::numeric_limits<Distortion>::max();
3414 xMergeEstimation( pcCU, pcOrgYuv, iPartIdx, uiMRGInterDir, cMRGMvField, uiMRGIndex, uiMRGCost, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand);
3416 if ( uiMRGCost < uiMECost )
3471 Distortion uiBestCost = std::numeric_limits<Distortion>::max();
3472 UInt uiPartAddr = 0;
3473 Int iRoiWidth, iRoiHeight;
3482 pcCU->
fillMvpCand( uiPartIdx, uiPartAddr, eRefPicList, iRefIdx, pcAMVPInfo );
3498 maxMVPCand = pcAMVPInfo->
iN;
3504 maxMVPCand = pcAMVPInfo->
iN;
3506 if (pcAMVPInfo->
iN <= 1)
3515 (*puiDistBiP) =
xGetTemplateCost( pcCU, uiPartAddr, pcOrgYuv, &
m_cYuvPredTemp, rcMvPred, 0,
AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight);
3522 assert(pcCU->
getMVPIdx(eRefPicList,uiPartAddr) >= 0);
3529 for ( i = minMVPCand ; i < maxMVPCand; i++)
3532 uiTmpCost =
xGetTemplateCost( pcCU, uiPartAddr, pcOrgYuv, &
m_cYuvPredTemp, pcAMVPInfo->
m_acMvCand[i], i,
AMVP_MAX_NUM_CANDS, eRefPicList, iRefIdx, iRoiWidth, iRoiHeight);
3533 if ( uiBestCost > uiTmpCost )
3535 uiBestCost = uiTmpCost;
3538 (*puiDistBiP) = uiTmpCost;
3553 assert(iIdx >= 0 && iNum >= 0 && iIdx < iNum);
3567 Bool bCodeLast = ( iNum-1 > iTemp );
3569 uiLength += (iTemp-1);
3583 uiBlkBit[0] = (! bPSlice) ? 3 : 1;
3589 UInt aauiMbBits[2][3][3] = { { {0,0,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7,5,7}, {9-3,9-3,9-3} } };
3598 ::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*
sizeof(
UInt) );
3603 UInt aauiMbBits[2][3][3] = { { {0,2,3}, {0,0,0}, {0,0,0} } , { {5,7,7}, {7-2,7-2,9-2}, {9-3,9-3,9-3} } };
3612 ::memcpy( uiBlkBit, aauiMbBits[iPartIdx][uiLastMode], 3*
sizeof(
UInt) );
3617 uiBlkBit[0] = (! bPSlice) ? 3 : 1;
3630 pDst->
iN = pSrc->
iN;
3631 for (
Int i = 0; i < pSrc->
iN; i++)
3641 assert(pcAMVPInfo->
m_acMvCand[riMVPIdx] == rcMvPred);
3643 if (pcAMVPInfo->
iN < 2)
3651 Int iBestMVPIdx = riMVPIdx;
3656 Int iBestMvBits = iOrgMvBits;
3660 Int maxMVPCand = pcAMVPInfo->
iN;
3667 for (
Int iMVPIdx = minMVPCand; iMVPIdx < maxMVPCand; iMVPIdx++)
3669 for (
Int iMVPIdx = 0; iMVPIdx < pcAMVPInfo->
iN; iMVPIdx++)
3672 if (iMVPIdx == riMVPIdx)
3682 if (iMvBits < iBestMvBits)
3684 iBestMvBits = iMvBits;
3685 iBestMVPIdx = iMVPIdx;
3689 if (iBestMVPIdx != riMVPIdx)
3691 rcMvPred = pcAMVPInfo->
m_acMvCand[iBestMVPIdx];
3693 riMVPIdx = iBestMVPIdx;
3694 UInt uiOrgBits = ruiBits;
3695 ruiBits = uiOrgBits - iOrgMvBits + iBestMvBits;
3714 Distortion uiCost = std::numeric_limits<Distortion>::max();
3732 xWeightedPredictionUni( pcCU, pcTemplateCand, uiPartAddr, iSizeX, iSizeY, eRefPicList, pcTemplateCand, iRefIdx );
3737 uiCost =
m_pcRdCost->
getDistPart( pcCU->
getSlice()->
getSPS()->
getBitDepth(
CHANNEL_TYPE_LUMA), pcTemplateCand->
getAddr(
COMPONENT_Y, uiPartAddr), pcTemplateCand->
getStride(
COMPONENT_Y), pcOrgYuv->
getAddr(
COMPONENT_Y, uiPartAddr), pcOrgYuv->
getStride(
COMPONENT_Y), iSizeX, iSizeY,
COMPONENT_Y,
DF_SAD );
3780 Int roiPosX, roiPosY;
3783 assert(roiW == iRoiWidth);
3784 assert(roiH == iRoiHeight);
3804 TComMv cMvPred = *pcMvPred;
3809 xSetSearchRange(pcCU, rcMv, iSrchRng, cMvSrchRngLT, cMvSrchRngRB, &cPattern);
3817 xSetSearchRange(pcCU, cMvPred, iSrchRng, cMvSrchRngLT, cMvSrchRngRB, &cPattern);
3832 xPatternSearch ( &cPattern, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost );
3837 const TComMv *pIntegerMv2Nx2NPred=0;
3842 xPatternSearchFast ( pcCU, &cPattern, piRefY, iRefStride, &cMvSrchRngLT, &cMvSrchRngRB, rcMv, ruiCost, pIntegerMv2Nx2NPred );
3853 xPatternSearchFracDIF( bIsLosslessCoded, &cPattern, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost );
3857 rcMv += (cMvHalf <<= 1);
3862 ruiBits += uiMvBits;
3871 UInt tileXPosInCtus = 0;
3872 UInt tileYPosInCtus = 0;
3873 UInt tileWidthtInCtus = 0;
3874 UInt tileHeightInCtus = 0;
3876 getTilePosition(pcCU, tileXPosInCtus, tileYPosInCtus, tileWidthtInCtus, tileHeightInCtus);
3881 const Int tileLeftTopPelPosX = ctuLength * tileXPosInCtus;
3882 const Int tileLeftTopPelPosY = ctuLength * tileYPosInCtus;
3883 const Int tileRightBottomPelPosX = ((tileWidthtInCtus + tileXPosInCtus) * ctuLength) - 1;
3884 const Int tileRightBottomPelPosY = ((tileHeightInCtus + tileYPosInCtus) * ctuLength) - 1;
3886 pcPatternKey->
setTileBorders (tileLeftTopPelPosX,tileLeftTopPelPosY,tileRightBottomPelPosX,tileRightBottomPelPosY);
3900 TComMv cTmpMvPred = cMvPred;
3901 pcCU->
clipMv( cTmpMvPred );
3911 rcMvSrchRngLT.setHor(lRangeXLeft);
3912 rcMvSrchRngLT.setVer(lRangeYTop);
3914 rcMvSrchRngRB.
setHor(lRangeXRight);
3915 rcMvSrchRngRB.
setVer(lRangeYBottom);
3919 rcMvSrchRngLT.setHor(cTmpMvPred.
getHor() - (iSrchRng << iMvShift));
3920 rcMvSrchRngLT.setVer(cTmpMvPred.
getVer() - (iSrchRng << iMvShift));
3922 rcMvSrchRngRB.
setHor( cTmpMvPred.
getHor() + (iSrchRng << iMvShift));
3923 rcMvSrchRngRB.
setVer( cTmpMvPred.
getVer() + (iSrchRng << iMvShift) );
3926 rcMvSrchRngLT.setHor( cTmpMvPred.
getHor() - (iSrchRng << iMvShift) );
3927 rcMvSrchRngLT.setVer( cTmpMvPred.
getVer() - (iSrchRng << iMvShift) );
3929 rcMvSrchRngRB.
setHor( cTmpMvPred.
getHor() + (iSrchRng << iMvShift));
3930 rcMvSrchRngRB.
setVer( cTmpMvPred.
getVer() + (iSrchRng << iMvShift) );
3933 pcCU->
clipMv ( rcMvSrchRngLT );
3934 pcCU->
clipMv ( rcMvSrchRngRB );
3936 #if ME_ENABLE_ROUNDING_OF_MVS
3937 rcMvSrchRngLT.divideByPowerOf2(iMvShift);
3940 rcMvSrchRngLT >>= iMvShift;
3941 rcMvSrchRngRB >>= iMvShift;
3948 const Int iRefStride,
3949 const TComMv*
const pcMvSrchRngLT,
3950 const TComMv*
const pcMvSrchRngRB,
3954 Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
3955 Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
3956 Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
3957 Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
3960 Distortion uiSadBest = std::numeric_limits<Distortion>::max();
3976 piRefY += (iSrchRngVerTop * iRefStride);
3977 for (
Int y = iSrchRngVerTop; y <= iSrchRngVerBottom; y++ )
3979 for (
Int x = iSrchRngHorLeft; x <= iSrchRngHorRight; x++ )
3992 if ( uiSad < uiSadBest )
4000 piRefY += iRefStride;
4003 rcMv.
set( iBestX, iBestY );
4012 const Pel*
const piRefY,
4013 const Int iRefStride,
4014 const TComMv*
const pcMvSrchRngLT,
4015 const TComMv*
const pcMvSrchRngRB,
4018 const TComMv*
const pIntegerMv2Nx2NPred )
4030 xTZSearch( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred,
false );
4034 xTZSearchSelective( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred );
4038 xTZSearch( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred,
true );
4050 const Pel*
const piRefY,
4051 const Int iRefStride,
4052 const TComMv*
const pcMvSrchRngLT,
4053 const TComMv*
const pcMvSrchRngRB,
4056 const TComMv*
const pIntegerMv2Nx2NPred,
4057 const Bool bExtendedSettings)
4059 const Bool bUseAdaptiveRaster = bExtendedSettings;
4060 const Int iRaster = 5;
4061 const Bool bTestOtherPredictedMV = bExtendedSettings;
4062 const Bool bTestZeroVector =
true;
4063 const Bool bTestZeroVectorStart = bExtendedSettings;
4064 const Bool bTestZeroVectorStop =
false;
4065 const Bool bFirstSearchDiamond =
true;
4066 const Bool bFirstCornersForDiamondDist1 = bExtendedSettings;
4068 const UInt uiFirstSearchRounds = 3;
4069 const Bool bEnableRasterSearch =
true;
4070 const Bool bAlwaysRasterSearch = bExtendedSettings;
4071 const Bool bRasterRefinementEnable =
false;
4072 const Bool bRasterRefinementDiamond =
false;
4073 const Bool bRasterRefinementCornersForDiamondDist1 = bExtendedSettings;
4074 const Bool bStarRefinementEnable =
true;
4075 const Bool bStarRefinementDiamond =
true;
4076 const Bool bStarRefinementCornersForDiamondDist1 = bExtendedSettings;
4077 const Bool bStarRefinementStop =
false;
4078 const UInt uiStarRefinementRounds = 2;
4079 const Bool bNewZeroNeighbourhoodTest = bExtendedSettings;
4083 #if ME_ENABLE_ROUNDING_OF_MVS
4098 if ( bTestOtherPredictedMV )
4104 #if ME_ENABLE_ROUNDING_OF_MVS
4118 if ( bTestZeroVector )
4128 Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
4129 Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
4130 Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
4131 Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
4133 if (pIntegerMv2Nx2NPred != 0)
4135 TComMv integerMv2Nx2NPred = *pIntegerMv2Nx2NPred;
4136 integerMv2Nx2NPred <<= 2;
4137 pcCU->
clipMv( integerMv2Nx2NPred );
4138 #if ME_ENABLE_ROUNDING_OF_MVS
4141 integerMv2Nx2NPred >>= 2;
4143 if ((rcMv != integerMv2Nx2NPred) &&
4157 xSetSearchRange(pcCU, currBestMv, iSrchRng, cMvSrchRngLT, cMvSrchRngRB, pcPatternKey);
4159 xSetSearchRange(pcCU, currBestMv, iSrchRng, cMvSrchRngLT, cMvSrchRngRB);
4161 iSrchRngHorLeft = cMvSrchRngLT.
getHor();
4162 iSrchRngHorRight = cMvSrchRngRB.
getHor();
4163 iSrchRngVerTop = cMvSrchRngLT.
getVer();
4164 iSrchRngVerBottom = cMvSrchRngRB.
getVer();
4172 const Bool bBestCandidateZero = (cStruct.
iBestX == 0) && (cStruct.
iBestY == 0);
4176 for ( iDist = 1; iDist <= (
Int)uiSearchRange; iDist*=2 )
4178 if ( bFirstSearchDiamond == 1 )
4180 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist, bFirstCornersForDiamondDist1 );
4184 xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist );
4187 if ( bFirstSearchStop && ( cStruct.
uiBestRound >= uiFirstSearchRounds ) )
4193 if (!bNewZeroNeighbourhoodTest)
4196 if ( bTestZeroVectorStart && ((cStruct.
iBestX != 0) || (cStruct.
iBestY != 0)) )
4202 for ( iDist = 1; iDist <= (
Int)uiSearchRange; iDist*=2 )
4205 if ( bTestZeroVectorStop && (cStruct.
uiBestRound > 0) )
4219 if (bTestZeroVectorStart ==
true && bBestCandidateZero !=
true)
4221 for ( iDist = 1; iDist <= ((Int)uiSearchRange >> 1); iDist*=2 )
4224 if ( bTestZeroVectorStop && (cStruct.
uiBestRound > 2) )
4236 xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB );
4240 if (bUseAdaptiveRaster)
4242 Int iWindowSize = iRaster;
4243 Int iSrchRngRasterLeft = iSrchRngHorLeft;
4244 Int iSrchRngRasterRight = iSrchRngHorRight;
4245 Int iSrchRngRasterTop = iSrchRngVerTop;
4246 Int iSrchRngRasterBottom = iSrchRngVerBottom;
4251 iSrchRngRasterLeft /= 2;
4252 iSrchRngRasterRight /= 2;
4253 iSrchRngRasterTop /= 2;
4254 iSrchRngRasterBottom /= 2;
4257 for ( iStartY = iSrchRngRasterTop; iStartY <= iSrchRngRasterBottom; iStartY += iWindowSize )
4259 for ( iStartX = iSrchRngRasterLeft; iStartX <= iSrchRngRasterRight; iStartX += iWindowSize )
4261 xTZSearchHelp( pcPatternKey, cStruct, iStartX, iStartY, 0, iWindowSize );
4267 if ( bEnableRasterSearch && ( ((
Int)(cStruct.
uiBestDistance) > iRaster) || bAlwaysRasterSearch ) )
4270 for ( iStartY = iSrchRngVerTop; iStartY <= iSrchRngVerBottom; iStartY += iRaster )
4272 for ( iStartX = iSrchRngHorLeft; iStartX <= iSrchRngHorRight; iStartX += iRaster )
4274 xTZSearchHelp( pcPatternKey, cStruct, iStartX, iStartY, 0, iRaster );
4286 iStartX = cStruct.
iBestX;
4287 iStartY = cStruct.
iBestY;
4291 if ( bRasterRefinementDiamond == 1 )
4293 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist, bRasterRefinementCornersForDiamondDist1 );
4297 xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist );
4307 xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB );
4318 iStartX = cStruct.
iBestX;
4319 iStartY = cStruct.
iBestY;
4322 for ( iDist = 1; iDist < (
Int)uiSearchRange + 1; iDist*=2 )
4324 if ( bStarRefinementDiamond == 1 )
4326 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist, bStarRefinementCornersForDiamondDist1 );
4330 xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist );
4332 if ( bStarRefinementStop && (cStruct.
uiBestRound >= uiStarRefinementRounds) )
4344 xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB );
4358 const Pel*
const piRefY,
4359 const Int iRefStride,
4360 const TComMv*
const pcMvSrchRngLT,
4361 const TComMv*
const pcMvSrchRngRB,
4364 const TComMv*
const pIntegerMv2Nx2NPred )
4366 const Bool bTestOtherPredictedMV =
true;
4367 const Bool bTestZeroVector =
true;
4368 const Bool bEnableRasterSearch =
true;
4369 const Bool bAlwaysRasterSearch =
false;
4370 const Bool bStarRefinementEnable =
true;
4371 const Bool bStarRefinementDiamond =
true;
4372 const Bool bStarRefinementStop =
false;
4373 const UInt uiStarRefinementRounds = 2;
4376 const Int uiSearchStep = 4;
4377 const Int iMVDistThresh = 8;
4379 Int iSrchRngHorLeft = pcMvSrchRngLT->
getHor();
4380 Int iSrchRngHorRight = pcMvSrchRngRB->
getHor();
4381 Int iSrchRngVerTop = pcMvSrchRngLT->
getVer();
4382 Int iSrchRngVerBottom = pcMvSrchRngRB->
getVer();
4383 Int iFirstSrchRngHorLeft = 0;
4384 Int iFirstSrchRngHorRight = 0;
4385 Int iFirstSrchRngVerTop = 0;
4386 Int iFirstSrchRngVerBottom = 0;
4394 #if ME_ENABLE_ROUNDING_OF_MVS
4412 if ( bTestOtherPredictedMV )
4418 #if ME_ENABLE_ROUNDING_OF_MVS
4428 if ( bTestZeroVector )
4433 if ( pIntegerMv2Nx2NPred != 0 )
4435 TComMv integerMv2Nx2NPred = *pIntegerMv2Nx2NPred;
4436 integerMv2Nx2NPred <<= 2;
4437 pcCU->
clipMv( integerMv2Nx2NPred );
4438 #if ME_ENABLE_ROUNDING_OF_MVS
4441 integerMv2Nx2NPred >>= 2;
4452 xSetSearchRange(pcCU, currBestMv, iSrchRng, cMvSrchRngLT, cMvSrchRngRB, pcPatternKey);
4454 xSetSearchRange(pcCU, currBestMv, iSrchRng, cMvSrchRngLT, cMvSrchRngRB);
4456 iSrchRngHorLeft = cMvSrchRngLT.getHor();
4457 iSrchRngHorRight = cMvSrchRngRB.
getHor();
4458 iSrchRngVerTop = cMvSrchRngLT.getVer();
4459 iSrchRngVerBottom = cMvSrchRngRB.
getVer();
4465 iFirstSrchRngHorLeft = ((iBestX - uiSearchRangeInitial) > iSrchRngHorLeft) ? (iBestX - uiSearchRangeInitial) : iSrchRngHorLeft;
4466 iFirstSrchRngVerTop = ((iBestY - uiSearchRangeInitial) > iSrchRngVerTop) ? (iBestY - uiSearchRangeInitial) : iSrchRngVerTop;
4467 iFirstSrchRngHorRight = ((iBestX + uiSearchRangeInitial) < iSrchRngHorRight) ? (iBestX + uiSearchRangeInitial) : iSrchRngHorRight;
4468 iFirstSrchRngVerBottom = ((iBestY + uiSearchRangeInitial) < iSrchRngVerBottom) ? (iBestY + uiSearchRangeInitial) : iSrchRngVerBottom;
4470 for ( iStartY = iFirstSrchRngVerTop; iStartY <= iFirstSrchRngVerBottom; iStartY += uiSearchStep )
4472 for ( iStartX = iFirstSrchRngHorLeft; iStartX <= iFirstSrchRngHorRight; iStartX += uiSearchStep )
4474 xTZSearchHelp( pcPatternKey, cStruct, iStartX, iStartY, 0, 0 );
4475 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, 1,
false );
4476 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, 2,
false );
4480 Int iMaxMVDistToPred = (abs(cStruct.
iBestX - iBestX) > iMVDistThresh || abs(cStruct.
iBestY - iBestY) > iMVDistThresh);
4483 if ( bEnableRasterSearch && (iMaxMVDistToPred || bAlwaysRasterSearch) )
4485 for ( iStartY = iSrchRngVerTop; iStartY <= iSrchRngVerBottom; iStartY += 1 )
4487 for ( iStartX = iSrchRngHorLeft; iStartX <= iSrchRngHorRight; iStartX += 1 )
4489 xTZSearchHelp( pcPatternKey, cStruct, iStartX, iStartY, 0, 1 );
4499 iStartX = cStruct.
iBestX;
4500 iStartY = cStruct.
iBestY;
4503 for ( iDist = 1; iDist < (
Int)uiSearchRange + 1; iDist*=2 )
4505 if ( bStarRefinementDiamond == 1 )
4507 xTZ8PointDiamondSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist,
false );
4511 xTZ8PointSquareSearch ( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB, iStartX, iStartY, iDist );
4513 if ( bStarRefinementStop && (cStruct.
uiBestRound >= uiStarRefinementRounds) )
4525 xTZ2PointSearch( pcPatternKey, cStruct, pcMvSrchRngLT, pcMvSrchRngRB );
4539 Bool bIsLosslessCoded,
4570 rcMvHalf = *pcMvInt; rcMvHalf <<= 1;
4572 ruiCost =
xPatternRefinement( pcPatternKey, baseRefMv, 2, rcMvHalf, !bIsLosslessCoded );
4577 baseRefMv = rcMvHalf;
4580 rcMvQter = *pcMvInt; rcMvQter <<= 1;
4581 rcMvQter += rcMvHalf; rcMvQter <<= 1;
4582 ruiCost =
xPatternRefinement( pcPatternKey, baseRefMv, 1, rcMvQter, !bIsLosslessCoded );
4601 if ( bSkipResidual )
4610 for (
Int comp=0; comp < numValidComponents; comp++)
4616 pcYuvOrg->
getStride(compID), cuWidthPixels >> csx, cuHeightPixels >> csy, compID);
4638 pcYuvResiBest->
clear();
4641 sDebug+=debug_reorder_data_inter_token[i];
4650 pcYuvResi->
subtract( pcYuvOrg, pcYuvPred, 0, cuWidthPixels );
4655 UInt nonZeroBits = 0;
4673 if ( zeroCost < nonZeroCost || !pcCU->getQtRootCbf(0) )
4677 for (
Int comp=0; comp < numValidComponents; comp++)
4680 ::memset( pcCU->
getCbf( component ) , 0, uiQPartNum *
sizeof(
UChar) );
4689 sDebug+=debug_reorder_data_inter_token[i];
4707 pcYuvResiBest->
clear();
4720 for(
Int comp=0; comp<numValidComponents; comp++)
4742 const UInt uiAbsPartIdx = rTu.GetAbsPartIdxTU();
4743 const UInt uiDepth = rTu.GetTransformDepthTotal();
4744 const UInt uiTrMode = rTu.GetTransformDepthRel();
4745 const UInt subTUDepth = uiTrMode + 1;
4750 const UInt uiLog2TrSize = rTu.GetLog2LumaTrSize();
4754 const Int debugPredModeMask = DebugStringGetPredModeMask(pcCU->
getPredictionMode(uiAbsPartIdx));
4770 assert( bCheckFull || bCheckSplit );
4774 UInt uiSingleBits = 0;
4797 #if ADAPTIVE_QP_SELECTION
4801 for(
UInt i=0; i<numValidComp; i++)
4809 for(
UInt i=0; i<numValidComp; i++)
4811 checkTransformSkip[i]=
false;
4814 pcCoeffCurr[compID] =
m_ppcQTTempCoeff[compID][uiQTTempAccessLayer] + rTu.getCoefficientOffset(compID);
4815 #if ADAPTIVE_QP_SELECTION
4816 pcArlCoeffCurr[compID] =
m_ppcQTTempArlCoeff[compID ][uiQTTempAccessLayer] + rTu.getCoefficientOffset(compID);
4819 if(rTu.ProcessComponentSection(compID))
4821 const QpParam cQP(*pcCU, compID);
4827 const Bool splitIntoSubTUs = rTu.getRect(compID).width != rTu.getRect(compID).height;
4838 const UInt subTUBufferOffset = tuCompRect.
width * tuCompRect.
height * subTUIndex;
4840 TCoeff *currentCoefficients = pcCoeffCurr[compID] + subTUBufferOffset;
4841 #if ADAPTIVE_QP_SELECTION
4842 TCoeff *currentARLCoefficients = pcArlCoeffCurr[compID] + subTUBufferOffset;
4844 const Bool isCrossCPredictionAvailable =
isChroma(compID)
4848 SChar preCalcAlpha = 0;
4851 if (isCrossCPredictionAvailable)
4854 const Pel *
const lumaResidualForEstimate = bUseReconstructedResidualForEstimate ? pLumaResi : pcResi->
getAddrPix(
COMPONENT_Y, tuCompRect.
x0, tuCompRect.
y0);
4859 lumaResidualForEstimate,
4863 lumaResidualStrideForEstimate,
4867 const Int transformSkipModesToTest = checkTransformSkip[compID] ? 2 : 1;
4868 const Int crossCPredictionModesToTest = (preCalcAlpha != 0) ? 2 : 1;
4870 const Bool isOneMode = (crossCPredictionModesToTest == 1) && (transformSkipModesToTest == 1);
4872 for (
Int transformSkipModeId = 0; transformSkipModeId < transformSkipModesToTest; transformSkipModeId++)
4876 for (
Int crossCPredictionModeId = 0; crossCPredictionModeId < crossCPredictionModesToTest; crossCPredictionModeId++)
4878 const Bool isFirstMode = (transformSkipModeId == 0) && (crossCPredictionModeId == 0);
4879 const Bool bUseCrossCPrediction = crossCPredictionModeId != 0;
4893 #if RDOQ_CHROMA_LAMBDA
4903 #if ADAPTIVE_QP_SELECTION
4907 UInt currCompBits = 0;
4910 UInt nonCoeffBits = 0;
4914 if(!isOneMode && !isFirstMode)
4916 memcpy(bestCoeffComp, currentCoefficients, (
sizeof(
TCoeff) * tuCompRect.
width * tuCompRect.
height));
4917 #if ADAPTIVE_QP_SELECTION
4918 memcpy(bestArlCoeffComp, currentARLCoefficients, (
sizeof(
TCoeff) * tuCompRect.
width * tuCompRect.
height));
4920 for(
Int y = 0; y < tuCompRect.
height; y++)
4922 memcpy(&bestResiComp[y * tuCompRect.
width], (pcResiCurrComp + (y * resiStride)), (
sizeof(
Pel) * tuCompRect.
width));
4926 if (bUseCrossCPrediction)
4932 crossCPredictedResidualBuffer,
4942 currentARLCoefficients,
4949 #if ADAPTIVE_QP_SELECTION
4950 currentARLCoefficients,
4955 if(isFirstMode || (currAbsSum == 0))
4957 if (bUseCrossCPrediction)
4983 if ( isCrossCPredictionAvailable )
4992 if((puiZeroDist !=
NULL) && isFirstMode)
4994 *puiZeroDist += nonCoeffDist;
4999 if( currAbsSum > 0 )
5009 if (isCrossCPredictionAvailable)
5021 if (bUseCrossCPrediction)
5049 else if ((transformSkipModeId == 1) && !bUseCrossCPrediction)
5055 currCompBits = nonCoeffBits;
5056 currCompDist = nonCoeffDist;
5057 currCompCost = nonCoeffCost;
5061 if ((currCompCost < minCost[compID][subTUIndex]) || ((transformSkipModeId == 1) && (currCompCost == minCost[compID][subTUIndex])))
5063 bestExplicitRdpcmModeUnSplit[compID][subTUIndex] = pcCU->
getExplicitRdpcmMode(compID, subTUAbsPartIdx);
5067 if((nonCoeffCost < currCompCost) || (currAbsSum == 0))
5069 memset(currentCoefficients, 0, (
sizeof(
TCoeff) * tuCompRect.
width * tuCompRect.
height));
5072 currCompBits = nonCoeffBits;
5073 currCompDist = nonCoeffDist;
5074 currCompCost = nonCoeffCost;
5085 sSingleStringComp[compID].clear();
5089 uiAbsSum [compID][subTUIndex] = currAbsSum;
5090 uiSingleDistComp [compID][subTUIndex] = currCompDist;
5091 minCost [compID][subTUIndex] = currCompCost;
5092 uiBestTransformMode [compID][subTUIndex] = transformSkipModeId;
5093 bestCrossCPredictionAlpha[compID][subTUIndex] = (crossCPredictionModeId == 1) ? pcCU->