74 const Int chromaQPOffset,
81 baseQp = qpy + qpBdOffset;
89 baseQp = baseQp + qpBdOffset;
104 Int chromaQpOffset = 0;
153 #if ADAPTIVE_QP_SELECTION
161 Double alpha = qpBase < 17 ? 0.5 : 1;
171 sliceQpused = qpBase;
196 if(qnext < alpha * q[v] + (1 - alpha) * q[v+1] )
201 sliceQpnext =
Clip3(sliceQpused - 3, sliceQpused + 3, v);
205 sliceQpnext = sliceQpused;
208 m_qpDelta[qpBase] = sliceQpnext - qpBase;
248 else if (uiTrSize==8)
252 else if (uiTrSize==16)
256 else if (uiTrSize==32)
267 const Int shift_1st = (uiLog2TrSize + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange;
268 const Int shift_2nd = uiLog2TrSize + TRANSFORM_MATRIX_SHIFT;
269 const Int add_1st = (shift_1st>0) ? (1<<(shift_1st-1)) : 0;
270 const Int add_2nd = 1<<(shift_2nd-1);
274 for (i=0; i<uiTrSize; i++)
276 for (j=0; j<uiTrSize; j++)
279 for (k=0; k<uiTrSize; k++)
281 iSum += iT[i*uiTrSize+k]*block[j*uiStride+k];
283 tmp[i*uiTrSize+j] = (iSum + add_1st)>>shift_1st;
288 for (i=0; i<uiTrSize; i++)
290 for (j=0; j<uiTrSize; j++)
293 for (k=0; k<uiTrSize; k++)
295 iSum += iT[i*uiTrSize+k]*tmp[j*uiTrSize+k];
297 coeff[i*uiTrSize+j] = (iSum + add_2nd)>>shift_2nd;
320 else if (uiTrSize==8)
324 else if (uiTrSize==16)
328 else if (uiTrSize==32)
339 const Int shift_1st = TRANSFORM_MATRIX_SHIFT + 1;
340 const Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1) - bitDepth;
341 const TCoeff clipMinimum = -(1 << maxLog2TrDynamicRange);
342 const TCoeff clipMaximum = (1 << maxLog2TrDynamicRange) - 1;
343 assert(shift_2nd>=0);
344 const Int add_1st = 1<<(shift_1st-1);
345 const Int add_2nd = (shift_2nd>0) ? (1<<(shift_2nd-1)) : 0;
348 for (i=0; i<uiTrSize; i++)
350 for (j=0; j<uiTrSize; j++)
353 for (k=0; k<uiTrSize; k++)
355 iSum += iT[k*uiTrSize+i]*coeff[k*uiTrSize+j];
359 tmp[i*uiTrSize+j] = Clip3<TCoeff>(clipMinimum, clipMaximum, (iSum + add_1st)>>shift_1st);
364 for (i=0; i<uiTrSize; i++)
366 for (j=0; j<uiTrSize; j++)
369 for (k=0; k<uiTrSize; k++)
371 iSum += iT[k*uiTrSize+j]*tmp[i*uiTrSize+k];
374 block[i*uiStride+j] = Clip3<TCoeff>(std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max(), (iSum + add_2nd)>>shift_2nd);
392 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
394 for (j=0; j<line; j++)
397 E[0] = src[0] + src[3];
398 O[0] = src[0] - src[3];
399 E[1] = src[1] + src[2];
400 O[1] = src[1] - src[2];
418 TCoeff rnd_factor = (shift > 0) ? (1<<(shift-1)) : 0;
427 for (
Int row = 0; row < 4; row++)
430 for (
Int column = 0; column < 4; column++)
435 coeff[(row * 4) + i] =
rightShift((result + rnd_factor), shift);
444 TCoeff rnd_factor = (shift > 0) ? (1<<(shift-1)) : 0;
453 for (
Int column = 0; column < 4; column++)
455 TCoeff &result = block[(i * 4) + column];
458 for (
Int row = 0; row < 4; row++)
463 result =
Clip3( outputMinimum, outputMaximum,
rightShift((result + rnd_factor), shift));
480 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
482 for (j=0; j<line; j++)
491 dst[0] =
Clip3( outputMinimum, outputMaximum, (E[0] + O[0] + add)>>shift );
492 dst[1] =
Clip3( outputMinimum, outputMaximum, (E[1] + O[1] + add)>>shift );
493 dst[2] =
Clip3( outputMinimum, outputMaximum, (E[1] - O[1] + add)>>shift );
494 dst[3] =
Clip3( outputMinimum, outputMaximum, (E[0] - O[0] + add)>>shift );
512 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
514 for (j=0; j<line; j++)
519 E[k] = src[k] + src[7-k];
520 O[k] = src[k] - src[7-k];
556 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
558 for (j=0; j<line; j++)
573 E[0] = EE[0] + EO[0];
574 E[3] = EE[0] - EO[0];
575 E[1] = EE[1] + EO[1];
576 E[2] = EE[1] - EO[1];
579 dst[ k ] =
Clip3( outputMinimum, outputMaximum, (E[k] + O[k] + add)>>shift );
580 dst[ k+4 ] =
Clip3( outputMinimum, outputMaximum, (E[3-k] - O[3-k] + add)>>shift );
599 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
601 for (j=0; j<line; j++)
606 E[k] = src[k] + src[15-k];
607 O[k] = src[k] - src[15-k];
612 EE[k] = E[k] + E[7-k];
613 EO[k] = E[k] - E[7-k];
616 EEE[0] = EE[0] + EE[3];
617 EEO[0] = EE[0] - EE[3];
618 EEE[1] = EE[1] + EE[2];
619 EEO[1] = EE[1] - EE[2];
660 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
662 for (j=0; j<line; j++)
685 EE[k] = EEE[k] + EEO[k];
686 EE[k+2] = EEE[1-k] - EEO[1-k];
690 E[k] = EE[k] + EO[k];
691 E[k+4] = EE[3-k] - EO[3-k];
695 dst[k] =
Clip3( outputMinimum, outputMaximum, (E[k] + O[k] + add)>>shift );
696 dst[k+8] =
Clip3( outputMinimum, outputMaximum, (E[7-k] - O[7-k] + add)>>shift );
716 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
718 for (j=0; j<line; j++)
723 E[k] = src[k] + src[31-k];
724 O[k] = src[k] - src[31-k];
729 EE[k] = E[k] + E[15-k];
730 EO[k] = E[k] - E[15-k];
735 EEE[k] = EE[k] + EE[7-k];
736 EEO[k] = EE[k] - EE[7-k];
739 EEEE[0] = EEE[0] + EEE[3];
740 EEEO[0] = EEE[0] - EEE[3];
741 EEEE[1] = EEE[1] + EEE[2];
742 EEEO[1] = EEE[1] - EEE[2];
792 TCoeff add = (shift > 0) ? (1<<(shift-1)) : 0;
794 for (j=0; j<line; j++)
826 EEE[0] = EEEE[0] + EEEO[0];
827 EEE[3] = EEEE[0] - EEEO[0];
828 EEE[1] = EEEE[1] + EEEO[1];
829 EEE[2] = EEEE[1] - EEEO[1];
832 EE[k] = EEE[k] + EEO[k];
833 EE[k+4] = EEE[3-k] - EEO[3-k];
837 E[k] = EE[k] + EO[k];
838 E[k+8] = EE[7-k] - EO[7-k];
842 dst[k] =
Clip3( outputMinimum, outputMaximum, (E[k] + O[k] + add)>>shift );
843 dst[k+16] =
Clip3( outputMinimum, outputMaximum, (E[15-k] - O[15-k] + add)>>shift );
864 const Int shift_1st = ((
g_aucConvertToBit[iWidth] + 2) + bitDepth + TRANSFORM_MATRIX_SHIFT) - maxLog2TrDynamicRange;
867 assert(shift_1st >= 0);
868 assert(shift_2nd >= 0);
876 if ((iHeight == 4) && useDST)
891 assert(0); exit (1);
break;
898 if ((iWidth == 4) && useDST)
913 assert(0); exit (1);
break;
931 Int shift_1st = TRANSFORM_MATRIX_SHIFT + 1;
932 Int shift_2nd = (TRANSFORM_MATRIX_SHIFT + maxLog2TrDynamicRange - 1) - bitDepth;
933 const TCoeff clipMinimum = -(1 << maxLog2TrDynamicRange);
934 const TCoeff clipMaximum = (1 << maxLog2TrDynamicRange) - 1;
936 assert(shift_1st >= 0);
937 assert(shift_2nd >= 0);
945 if ((iWidth == 4) && useDST)
961 assert(0); exit (1);
break;
969 if ((iHeight == 4) && useDST)
971 fastInverseDst( tmp, block, shift_2nd, std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max() );
975 partialButterflyInverse4 ( tmp, block, shift_2nd, iHeight, std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max());
980 case 8:
partialButterflyInverse8 ( tmp, block, shift_2nd, iHeight, std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max());
break;
981 case 16:
partialButterflyInverse16( tmp, block, shift_2nd, iHeight, std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max());
break;
982 case 32:
partialButterflyInverse32( tmp, block, shift_2nd, iHeight, std::numeric_limits<Pel>::min(), std::numeric_limits<Pel>::max());
break;
985 assert(0); exit (1);
break;
997 const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
998 const TCoeff entropyCodingMaximum = (1 << maxLog2TrDynamicRange) - 1;
1004 for(
Int subSet = (width*height-1) >>
MLS_CG_SIZE; subSet >= 0; subSet-- )
1007 Int firstNZPosInCG=groupSize , lastNZPosInCG=-1 ;
1010 for(n = groupSize-1; n >= 0; --n )
1012 if( pQCoef[ codingParameters.
scan[ n + subPos ]] )
1019 for(n = 0; n <groupSize; n++ )
1021 if( pQCoef[ codingParameters.
scan[ n + subPos ]] )
1028 for(n = firstNZPosInCG; n <=lastNZPosInCG; n++ )
1030 absSum +=
Int(pQCoef[ codingParameters.
scan[ n + subPos ]]);
1033 if(lastNZPosInCG>=0 && lastCG==-1)
1040 UInt signbit = (pQCoef[codingParameters.
scan[subPos+firstNZPosInCG]]>0?0:1) ;
1041 if( signbit!=(absSum&0x1) )
1043 TCoeff curCost = std::numeric_limits<TCoeff>::max();
1044 TCoeff minCostInc = std::numeric_limits<TCoeff>::max();
1045 Int minPos =-1, finalChange=0, curChange=0;
1047 for( n = (lastCG==1?lastNZPosInCG:groupSize-1) ; n >= 0; --n )
1049 UInt blkPos = codingParameters.
scan[ n+subPos ];
1050 if(pQCoef[ blkPos ] != 0 )
1052 if(deltaU[blkPos]>0)
1054 curCost = - deltaU[blkPos];
1060 if(n==firstNZPosInCG && abs(pQCoef[blkPos])==1)
1062 curCost = std::numeric_limits<TCoeff>::max();
1066 curCost = deltaU[blkPos];
1073 if(n<firstNZPosInCG)
1075 UInt thisSignBit = (pCoef[blkPos]>=0?0:1);
1076 if(thisSignBit != signbit )
1078 curCost = std::numeric_limits<TCoeff>::max();
1082 curCost = - (deltaU[blkPos]) ;
1088 curCost = - (deltaU[blkPos]) ;
1093 if( curCost<minCostInc)
1095 minCostInc = curCost ;
1096 finalChange = curChange ;
1101 if(pQCoef[minPos] == entropyCodingMaximum || pQCoef[minPos] == entropyCodingMinimum)
1106 if(pCoef[minPos]>=0)
1108 pQCoef[minPos] += finalChange ;
1112 pQCoef[minPos] -= finalChange ;
1145 #if ADAPTIVE_QP_SELECTION
1146 TCoeff* piArlCCoef = pArlDes;
1157 #if ADAPTIVE_QP_SELECTION
1165 memset( pDes, 0,
sizeof(
TCoeff ) * uiWidth *uiHeight );
1174 const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
1175 const TCoeff entropyCodingMaximum = (1 << maxLog2TrDynamicRange) - 1;
1198 iTransformShift = std::max<Int>(0, iTransformShift);
1204 #if ADAPTIVE_QP_SELECTION
1211 iAddC = 1 << (iQBitsC-1);
1216 const Int qBits8 = iQBits - 8;
1218 for(
Int uiBlockPos = 0; uiBlockPos < uiWidth*uiHeight; uiBlockPos++ )
1220 const TCoeff iLevel = piCoef[uiBlockPos];
1221 const TCoeff iSign = (iLevel < 0 ? -1: 1);
1223 const Int64 tmpLevel = (
Int64)abs(iLevel) * (enableScalingLists ? piQuantCoeff[uiBlockPos] : defaultQuantisationCoefficient);
1225 #if ADAPTIVE_QP_SELECTION
1228 piArlCCoef[uiBlockPos] = (
TCoeff)((tmpLevel + iAddC ) >> iQBitsC);
1232 const TCoeff quantisedMagnitude =
TCoeff((tmpLevel + iAdd ) >> iQBits);
1233 deltaU[uiBlockPos] = (
TCoeff)((tmpLevel - (quantisedMagnitude<<iQBits) )>> qBits8);
1235 uiAbsSum += quantisedMagnitude;
1236 const TCoeff quantisedCoefficient = quantisedMagnitude * iSign;
1238 piQCoef[uiBlockPos] = Clip3<TCoeff>( entropyCodingMinimum, entropyCodingMaximum, quantisedCoefficient );
1245 signBitHidingHDQ( piQCoef, piCoef, deltaU, codingParameters, maxLog2TrDynamicRange ) ;
1285 iTransformShift = std::max<Int>(0, iTransformShift);
1292 const Int iAdd = (compID ==
COMPONENT_Y ? 171 : 256) << (iQBits-9);
1294 for(
Int uiBlockPos = 0; uiBlockPos < uiWidth*uiHeight; uiBlockPos++ )
1296 const TCoeff iLevel = piCoef[uiBlockPos];
1297 const Int64 tmpLevel = (
Int64)abs(iLevel) * (enableScalingLists ? piQuantCoeff[uiBlockPos] : defaultQuantisationCoefficient);
1298 const TCoeff quantisedMagnitude =
TCoeff((tmpLevel + iAdd ) >> iQBits);
1300 if ( quantisedMagnitude != 0 )
1321 const TCoeff *
const piQCoef = pSrc;
1322 TCoeff *
const piCoef = pDes;
1324 const UInt numSamplesInBlock = uiWidth*uiHeight;
1326 const TCoeff transformMinimum = -(1 << maxLog2TrDynamicRange);
1327 const TCoeff transformMaximum = (1 << maxLog2TrDynamicRange) - 1;
1330 #if O0043_BEST_EFFORT_DECODING
1341 const Int originalTransformShift =
getTransformShift(channelBitDepth, uiLog2TrSize, maxLog2TrDynamicRange);
1342 const Int iTransformShift = bClipTransformShiftTo0 ? std::max<Int>(0, originalTransformShift) : originalTransformShift;
1344 const Int QP_per = cQP.
per;
1345 const Int QP_rem = cQP.
rem;
1349 if(enableScalingLists)
1355 const UInt targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((
sizeof(
Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
1358 const Intermediate_Int inputMaximum = (1 << (targetInputBitDepth - 1)) - 1;
1366 for(
Int n = 0; n < numSamplesInBlock; n++ )
1368 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, piQCoef[n]));
1371 piCoef[n] =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
1378 for(
Int n = 0; n < numSamplesInBlock; n++ )
1380 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, piQCoef[n]));
1383 piCoef[n] =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
1397 const Intermediate_Int inputMaximum = (1 << (targetInputBitDepth - 1)) - 1;
1403 for(
Int n = 0; n < numSamplesInBlock; n++ )
1405 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, piQCoef[n]));
1408 piCoef[n] =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
1415 for(
Int n = 0; n < numSamplesInBlock; n++ )
1417 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, piQCoef[n]));
1420 piCoef[n] =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
1430 Bool useSelectiveRDOQ,
1432 Bool useTransformSkipFast
1434 ,
Bool bUseAdaptQpSelect
1443 #if ADAPTIVE_QP_SELECTION
1453 const UInt uiStride,
1472 rdpcmNxN( rTu, compID, pcResidual, uiStride, cQP, rpcCoeff, uiAbsSum, rdpcmMode );
1481 const UInt uiSizeMinus1 = (uiWidth * uiHeight) - 1;
1483 for (
UInt y = 0, coefficientIndex = 0; y<uiHeight; y++)
1485 for (
UInt x = 0; x<uiWidth; x++, coefficientIndex++)
1487 const Pel currentSample = pcResidual[(y * uiStride) + x];
1489 rpcCoeff[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex] = currentSample;
1490 uiAbsSum +=
TCoeff(abs(currentSample));
1496 #if DEBUG_TRANSFORM_AND_QUANTISE
1497 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU at input to transform\n";
1498 printBlock(pcResidual, uiWidth, uiHeight, uiStride);
1513 #if DEBUG_TRANSFORM_AND_QUANTISE
1514 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU between transform and quantiser\n";
1523 uiAbsSum, compID, cQP );
1525 #if DEBUG_TRANSFORM_AND_QUANTISE
1526 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU at output of quantiser\n";
1527 printBlock(rpcCoeff, uiWidth, uiHeight, uiWidth);
1540 const UInt uiStride,
1551 if (uiWidth != uiHeight)
1565 Pel *subTUResidual = pcResidual + (lineOffset * uiStride);
1566 TCoeff *subTUCoefficients = pcCoeff + (lineOffset * subTURecurse.
getRect(compID).
width);
1582 std::stringstream ss(stringstream::out);
1583 printBlockToStream(ss, (compID==0)?
"###InvTran ip Ch0: " : ((compID==1)?
"###InvTran ip Ch1: ":
"###InvTran ip Ch2: "), pcCoeff, uiWidth, uiHeight, uiWidth);
1591 const UInt uiSizeMinus1 = (uiWidth * uiHeight) - 1;
1593 for (
UInt y = 0, coefficientIndex = 0; y<uiHeight; y++)
1595 for (
UInt x = 0; x<uiWidth; x++, coefficientIndex++)
1597 pcResidual[(y * uiStride) + x] =
Pel(pcCoeff[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex]);
1603 #if DEBUG_TRANSFORM_AND_QUANTISE
1604 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU at input to dequantiser\n";
1605 printBlock(pcCoeff, uiWidth, uiHeight, uiWidth);
1610 #if DEBUG_TRANSFORM_AND_QUANTISE
1611 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU between dequantiser and inverse-transform\n";
1618 std::stringstream ss(stringstream::out);
1620 (*psDebug)+=ss.str();
1631 std::stringstream ss(stringstream::out);
1632 printBlockToStream(ss,
"###InvTran resi: ", pcResidual, uiWidth, uiHeight, uiStride);
1633 (*psDebug)+=ss.str();
1634 (*psDebug)+=
"(<- was a Transform-skipped block)\n";
1640 #if O0043_BEST_EFFORT_DECODING
1650 std::stringstream ss(stringstream::out);
1651 printBlockToStream(ss,
"###InvTran resi: ", pcResidual, uiWidth, uiHeight, uiStride);
1652 (*psDebug)+=ss.str();
1653 (*psDebug)+=
"(<- was a Transformed block)\n";
1658 #if DEBUG_TRANSFORM_AND_QUANTISE
1659 std::cout <<
g_debugCounter <<
": " << uiWidth <<
"x" << uiHeight <<
" channel " << compID <<
" TU at output of inverse-transform\n";
1660 printBlock(pcResidual, uiWidth, uiHeight, uiStride);
1689 Pel *rpcResidual = pResidual->
getAddr( compID );
1690 UInt uiAddr = (tuRect.
x0 + uiStride*tuRect.
y0);
1691 Pel *pResi = rpcResidual + uiAddr;
1694 const QpParam cQP(*pcCU, compID);
1696 if(pcCU->
getCbf(absPartIdxTU, compID, uiTrMode) != 0)
1700 std::string *psDebug=((DebugOptionList::DebugString_InvTran.getInt()&(pcCU->
isIntra(absPartIdxTU)?1:(pcCU->
isInter(absPartIdxTU)?2:4)))!=0) ? &sTemp : 0;
1708 std::cout << (*psDebug);
1722 pResi = rpcResidual + uiAddr;
1723 const Pel *pResiLuma = piResiLuma + uiAddr;
1725 crossComponentPrediction( rTu, compID, pResiLuma, pResi, pResi, tuWidth, tuHeight, strideLuma, uiStride, uiStride,
true );
1748 const UInt uiSizeMinus1 = (uiWidth * uiHeight) - 1;
1755 const UInt majorAxisLimit = (mode ==
RDPCM_VER) ? uiWidth : uiHeight;
1756 const UInt minorAxisLimit = (mode ==
RDPCM_VER) ? uiHeight : uiWidth;
1762 for ( majorAxis = 0; majorAxis < majorAxisLimit; majorAxis++ )
1764 TCoeff accumulatorValue = 0;
1765 for ( minorAxis = 0; minorAxis < minorAxisLimit; minorAxis++ )
1767 const UInt sampleIndex = (uiY * uiWidth) + uiX;
1768 const UInt coefficientIndex = (rotateResidual ? (uiSizeMinus1-sampleIndex) : sampleIndex);
1769 const Pel currentSample = pcResidual[(uiY * uiStride) + uiX];
1770 const TCoeff encoderSideDelta =
TCoeff(currentSample) - accumulatorValue;
1772 Pel reconstructedDelta;
1775 pcCoeff[coefficientIndex] = encoderSideDelta;
1776 reconstructedDelta = (
Pel) encoderSideDelta;
1784 uiAbsSum += abs(pcCoeff[coefficientIndex]);
1788 accumulatorValue += reconstructedDelta;
1803 else if ( pcCU->
isIntra( uiAbsPartIdx ) )
1816 applyForwardRDPCM( rTu, compID, pcResidual, uiStride, cQP, pcCoeff, uiAbsSum, rdpcmMode );
1829 TCoeff bestAbsSum = std::numeric_limits<TCoeff>::max();
1838 applyForwardRDPCM( rTu, compID, pcResidual, uiStride, cQP, pcCoeff, currAbsSum, mode );
1840 if (currAbsSum < bestAbsSum)
1843 bestAbsSum = currAbsSum;
1846 memcpy(bestCoefficients, pcCoeff, (uiWidth * uiHeight *
sizeof(
TCoeff)));
1851 rdpcmMode = bestMode;
1852 uiAbsSum = bestAbsSum;
1856 memcpy(pcCoeff, bestCoefficients, (uiWidth * uiHeight *
sizeof(
TCoeff)));
1875 if ( pcCU->
isIntra( uiAbsPartIdx ) )
1895 const TCoeff pelMin=(
TCoeff) std::numeric_limits<Pel>::min();
1896 const TCoeff pelMax=(
TCoeff) std::numeric_limits<Pel>::max();
1899 for(
UInt uiX = 0; uiX < uiWidth; uiX++ )
1901 Pel *pcCurResidual = pcResidual+uiX;
1902 TCoeff accumulator = *pcCurResidual;
1903 pcCurResidual+=uiStride;
1904 for(
UInt uiY = 1; uiY < uiHeight; uiY++, pcCurResidual+=uiStride )
1906 accumulator += *(pcCurResidual);
1907 *pcCurResidual = (
Pel)Clip3<TCoeff>(pelMin, pelMax, accumulator);
1913 for(
UInt uiY = 0; uiY < uiHeight; uiY++ )
1915 Pel *pcCurResidual = pcResidual+uiY*uiStride;
1916 TCoeff accumulator = *pcCurResidual;
1918 for(
UInt uiX = 1; uiX < uiWidth; uiX++, pcCurResidual++ )
1920 accumulator += *(pcCurResidual);
1921 *pcCurResidual = (
Pel)Clip3<TCoeff>(pelMin, pelMax, accumulator);
1945 if( iWidth == iHeight)
1947 xTr(channelBitDepth, piBlkResi, psCoeff, uiStride, (
UInt)iWidth, useDST, maxLog2TrDynamicRange);
1955 for (
Int y = 0; y < iHeight; y++)
1957 for (
Int x = 0; x < iWidth; x++)
1959 block[(y * iWidth) + x] = piBlkResi[(y * uiStride) + x];
1963 xTrMxN( channelBitDepth, block, coeff, iWidth, iHeight, useDST, maxLog2TrDynamicRange );
1965 memcpy(psCoeff, coeff, (iWidth * iHeight *
sizeof(
TCoeff)));
1981 if( iWidth == iHeight )
1983 xITr(channelBitDepth, plCoef, pResidual, uiStride, (
UInt)iWidth, useDST, maxLog2TrDynamicRange);
1991 memcpy(coeff, plCoef, (iWidth * iHeight *
sizeof(
TCoeff)));
1993 xITrMxN( channelBitDepth, coeff, block, iWidth, iHeight, useDST, maxLog2TrDynamicRange );
1995 for (
Int y = 0; y < iHeight; y++)
1997 for (
Int x = 0; x < iWidth; x++)
1999 pResidual[(y * uiStride) + x] =
Pel(block[(y * iWidth) + x]);
2022 iTransformShift = std::max<Int>(0, iTransformShift);
2026 const UInt uiSizeMinus1 = (width * height) - 1;
2028 if (iTransformShift >= 0)
2030 for (
UInt y = 0, coefficientIndex = 0; y < height; y++)
2032 for (
UInt x = 0; x < width; x++, coefficientIndex++)
2034 psCoeff[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex] =
TCoeff(piBlkResi[(y * uiStride) + x]) << iTransformShift;
2040 iTransformShift = -iTransformShift;
2041 const TCoeff offset = 1 << (iTransformShift - 1);
2043 for (
UInt y = 0, coefficientIndex = 0; y < height; y++)
2045 for (
UInt x = 0; x < width; x++, coefficientIndex++)
2047 psCoeff[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex] = (
TCoeff(piBlkResi[(y * uiStride) + x]) + offset) >> iTransformShift;
2066 #if O0043_BEST_EFFORT_DECODING
2075 iTransformShift = std::max<Int>(0, iTransformShift);
2079 const UInt uiSizeMinus1 = (width * height) - 1;
2081 if (iTransformShift >= 0)
2083 const TCoeff offset = iTransformShift==0 ? 0 : (1 << (iTransformShift - 1));
2085 for (
UInt y = 0, coefficientIndex = 0; y < height; y++)
2087 for (
UInt x = 0; x < width; x++, coefficientIndex++)
2089 pResidual[(y * uiStride) + x] =
Pel((plCoef[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex] + offset) >> iTransformShift);
2095 iTransformShift = -iTransformShift;
2097 for (
UInt y = 0, coefficientIndex = 0; y < height; y++)
2099 for (
UInt x = 0; x < width; x++, coefficientIndex++)
2101 pResidual[(y * uiStride) + x] =
Pel(plCoef[rotateResidual ? (uiSizeMinus1 - coefficientIndex) : coefficientIndex] << iTransformShift);
2149 if ((pcCU->
getTransformSkip(uiAbsPartIdx, compID) != 0) && extendedPrecision)
2151 iTransformShift = std::max<Int>(0, iTransformShift);
2156 UInt uiGoRiceParam = initialGolombRiceParameter;
2157 Double d64BlockUncodedCost = 0;
2160 const UInt uiMaxNumCoeff = uiWidth * uiHeight;
2166 #if ADAPTIVE_QP_SELECTION
2167 memset(piArlDstCoeff, 0,
sizeof(
TCoeff) * uiMaxNumCoeff);
2173 memset( pdCostCoeff, 0,
sizeof(
Double) * uiMaxNumCoeff );
2174 memset( pdCostSig, 0,
sizeof(
Double) * uiMaxNumCoeff );
2179 memset( rateIncUp, 0,
sizeof(
Int ) * uiMaxNumCoeff );
2180 memset( rateIncDown, 0,
sizeof(
Int ) * uiMaxNumCoeff );
2181 memset( sigRateDelta, 0,
sizeof(
Int ) * uiMaxNumCoeff );
2182 memset( deltaU, 0,
sizeof(
TCoeff) * uiMaxNumCoeff );
2192 const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
2193 const TCoeff entropyCodingMaximum = (1 << maxLog2TrDynamicRange) - 1;
2195 #if ADAPTIVE_QP_SELECTION
2197 Int iAddC = 1 << (iQBitsC-1);
2206 Int iCGLastScanPos = -1;
2212 Int iLastScanPos = -1;
2219 memset( uiSigCoeffGroupFlag, 0,
sizeof(
UInt) * MLS_GRP_NUM );
2227 for (
Int iCGScanPos = uiCGNum-1; iCGScanPos >= 0; iCGScanPos--)
2229 UInt uiCGBlkPos = codingParameters.
scanCG[ iCGScanPos ];
2237 for (
Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--)
2239 iScanPos = iCGScanPos*uiCGSize + iScanPosinCG;
2241 UInt uiBlkPos = codingParameters.
scan[iScanPos];
2244 const Int quantisationCoefficient = (enableScalingLists) ? piQCoef [uiBlkPos] : defaultQuantisationCoefficient;
2245 const Double errorScale = (enableScalingLists) ? pdErrScale[uiBlkPos] : defaultErrorScale;
2247 const Int64 tmpLevel =
Int64(abs(plSrcCoeff[ uiBlkPos ])) * quantisationCoefficient;
2251 #if ADAPTIVE_QP_SELECTION
2254 piArlDstCoeff[uiBlkPos] = (
TCoeff)(( lLevelDouble + iAddC) >> iQBitsC );
2257 const UInt uiMaxAbsLevel = std::min<UInt>(
UInt(entropyCodingMaximum),
UInt((lLevelDouble + (
Intermediate_Int(1) << (iQBits - 1))) >> iQBits));
2260 pdCostCoeff0[ iScanPos ] = dErr * dErr * errorScale;
2261 d64BlockUncodedCost += pdCostCoeff0[ iScanPos ];
2262 piDstCoeff[ uiBlkPos ] = uiMaxAbsLevel;
2264 if ( uiMaxAbsLevel > 0 && iLastScanPos < 0 )
2266 iLastScanPos = iScanPos;
2268 iCGLastScanPos = iCGScanPos;
2271 if ( iLastScanPos >= 0 )
2278 if( iScanPos == iLastScanPos )
2280 uiLevel =
xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
2281 lLevelDouble, uiMaxAbsLevel, significanceMapContextOffset, uiOneCtx, uiAbsCtx, uiGoRiceParam,
2282 c1Idx, c2Idx, iQBits, errorScale, 1, extendedPrecision, maxLog2TrDynamicRange
2287 UShort uiCtxSig = significanceMapContextOffset +
getSigCtxInc( patternSigCtx, codingParameters, iScanPos, uiLog2BlockWidth, uiLog2BlockHeight, channelType );
2289 uiLevel =
xGetCodedLevel( pdCostCoeff[ iScanPos ], pdCostCoeff0[ iScanPos ], pdCostSig[ iScanPos ],
2290 lLevelDouble, uiMaxAbsLevel, uiCtxSig, uiOneCtx, uiAbsCtx, uiGoRiceParam,
2291 c1Idx, c2Idx, iQBits, errorScale, 0, extendedPrecision, maxLog2TrDynamicRange
2301 Int rateNow =
xGetICRate( uiLevel, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx, extendedPrecision, maxLog2TrDynamicRange );
2302 rateIncUp [ uiBlkPos ] =
xGetICRate( uiLevel+1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
2303 rateIncDown [ uiBlkPos ] =
xGetICRate( uiLevel-1, uiOneCtx, uiAbsCtx, uiGoRiceParam, c1Idx, c2Idx, extendedPrecision, maxLog2TrDynamicRange ) - rateNow;
2309 piDstCoeff[ uiBlkPos ] = uiLevel;
2310 d64BaseCost += pdCostCoeff [ iScanPos ];
2313 if( uiLevel >= baseLevel )
2315 if (uiLevel > 3*(1<<uiGoRiceParam))
2317 uiGoRiceParam = bUseGolombRiceParameterAdaptation ? (uiGoRiceParam + 1) : (std::min<UInt>((uiGoRiceParam + 1), 4));
2332 else if( (c1 < 3) && (c1 > 0) && uiLevel)
2338 if( ( iScanPos % uiCGSize == 0 ) && ( iScanPos > 0 ) )
2345 uiGoRiceParam = initialGolombRiceParameter;
2350 d64BaseCost += pdCostCoeff0[ iScanPos ];
2353 if (iScanPosinCG == 0 )
2357 if (piDstCoeff[ uiBlkPos ] )
2359 uiSigCoeffGroupFlag[ uiCGBlkPos ] = 1;
2362 if ( iScanPosinCG != 0 )
2369 if (iCGLastScanPos >= 0)
2373 if (uiSigCoeffGroupFlag[ uiCGBlkPos ] == 0)
2381 if (iCGScanPos < iCGLastScanPos)
2389 Double d64CostZeroCG = d64BaseCost;
2394 if (iCGScanPos < iCGLastScanPos)
2407 if ( d64CostZeroCG < d64BaseCost )
2409 uiSigCoeffGroupFlag[ uiCGBlkPos ] = 0;
2410 d64BaseCost = d64CostZeroCG;
2411 if (iCGScanPos < iCGLastScanPos)
2416 for (
Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--)
2418 iScanPos = iCGScanPos*uiCGSize + iScanPosinCG;
2419 UInt uiBlkPos = codingParameters.
scan[ iScanPos ];
2421 if (piDstCoeff[ uiBlkPos ])
2423 piDstCoeff [ uiBlkPos ] = 0;
2424 pdCostCoeff[ iScanPos ] = pdCostCoeff0[ iScanPos ];
2425 pdCostSig [ iScanPos ] = 0;
2434 uiSigCoeffGroupFlag[ uiCGBlkPos ] = 1;
2440 if ( iLastScanPos < 0 )
2447 Int iBestLastIdxP1 = 0;
2456 ui16CtxCbf = pcCU->
getCtxQtCbf( rTu, channelType );
2463 Bool bFoundLast =
false;
2464 for (
Int iCGScanPos = iCGLastScanPos; iCGScanPos >= 0; iCGScanPos--)
2466 UInt uiCGBlkPos = codingParameters.
scanCG[ iCGScanPos ];
2468 d64BaseCost -= pdCostCoeffGroupSig [ iCGScanPos ];
2469 if (uiSigCoeffGroupFlag[ uiCGBlkPos ])
2471 for (
Int iScanPosinCG = uiCGSize-1; iScanPosinCG >= 0; iScanPosinCG--)
2473 iScanPos = iCGScanPos*uiCGSize + iScanPosinCG;
2475 if (iScanPos > iLastScanPos)
2479 UInt uiBlkPos = codingParameters.
scan[iScanPos];
2481 if( piDstCoeff[ uiBlkPos ] )
2483 UInt uiPosY = uiBlkPos >> uiLog2BlockWidth;
2484 UInt uiPosX = uiBlkPos - ( uiPosY << uiLog2BlockWidth );
2487 Double totalCost = d64BaseCost + d64CostLast - pdCostSig[ iScanPos ];
2489 if( totalCost < d64BestCost )
2491 iBestLastIdxP1 = iScanPos + 1;
2492 d64BestCost = totalCost;
2494 if( piDstCoeff[ uiBlkPos ] > 1 )
2499 d64BaseCost -= pdCostCoeff[ iScanPos ];
2500 d64BaseCost += pdCostCoeff0[ iScanPos ];
2504 d64BaseCost -= pdCostSig[ iScanPos ];
2515 for (
Int scanPos = 0; scanPos < iBestLastIdxP1; scanPos++ )
2517 Int blkPos = codingParameters.
scan[ scanPos ];
2518 TCoeff level = piDstCoeff[ blkPos ];
2520 piDstCoeff[ blkPos ] = ( plSrcCoeff[ blkPos ] < 0 ) ? -level : level;
2524 for (
Int scanPos = iBestLastIdxP1; scanPos <= iLastScanPos; scanPos++ )
2526 piDstCoeff[ codingParameters.
scan[ scanPos ] ] = 0;
2533 Int64 rdFactor = (
Int64)(inverseQuantScale * inverseQuantScale * (1 << (2 * cQP.
per))
2541 for(
Int subSet = (uiWidth*uiHeight-1) >>
MLS_CG_SIZE; subSet >= 0; subSet-- )
2544 Int firstNZPosInCG=uiCGSize , lastNZPosInCG=-1 ;
2547 for(n = uiCGSize-1; n >= 0; --n )
2549 if( piDstCoeff[ codingParameters.
scan[ n + subPos ]] )
2556 for(n = 0; n <uiCGSize; n++ )
2558 if( piDstCoeff[ codingParameters.
scan[ n + subPos ]] )
2565 for(n = firstNZPosInCG; n <=lastNZPosInCG; n++ )
2567 absSum +=
Int(piDstCoeff[ codingParameters.
scan[ n + subPos ]]);
2570 if(lastNZPosInCG>=0 && lastCG==-1)
2577 UInt signbit = (piDstCoeff[codingParameters.
scan[subPos+firstNZPosInCG]]>0?0:1);
2578 if( signbit!=(absSum&0x1) )
2581 Int64 minCostInc = std::numeric_limits<Int64>::max(), curCost = std::numeric_limits<Int64>::max();
2582 Int minPos = -1, finalChange = 0, curChange = 0;
2584 for( n = (lastCG==1?lastNZPosInCG:uiCGSize-1) ; n >= 0; --n )
2586 UInt uiBlkPos = codingParameters.
scan[ n + subPos ];
2587 if(piDstCoeff[ uiBlkPos ] != 0 )
2589 Int64 costUp = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos];
2590 Int64 costDown = rdFactor * ( deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos]
2591 - ((abs(piDstCoeff[uiBlkPos]) == 1) ? sigRateDelta[uiBlkPos] : 0);
2593 if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
2595 costDown -= (4<<15);
2606 if(n==firstNZPosInCG && abs(piDstCoeff[uiBlkPos])==1)
2608 curCost = std::numeric_limits<Int64>::max();
2618 curCost = rdFactor * ( - (abs(deltaU[uiBlkPos])) ) + (1<<15) + rateIncUp[uiBlkPos] + sigRateDelta[uiBlkPos] ;
2621 if(n<firstNZPosInCG)
2623 UInt thissignbit = (plSrcCoeff[uiBlkPos]>=0?0:1);
2624 if(thissignbit != signbit )
2626 curCost = std::numeric_limits<Int64>::max();
2631 if( curCost<minCostInc)
2633 minCostInc = curCost;
2634 finalChange = curChange;
2639 if(piDstCoeff[minPos] == entropyCodingMaximum || piDstCoeff[minPos] == entropyCodingMinimum)
2644 if(plSrcCoeff[minPos]>=0)
2646 piDstCoeff[minPos] += finalChange ;
2650 piDstCoeff[minPos] -= finalChange ;
2674 if ((widthInGroups <= 1) && (heightInGroups <= 1))
2679 const Bool rightAvailable = uiCGPosX < (widthInGroups - 1);
2680 const Bool belowAvailable = uiCGPosY < (heightInGroups - 1);
2687 sigRight = ((sigCoeffGroupFlag[ (uiCGPosY * widthInGroups) + uiCGPosX + 1 ] != 0) ? 1 : 0);
2691 sigLower = ((sigCoeffGroupFlag[ (uiCGPosY + 1) * widthInGroups + uiCGPosX ] != 0) ? 1 : 0);
2694 return sigRight + (sigLower << 1);
2709 const Int scanPosition,
2710 const Int log2BlockWidth,
2711 const Int log2BlockHeight,
2720 const UInt rasterPosition = codingParameters.
scan[scanPosition];
2721 const UInt posY = rasterPosition >> log2BlockWidth;
2722 const UInt posX = rasterPosition - (posY << log2BlockWidth);
2724 if ((posX + posY) == 0)
2731 if ((log2BlockWidth == 2) && (log2BlockHeight == 2))
2739 switch (patternSigCtx)
2747 const Int posTotalInSubset = posXinSubset + posYinSubset;
2753 cnt = (posTotalInSubset >= context1Threshold) ? 0 : ((posTotalInSubset >= context2Threshold) ? 1 : 2);
2764 cnt = (posYinSubset >= (groupHeight >> 1)) ? 0 : ((posYinSubset >= (groupHeight >> 2)) ? 1 : 2);
2775 cnt = (posXinSubset >= (groupWidth >> 1)) ? 0 : ((posXinSubset >= (groupWidth >> 2)) ? 1 : 2);
2790 std::cerr <<
"ERROR: Invalid patternSigCtx \"" <<
Int(patternSigCtx) <<
"\" in getSigCtxInc" << std::endl;
2814 Double& rd64CodedCostSig,
2826 Bool useLimitedPrefixLength,
2827 const Int maxLog2TrDynamicRange
2831 UInt uiBestAbsLevel = 0;
2833 if( !bLast && uiMaxAbsLevel < 3 )
2836 rd64CodedCost = rd64CodedCost0 + rd64CodedCostSig;
2837 if( uiMaxAbsLevel == 0 )
2839 return uiBestAbsLevel;
2852 UInt uiMinAbsLevel = ( uiMaxAbsLevel > 1 ? uiMaxAbsLevel - 1 : 1 );
2853 for(
Int uiAbsLevel = uiMaxAbsLevel; uiAbsLevel >= uiMinAbsLevel ; uiAbsLevel-- )
2856 Double dCurrCost = dErr * dErr * errorScale +
xGetICost(
xGetICRate( uiAbsLevel, ui16CtxNumOne, ui16CtxNumAbs, ui16AbsGoRice, c1Idx, c2Idx, useLimitedPrefixLength, maxLog2TrDynamicRange ) );
2857 dCurrCost += dCurrCostSig;
2859 if( dCurrCost < rd64CodedCost )
2861 uiBestAbsLevel = uiAbsLevel;
2862 rd64CodedCost = dCurrCost;
2863 rd64CodedCostSig = dCurrCostSig;
2867 return uiBestAbsLevel;
2882 const UShort ui16CtxNumOne,
2883 const UShort ui16CtxNumAbs,
2884 const UShort ui16AbsGoRice,
2887 const Bool useLimitedPrefixLength,
2888 const Int maxLog2TrDynamicRange
2894 if ( uiAbsLevel >= baseLevel )
2896 UInt symbol = uiAbsLevel - baseLevel;
2900 length = symbol>>ui16AbsGoRice;
2901 iRate += (length+1+ui16AbsGoRice)<< 15;
2903 else if (useLimitedPrefixLength)
2907 UInt prefixLength = 0;
2910 while ((prefixLength < maximumPrefixLength) && (suffix > ((2 << prefixLength) - 2)))
2915 const UInt suffixLength = (prefixLength == maximumPrefixLength) ? (maxLog2TrDynamicRange - ui16AbsGoRice) : (prefixLength + 1);
2921 length = ui16AbsGoRice;
2923 while (symbol >= (1<<length))
2925 symbol -= (1<<(length++));
2940 else if( uiAbsLevel == 1 )
2944 else if( uiAbsLevel == 2 )
2958 UShort ui16CtxNumSig )
const
2993 UShort ui16CtxNumSig )
const
3024 const UInt uiCGPosX,
3025 const UInt uiCGPosY,
3026 const UInt widthInGroups,
3027 const UInt heightInGroups)
3032 if (uiCGPosX < (widthInGroups - 1))
3034 sigRight = ((uiSigCoeffGroupFlag[ (uiCGPosY * widthInGroups) + uiCGPosX + 1 ] != 0) ? 1 : 0);
3036 if (uiCGPosY < (heightInGroups - 1))
3038 sigLower = ((uiSigCoeffGroupFlag[ (uiCGPosY + 1) * widthInGroups + uiCGPosX ] != 0) ? 1 : 0);
3041 return ((sigRight + sigLower) != 0) ? 1 : 0;
3053 const Int minimumQp = 0;
3060 for(
Int qp = minimumQp; qp < maximumQp; qp++)
3075 const Int minimumQp = 0;
3082 for(
Int qp = minimumQp; qp < maximumQp; qp++)
3101 const Int channelBitDepth = bitDepths.
recon[channelType];
3102 const Int iTransformShift =
getTransformShift(channelBitDepth, uiLog2TrSize, maxLog2TrDynamicRange[channelType]);
3111 dErrScale = dErrScale*pow(2.0,(-2.0*iTransformShift));
3113 for(i=0;i<uiMaxNumCoeff;i++)
3142 height, width, ratio,
3169 height, width, ratio,
3178 const Int minimumQp = 0;
3185 for(
Int qp = minimumQp; qp < maximumQp; qp++)
3214 *quantcoeff++ = quantScales;
3215 *dequantcoeff++ = invQuantScales;
3231 for(
UInt j=0;j<height;j++)
3233 for(
UInt i=0;i<width;i++)
3235 quantcoeff[j*width + i] = quantScales / coeff[sizuNum * (j / ratio) + i / ratio];
3241 quantcoeff[0] = quantScales / dc;
3257 for(
UInt j=0;j<height;j++)
3259 for(
UInt i=0;i<width;i++)
3261 dequantcoeff[j*width + i] = invQuantScales * coeff[sizuNum * (j / ratio) + i / ratio];
3267 dequantcoeff[0] = invQuantScales * dc;
3345 TCoeff transformedCoefficient;
3348 if (iTransformShift >= 0)
3350 transformedCoefficient = resiDiff << iTransformShift;
3354 const Int iTrShiftNeg = -iTransformShift;
3355 const Int offset = 1 << (iTrShiftNeg - 1);
3356 transformedCoefficient = ( resiDiff + offset ) >> iTrShiftNeg;
3360 const TCoeff iSign = (transformedCoefficient < 0 ? -1: 1);
3362 const Int quantisationCoefficient = enableScalingLists ? piQuantCoeff[uiPos] : defaultQuantisationCoefficient;
3364 const Int64 tmpLevel = (
Int64)abs(transformedCoefficient) * quantisationCoefficient;
3366 const TCoeff quantisedCoefficient = (
TCoeff((tmpLevel + iAdd ) >> iQBits)) * iSign;
3368 const TCoeff entropyCodingMinimum = -(1 << maxLog2TrDynamicRange);
3369 const TCoeff entropyCodingMaximum = (1 << maxLog2TrDynamicRange) - 1;
3370 pcCoeff[ uiPos ] = Clip3<TCoeff>( entropyCodingMinimum, entropyCodingMaximum, quantisedCoefficient );
3381 const Int QP_per = cQP.
per;
3382 const Int QP_rem = cQP.
rem;
3384 #if O0043_BEST_EFFORT_DECODING
3398 const TCoeff transformMinimum = -(1 << maxLog2TrDynamicRange);
3399 const TCoeff transformMaximum = (1 << maxLog2TrDynamicRange) - 1;
3403 TCoeff dequantisedSample;
3405 if(enableScalingLists)
3408 const UInt targetInputBitDepth = std::min<UInt>((maxLog2TrDynamicRange + 1), (((
sizeof(
Intermediate_Int) * 8) + rightShift) - dequantCoefBits));
3411 const Intermediate_Int inputMaximum = (1 << (targetInputBitDepth - 1)) - 1;
3418 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, inSample));
3421 dequantisedSample =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
3426 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, inSample));
3429 dequantisedSample =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
3439 const Intermediate_Int inputMaximum = (1 << (targetInputBitDepth - 1)) - 1;
3444 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, inSample));
3447 dequantisedSample =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
3452 const TCoeff clipQCoef =
TCoeff(Clip3<Intermediate_Int>(inputMinimum, inputMaximum, inSample));
3455 dequantisedSample =
TCoeff(Clip3<Intermediate_Int>(transformMinimum,transformMaximum,iCoeffQ));
3461 if (iTransformShift >= 0)
3463 const TCoeff offset = iTransformShift==0 ? 0 : (1 << (iTransformShift - 1));
3464 reconSample =
Pel(( dequantisedSample + offset ) >> iTransformShift);
3468 const Int iTrShiftNeg = -iTransformShift;
3469 reconSample =
Pel(dequantisedSample << iTrShiftNeg);
3476 const Pel * piResiL,
3477 const Pel * piResiC,
3484 const Bool reverse )
3486 const Pel *pResiL = piResiL;
3487 const Pel *pResiC = piResiC;
3488 Pel *pResiT = piResiT;
3494 for(
Int y = 0; y < height; y++ )
3503 #if RExt__HIGH_BIT_DEPTH_SUPPORT
3504 for(
Int x = 0; x < width; x++ )
3506 pResiT[x] = pResiC[x] + (( alpha *
rightShift( pResiL[x], diffBitDepth) ) >> 3);
3509 const Int minPel=std::numeric_limits<Pel>::min();
3510 const Int maxPel=std::numeric_limits<Pel>::max();
3511 for(
Int x = 0; x < width; x++ )
3513 pResiT[x] = Clip3<Int>(minPel, maxPel, pResiC[x] + (( alpha * rightShift<Int>(
Int(pResiL[x]), diffBitDepth) ) >> 3));
3520 for(
Int x = 0; x < width; x++ )
3522 pResiT[x] = pResiC[x] - (( alpha * rightShift<Int>(
Int(pResiL[x]), diffBitDepth) ) >> 3);
SChar g_aucConvertToBit[MAX_CU_SIZE+1]
const Int g_quantScales[SCALING_LIST_REM_NUM]
Bool xNeedRDOQ(TComTU &rTu, TCoeff *pSrc, const ComponentID compID, const QpParam &cQP)
static const Int SCALING_LIST_REM_NUM
Bool getCrossComponentPredictionEnabledFlag() const
Int * m_dequantCoef[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]
array of dequantization matrix coefficient 4x4
Int m_sliceNsamples[LEVEL_RANGE+1]
static const Int SCALING_LIST_NUM
list number for quantization matrix
Void partialButterflyInverse8(TCoeff *src, TCoeff *dst, Int shift, Int line, const TCoeff outputMinimum, const TCoeff outputMaximum)
Bool getPersistentRiceAdaptationEnabledFlag() const
ValueType leftShift(const ValueType value, const Int shift)
static const Int g_transformMatrixShift[TRANSFORM_NUMBER_OF_DIRECTIONS]
static const Int ARL_C_PRECISION
G382: 7-bit arithmetic precision.
static Int getSigCtxInc(Int patternSigCtx, const TUEntropyCodingParameters &codingParameters, const Int scanPosition, const Int log2BlockWidth, const Int log2BlockHeight, const ChannelType chanType)
static const UInt notFirstGroupNeighbourhoodContextOffset[MAX_NUM_CHANNEL_TYPE]
Void xTrMxN(Int bitDepth, TCoeff *block, TCoeff *coeff, Int iWidth, Int iHeight, Bool useDST, const Int maxLog2TrDynamicRange)
Int * getScalingListAddress(UInt sizeId, UInt listId)
get matrix coefficient
SliceType getSliceType() const
Void destroyScalingList()
Void setScalingList(TComScalingList *scalingList, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths)
Bool useDST(const ComponentID compID)
Int lastYBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]
Double * m_errScale[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]
array of quantization matrix coefficient 4x4
static const Int HOR_IDX
index for intra HORIZONTAL mode
const TMatrixCoeff g_aiT16[TRANSFORM_NUMBER_OF_DIRECTIONS][16][16]
#define NEIGHBOURHOOD_00_CONTEXT_2_THRESHOLD_4x4
Void setFlatScalingList(const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths)
Void xITrMxN(Int bitDepth, TCoeff *coeff, TCoeff *block, Int iWidth, Int iHeight, Bool useDST, const Int maxLog2TrDynamicRange)
UChar * getExplicitRdpcmMode(ComponentID component)
const TComPPSRExt & getPpsRangeExtension() const
static const Int DM_CHROMA_IDX
chroma mode index for derived from luma intra mode
const TComSPSRExt & getSpsRangeExtension() const
SChar * getCrossComponentPredictionAlpha(ComponentID compID)
#define DEBUG_STRING_FN_DECLAREP(name)
static const Int MAX_TU_SIZE
estBitsSbacStruct * m_pcEstBitsSbac
static Void crossComponentPrediction(TComTU &rTu, const ComponentID compID, const Pel *piResiL, const Pel *piResiC, Pel *piResiT, const Int width, const Int height, const Int strideL, const Int strideC, const Int strideT, const Bool reverse)
UChar * getTransformIdx()
const TMatrixCoeff g_aiT4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]
Int lastXBits[MAX_NUM_CHANNEL_TYPE][LAST_SIGNIFICANT_GROUPS]
__inline Double xGetICost(Double dRate) const
Void applyForwardRDPCM(TComTU &rTu, const ComponentID compID, Pel *pcResidual, const UInt uiStride, const QpParam &cQP, TCoeff *pcCoeff, TCoeff &uiAbsSum, const RDPCMMode mode)
Double d64CodedLevelandDist
Bool m_useTransformSkipFast
QpParam(const Int qpy, const ChannelType chType, const Int qpBdOffset, const Int chromaQPOffset, const ChromaFormat chFmt)
Int blockCbpBits[2 *5][2]
const ChromaQpAdj & getChromaQpOffsetListEntry(Int cuChromaQpOffsetIdxPlus1) const
static const Int MLS_GRP_NUM
Max number of coefficient groups, max(16, 64)
Void partialButterfly16(TCoeff *src, TCoeff *dst, Int shift, Int line)
Double m_sliceSumC[LEVEL_RANGE+1]
SChar * getPredictionMode()
Void setExplicitRdpcmModePartRange(UInt rdpcmMode, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
static const Int LEVEL_RANGE
G382: max coefficient level in statistics collection.
Void xQuant(TComTU &rTu, TCoeff *pSrc, TCoeff *pDes, TCoeff *pArlDes, TCoeff &uiAbsSum, const ComponentID compID, const QpParam &cQP)
Void partialButterflyInverse32(TCoeff *src, TCoeff *dst, Int shift, Int line, const TCoeff outputMinimum, const TCoeff outputMaximum)
Void xITransformSkip(TCoeff *plCoef, Pel *pResidual, UInt uiStride, TComTU &rTu, const ComponentID component)
Int blockRootCbpBits[4][2]
Int * getDequantCoeff(UInt list, Int qp, UInt size)
get Quant Coefficent
Void setCbfPartRange(UInt uiCbf, ComponentID compID, UInt uiAbsPartIdx, UInt uiCoveredPartIdxes)
static const Int SCALING_LIST_BITS
bit depth of scaling list entries
static const Int MAX_MATRIX_SIZE_NUM
max size number for quantization matrix
__inline Int xGetICRate(const UInt uiAbsLevel, const UShort ui16CtxNumOne, const UShort ui16CtxNumAbs, const UShort ui16AbsGoRice, const UInt c1Idx, const UInt c2Idx, const Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange) const
UInt getStride(const ComponentID id) const
Int * getQuantCoeff(UInt list, Int qp, UInt size)
get Error Scale Coefficent
UInt GetTransformDepthRel() const
static const Int IQUANT_SHIFT
Void init(UInt uiMaxTrSize, Bool useRDOQ=false, Bool useRDOQTS=false, Bool useSelectiveRDOQ=false, Bool bEnc=false, Bool useTransformSkipFast=false, Bool bUseAdaptQpSelect=false)
UChar getCbf(UInt uiIdx, ComponentID eType) const
Bool nextSection(const TComTU &parent)
Int getScalingListDC(UInt sizeId, UInt listId) const
get DC value
Void xDeQuant(TComTU &rTu, const TCoeff *pSrc, TCoeff *pDes, const ComponentID compID, const QpParam &cQP)
Int recon[MAX_NUM_CHANNEL_TYPE]
the bit depth as indicated in the SPS
UInt GetSectionNumber() const
UInt getMaxTrSize() const
Bool getSignDataHidingEnabledFlag() const
static UInt getSigCoeffGroupCtxInc(const UInt *uiSigCoeffGroupFlag, const UInt uiCGPosX, const UInt uiCGPosY, const UInt widthInGroups, const UInt heightInGroups)
Int m_greaterOneBits[((4 *4)+(4 *2))][2]
Bool isInter(UInt uiPartIdx) const
TComPicYuv * getPicYuvRec()
UInt GetAbsPartIdxTU() const
#define NUM_ONE_FLAG_CTX_PER_SET
number of context models for greater than 1 flag in a set
Short TMatrixCoeff
transform matrix coefficient
Void partialButterfly8(TCoeff *src, TCoeff *dst, Int shift, Int line)
UInt getMaxTotalCUDepth() const
#define NEIGHBOURHOOD_00_CONTEXT_1_THRESHOLD_4x4
Int significantBits[(28+16)][2]
Void storeSliceQpNext(TComSlice *pcSlice)
UChar * getIntraDir(const ChannelType channelType) const
Int Intermediate_Int
used as intermediate value in calculations
UInt getGolombRiceStatisticsIndex(const ComponentID compID)
Int golombRiceAdaptationStatistics[RExt__GOLOMB_RICE_ADAPTATION_STATISTICS_SETS]
static const Int QUANT_SHIFT
Q(4) = 2^14.
Int getQpBDOffset(ChannelType type) const
Double & getErrScaleCoeffNoScalingList(UInt list, UInt size, Int qp)
get Error Scale Coefficent
Double * getErrScaleCoeff(UInt list, UInt size, Int qp)
static const Int MLS_CG_LOG2_WIDTH
Void transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const TCoeff resiDiff, TCoeff *pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint)
Bool isIntra(UInt uiPartIdx) const
Void invRdpcmNxN(TComTU &rTu, const ComponentID compID, Pel *pcResidual, const UInt uiStride)
#define ADAPTIVE_QP_SELECTION
G382: Adaptive reconstruction levels, non-normative part for adaptive QP selection.
static const Int VER_IDX
index for intra VERTICAL mode
__inline Double xGetRateLast(const UInt uiPosX, const UInt uiPosY, const ComponentID component) const
static const Int RExt__GOLOMB_RICE_INCREMENT_DIVISOR
Void processScalingListDec(const Int *coeff, Int *dequantcoeff, Int invQuantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc)
Bool isRDPCMEnabled(UInt uiAbsPartIdx) const
static const Int C2FLAG_NUMBER
UInt GetEquivalentLog2TrSize(const ComponentID compID) const
static const Int MAX_INT
max. value of signed 32-bit integer
static const Int LOG2_SCALING_LIST_NEUTRAL_VALUE
log2 of the value that, when used in a scaling list, has no effect on quantisation ...
Void partialButterfly32(TCoeff *src, TCoeff *dst, Int shift, Int line)
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Defines constants and tables for SBAC.
#define DEBUG_STRING_APPEND(str1, str2)
TComPicYuv * getPicYuvOrg()
Int getBitDepth(ChannelType type) const
ValueType rightShift(const ValueType value, const Int shift)
Int TCoeff
transform coefficient
Int * m_quantCoef[SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM][SCALING_LIST_REM_NUM]
array of quantization matrix coefficient 4x4
Int getDifferentialLumaChromaBitDepth() const
Pel * getAddr(const ComponentID id)
__inline Double xGetRateSigCoeffGroup(UShort uiSignificanceCoeffGroup, UShort ui16CtxNumSig) const
Void partialButterflyInverse4(TCoeff *src, TCoeff *dst, Int shift, Int line, const TCoeff outputMinimum, const TCoeff outputMaximum)
Int getSliceQpBase() const
Void xSetScalingListEnc(TComScalingList *scalingList, UInt list, UInt size, Int qp)
Void fastInverseDst(TCoeff *tmp, TCoeff *block, Int shift, const TCoeff outputMinimum, const TCoeff outputMaximum)
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
const Int g_invQuantScales[SCALING_LIST_REM_NUM]
UInt getCoefficientOffset(const ComponentID compID) const
__inline Double xGetRateSigCoef(UShort uiSignificance, UShort ui16CtxNumSig) const
const TComRectangle & getRect(const ComponentID compID) const
UInt firstSignificanceMapContext
Int getMaxLog2TrDynamicRange(ChannelType channelType) const
Void partialButterflyInverse16(TCoeff *src, TCoeff *dst, Int shift, Int line, const TCoeff outputMinimum, const TCoeff outputMaximum)
const UInt g_scalingListSize[SCALING_LIST_SIZE_NUM]
const TComPPS * getPPS() const
static const UInt significanceMapContextSetStart[MAX_NUM_CHANNEL_TYPE][CONTEXT_NUMBER_OF_TYPES]
#define DEBUG_STRING_PASS_INTO(name)
Void signBitHidingHDQ(TCoeff *pQCoef, TCoeff *pCoef, TCoeff *deltaU, const TUEntropyCodingParameters &codingParameters, const Int maxLog2TrDynamicRange)
Bool getUseScalingList(const UInt width, const UInt height, const Bool isTransformSkip)
UChar * getTransformSkip(ComponentID compID)
ChromaFormat getChromaFormat() const
__inline Double xGetIEPRate() const
Void setErrScaleCoeff(UInt list, UInt size, Int qp, const Int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths)
Void rdpcmNxN(TComTU &rTu, const ComponentID compID, Pel *pcResidual, const UInt uiStride, const QpParam &cQP, TCoeff *pcCoeff, TCoeff &uiAbsSum, RDPCMMode &rdpcmMode)
Bool ProcessComponentSection(const ComponentID compID) const
Void invTrSkipDeQuantOneSample(TComTU &rTu, ComponentID compID, TCoeff pcCoeff, Pel &reconSample, const QpParam &cQP, UInt uiPos)
Void invTransformNxN(TComTU &rTu, const ComponentID compID, Pel *pcResidual, const UInt uiStride, TCoeff *pcCoeff, const QpParam &cQP)
const TMatrixCoeff g_aiT32[TRANSFORM_NUMBER_OF_DIRECTIONS][32][32]
Int getLog2DiffMaxMinCodingBlockSize() const
const TMatrixCoeff g_aiT8[TRANSFORM_NUMBER_OF_DIRECTIONS][8][8]
Bool * getCUTransquantBypass()
__inline UInt xGetCodedLevel(Double &rd64CodedCost, Double &rd64CodedCost0, Double &rd64CodedCostSig, Intermediate_Int lLevelDouble, UInt uiMaxAbsLevel, UShort ui16CtxNumSig, UShort ui16CtxNumOne, UShort ui16CtxNumAbs, UShort ui16AbsGoRice, UInt c1Idx, UInt c2Idx, Int iQBits, Double errorScale, Bool bLast, Bool useLimitedPrefixLength, const Int maxLog2TrDynamicRange) const
Void xTransformSkip(Pel *piBlkResi, UInt uiStride, TCoeff *psCoeff, TComTU &rTu, const ComponentID component)
UInt GetAbsPartIdxNumParts() const
#define RDOQ_CHROMA
use of RDOQ in chroma
Void processScalingListEnc(Int *coeff, Int *quantcoeff, Int quantScales, UInt height, UInt width, UInt ratio, Int sizuNum, UInt dc)
const UChar g_chroma422IntraAngleMappingTable[NUM_INTRA_MODE]
const UInt g_uiGroupIdx[MAX_TU_SIZE]
const UInt ctxIndMap4x4[4 *4]
static const Int MAX_CU_SIZE
= 1<<(MAX_CU_DEPTH)
Int getQpOffset(ComponentID compID) const
const TMatrixCoeff g_as_DST_MAT_4[TRANSFORM_NUMBER_OF_DIRECTIONS][4][4]
static const Int SCALE_BITS
For fractional bit estimates in RDOQ.
static const Double MAX_DOUBLE
max. value of Double-type value
static Int calcPatternSigCtx(const UInt *sigCoeffGroupFlag, UInt uiCGPosX, UInt uiCGPosY, UInt widthInGroups, UInt heightInGroups)
Void xIT(const Int channelBitDepth, Bool useDST, TCoeff *plCoef, Pel *pResidual, UInt uiStride, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange)
Int significantCoeffGroupBits[2][2]
UInt getCtxQtCbf(TComTU &rTu, const ChannelType chType) const
static const Int MLS_CG_SIZE
Coefficient group size of 4x4; = MLS_CG_LOG2_WIDTH + MLS_CG_LOG2_HEIGHT.
#define DISTORTION_PRECISION_ADJUSTMENT(x)
const UInt g_scalingListSizeX[SCALING_LIST_SIZE_NUM]
static const Int chromaQPMappingTableSize
TCoeff * getCoeff(ComponentID component)
Void xsetFlatScalingList(UInt list, UInt size, Int qp)
static const Int MLS_CG_LOG2_HEIGHT
Int m_levelAbsBits[((1 *4)+(1 *2))][2]
Void partialButterfly4(TCoeff *src, TCoeff *dst, Int shift, Int line)
Int getSliceChromaQpDelta(ComponentID compID) const
Void xRateDistOptQuant(TComTU &rTu, TCoeff *plSrcCoeff, TCoeff *piDstCoeff, TCoeff *piArlDstCoeff, TCoeff &uiAbsSum, const ComponentID compID, const QpParam &cQP)
transform and quantization class (header)
Bool isNonTransformedResidualRotated(const ComponentID compID)
Void invRecurTransformNxN(const ComponentID compID, TComYuv *pResidual, TComTU &rTu)
Void printBlock(const ValueType *const source, const UInt width, const UInt height, const UInt stride, const UInt outputValueWidth=0, const Bool onlyPrintEdges=false, const Bool printInZScan=false, const Int shiftLeftBy=0, const Bool printAverage=false, std::ostream &stream=std::cout)
Void setScalingListDec(const TComScalingList &scalingList)
Void transformNxN(TComTU &rTu, const ComponentID compID, Pel *pcResidual, const UInt uiStride, TCoeff *rpcCoeff, TCoeff *rpcArlCoeff, TCoeff &uiAbsSum, const QpParam &cQP)
UChar * getChromaQpAdj()
array of chroma QP adjustments (indexed). when value = 0, cu_chroma_qp_offset_flag=0; when value>0...
Void fastForwardDst(TCoeff *block, TCoeff *coeff, Int shift)
static const Int COEF_REMAIN_BIN_REDUCTION
indicates the level at which the VLC transitions from Golomb-Rice to TU+EG(k)
#define NUM_ABS_FLAG_CTX_PER_SET
number of context models for greater than 2 flag in a set
#define DEBUG_STRING_NEW(name)
Void printBlockToStream(std::ostream &ss, const TChar *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross, const UInt numSubBlocksUp, const UInt defWidth)
Defines types and objects for environment-variable-based debugging and feature control.
Void xSetScalingListDec(const TComScalingList &scalingList, UInt list, UInt size, Int qp)
Void xT(const Int channelBitDepth, Bool useDST, Pel *piBlkResi, UInt uiStride, TCoeff *psCoeff, Int iWidth, Int iHeight, const Int maxLog2TrDynamicRange)
Bool getExtendedPrecisionProcessingFlag() const
const TComSPS * getSPS() const
static const Int SBH_THRESHOLD
value of the fixed SBH controlling threshold
static const Int C1FLAG_NUMBER
ChromaFormat getChromaFormat() const