Commit a2400de3 authored by Frank Bossen's avatar Frank Bossen
Browse files

Define global FRAC_BITS_SCALE constant to replace local ones

parent eae3419a
......@@ -324,7 +324,9 @@ static const int SCALING_LIST_REM_NUM = 6;
static const int QUANT_SHIFT = 14; ///< Q(4) = 2^14
static const int IQUANT_SHIFT = 6;
static const int SCALE_BITS = 15; ///< Precision for fractional bit estimates
static constexpr int SCALE_BITS = 15; // Precision for fractional bit estimates
static constexpr double FRAC_BITS_SCALE = 1.0 / (1 << SCALE_BITS);
static const int SCALING_LIST_NUM = MAX_NUM_COMPONENT * (NUMBER_OF_PREDICTION_MODES - 1); ///< list number for quantization matrix
......
......@@ -879,7 +879,7 @@ double EncAdaptiveLoopFilter::deriveCtbAlfEnableFlags( CodingStructure& cs, cons
assert( cs.slice->getTileGroupNumAps() == 1 );
m_CABACEstimator->codeAlfCtuFilterIndex(cs, ctuIdx, &m_alfParamTemp.enabledFlag[COMPONENT_Y]);
}
double costOn = distUnfilterCtu + ctuLambda * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double costOn = distUnfilterCtu + ctuLambda * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
#else
double costOn = distUnfilterCtu + getFilteredDistortion( m_alfCovariance[compID][iShapeIdx][ctuIdx], numClasses, m_alfParamTemp.numLumaFilters - 1, numCoeff );
......@@ -888,7 +888,7 @@ double EncAdaptiveLoopFilter::deriveCtbAlfEnableFlags( CodingStructure& cs, cons
#else
const double ctuLambda = m_lambda[compID];
#endif
costOn += ctuLambda * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
costOn += ctuLambda * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
#endif
ctxTempBest = AlfCtx( m_CABACEstimator->getCtx() );
#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
......@@ -908,7 +908,7 @@ double EncAdaptiveLoopFilter::deriveCtbAlfEnableFlags( CodingStructure& cs, cons
m_CABACEstimator->resetBits();
m_ctuAlternative[compID][ctuIdx] = altIdx;
m_CABACEstimator->codeAlfCtuAlternative( cs, ctuIdx, compID, &m_alfParamTemp );
double r_altCost = ctuLambda * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double r_altCost = ctuLambda * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
double altDist = 0.;
altDist += m_alfCovariance[compID][iShapeIdx][ctuIdx][0].calcErrorForCoeffs( m_filterClippSet[altIdx], m_filterCoeffSet[altIdx], numCoeff, m_NUM_BITS );
......@@ -930,7 +930,7 @@ double EncAdaptiveLoopFilter::deriveCtbAlfEnableFlags( CodingStructure& cs, cons
m_CABACEstimator->resetBits();
m_ctuEnableFlag[compID][ctuIdx] = 0;
m_CABACEstimator->codeAlfCtuEnableFlag( cs, ctuIdx, compID, &m_alfParamTemp);
double costOff = distUnfilterCtu + ctuLambda * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double costOff = distUnfilterCtu + ctuLambda * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
if( costOn < costOff )
{
......@@ -1240,7 +1240,7 @@ double EncAdaptiveLoopFilter::getFilterCoeffAndCost( CodingStructure& cs, double
}
m_CABACEstimator->codeAlfCtuAlternatives( cs, channel, &m_alfParamTemp );
#endif
rate += FracBitsScale * (double)m_CABACEstimator->getEstFracBits();
rate += FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
return dist + m_lambda[channel] * rate;
}
......@@ -3160,7 +3160,7 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar
m_CABACEstimator->codeAlfCtuEnableFlag(cs, ctbIdx, COMPONENT_Y, &m_alfParamTemp);
alfCtbFilterSetIndex[ctbIdx] = filterSetIdx;
m_CABACEstimator->codeAlfCtuFilterIndex(cs, ctbIdx, &m_alfParamTemp.enabledFlag[COMPONENT_Y]);
double rateOn = FracBitsScale *(double)m_CABACEstimator->getEstFracBits();
double rateOn = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
//distortion
double dist = distUnfilterCtb;
for (int classIdx = 0; classIdx < MAX_NUM_ALF_CLASSES; classIdx++)
......@@ -3213,7 +3213,8 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar
m_CABACEstimator->resetBits();
m_CABACEstimator->codeAlfCtuEnableFlag(cs, ctbIdx, COMPONENT_Y, &m_alfParamTemp);
//cost
double costOff = distUnfilterCtb + m_lambda[COMPONENT_Y] * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double costOff =
distUnfilterCtb + m_lambda[COMPONENT_Y] * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
if (costOn < costOff)
{
m_CABACEstimator->getCtx() = AlfCtx(ctxTempBest);
......@@ -3378,7 +3379,7 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar
m_CABACEstimator->resetBits();
//ctb flag
m_CABACEstimator->codeAlfCtuEnableFlag(cs, ctbIdx, compId, &m_alfParamTemp);
double rateOn = FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double rateOn = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
#if ENABLE_QPA
const double ctuLambda = lambdaChromaWeight > 0.0 ? cs.picture->m_uEnerHpCtu[ctbIdx] / lambdaChromaWeight : m_lambda[compId];
......@@ -3399,7 +3400,7 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar
m_CABACEstimator->resetBits();
m_ctuAlternative[compId][ctbIdx] = altIdx;
m_CABACEstimator->codeAlfCtuAlternative( cs, ctbIdx, compId, &m_alfParamTemp );
double altRate = FracBitsScale *(double)m_CABACEstimator->getEstFracBits();
double altRate = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
double r_altCost = ctuLambda * altRate;
//distortion
......@@ -3442,7 +3443,7 @@ void EncAdaptiveLoopFilter::alfEncoderCtb(CodingStructure& cs, AlfParam& alfPar
m_CABACEstimator->resetBits();
m_CABACEstimator->codeAlfCtuEnableFlag(cs, ctbIdx, compId, &m_alfParamTemp);
//cost
double costOff = distUnfilterCtu + m_lambda[compId] * FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double costOff = distUnfilterCtu + m_lambda[compId] * FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
if (costOn < costOff)
{
m_CABACEstimator->getCtx() = AlfCtx(ctxTempBest);
......
......@@ -249,7 +249,6 @@ private:
CABACWriter* m_CABACEstimator;
CtxCache* m_CtxCache;
double m_lambda[MAX_NUM_COMPONENT];
const double FracBitsScale = 1.0 / double( 1 << SCALE_BITS );
#if JVET_O0090_ALF_CHROMA_FILTER_ALTERNATIVES_CTB
int** m_filterCoeffSet; // [lumaClassIdx/chromaAltIdx][coeffIdx]
......
......@@ -2021,7 +2021,7 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
const TempCtx ctxStart(m_CtxCache, m_CABACEstimator->getCtx());
CodingUnit &cu = tempCS->addCU( tempCS->area, partitioner.chType );
const double sqrtLambdaForFirstPassIntra = m_pcRdCost->getMotionLambda(cu.transQuantBypass) / double(1 << SCALE_BITS);
const double sqrtLambdaForFirstPassIntra = m_pcRdCost->getMotionLambda(cu.transQuantBypass) * FRAC_BITS_SCALE;
partitioner.setCUData( cu );
cu.slice = tempCS->slice;
cu.tileIdx = tempCS->picture->brickMap->getBrickIdxRsMap( tempCS->area.lumaPos() );
......
......@@ -621,7 +621,7 @@ void EncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, int c
m_CABACEstimator->resetBits();
m_CABACEstimator->sao_offset_pars( modeParam[compIdx], compIdx, sliceEnabled[compIdx], bitDepths.recon[CHANNEL_TYPE_LUMA] );
modeDist[compIdx] = 0;
minCost= m_lambda[compIdx]*(FracBitsScale*(double)m_CABACEstimator->getEstFracBits());
minCost = m_lambda[compIdx] * (FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits());
ctxBestLuma = SAOCtx( m_CABACEstimator->getCtx() );
if(sliceEnabled[compIdx])
{
......@@ -643,7 +643,7 @@ void EncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, int c
m_CABACEstimator->getCtx() = SAOCtx( ctxStartLuma );
m_CABACEstimator->resetBits();
m_CABACEstimator->sao_offset_pars( testOffset[compIdx], compIdx, sliceEnabled[compIdx], bitDepths.recon[CHANNEL_TYPE_LUMA] );
double rate = FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double rate = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
cost = (double)dist[compIdx] + m_lambda[compIdx]*rate;
if(cost < minCost)
{
......@@ -670,7 +670,7 @@ void EncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, int c
modeDist [component] = 0;
m_CABACEstimator->sao_offset_pars( modeParam[component], component, sliceEnabled[component], bitDepths.recon[CHANNEL_TYPE_CHROMA] );
const uint64_t currentFracBits = m_CABACEstimator->getEstFracBits();
cost += m_lambda[component] * FracBitsScale * double( currentFracBits - previousFracBits );
cost += m_lambda[component] * FRAC_BITS_SCALE * (currentFracBits - previousFracBits);
previousFracBits = currentFracBits;
}
......@@ -703,7 +703,7 @@ void EncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, int c
dist[component] = getDistortion(bitDepths.recon[CHANNEL_TYPE_CHROMA], typeIdc, testOffset[component].typeAuxInfo, invQuantOffset, blkStats[ctuRsAddr][component][typeIdc]);
m_CABACEstimator->sao_offset_pars( testOffset[component], component, sliceEnabled[component], bitDepths.recon[CHANNEL_TYPE_CHROMA] );
const uint64_t currentFracBits = m_CABACEstimator->getEstFracBits();
cost += dist[component] + (m_lambda[component] * FracBitsScale * double(currentFracBits - previousFracBits));
cost += dist[component] + (m_lambda[component] * FRAC_BITS_SCALE * (currentFracBits - previousFracBits));
previousFracBits = currentFracBits;
}
......@@ -729,7 +729,7 @@ void EncSampleAdaptiveOffset::deriveModeNewRDO(const BitDepths &bitDepths, int c
m_CABACEstimator->getCtx() = SAOCtx( ctxStartBlk );
m_CABACEstimator->resetBits();
m_CABACEstimator->sao_block_pars( modeParam, bitDepths, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false );
modeNormCost += FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
modeNormCost += FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
}
void EncSampleAdaptiveOffset::deriveModeMergeRDO(const BitDepths &bitDepths, int ctuRsAddr, SAOBlkParam* mergeList[NUM_SAO_MERGE_TYPES], bool* sliceEnabled, std::vector<SAOStatData**>& blkStats, SAOBlkParam& modeParam, double& modeNormCost )
......@@ -772,7 +772,7 @@ void EncSampleAdaptiveOffset::deriveModeMergeRDO(const BitDepths &bitDepths, int
m_CABACEstimator->getCtx() = SAOCtx( ctxStart );
m_CABACEstimator->resetBits();
m_CABACEstimator->sao_block_pars( testBlkParam, bitDepths, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false );
double rate = FracBitsScale*(double)m_CABACEstimator->getEstFracBits();
double rate = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
cost = normDist+rate;
if(cost < modeNormCost)
......@@ -981,7 +981,7 @@ void EncSampleAdaptiveOffset::decideBlkParams(CodingStructure& cs, bool* sliceEn
testBlkParam[COMPONENT_Y].typeIdc = SAO_MERGE_LEFT;
m_CABACEstimator->resetBits();
m_CABACEstimator->sao_block_pars(testBlkParam, cs.sps->getBitDepths(), sliceEnabled, true, false, true);
double rate = FracBitsScale * (double)m_CABACEstimator->getEstFracBits();
double rate = FRAC_BITS_SCALE * m_CABACEstimator->getEstFracBits();
modeCost += rate * groupSize;
if (modeCost < minCost2)
{
......
......@@ -130,7 +130,6 @@ private: //members
CABACWriter* m_CABACEstimator;
CtxCache* m_CtxCache;
double m_lambda[MAX_NUM_COMPONENT];
const double FracBitsScale = 1.0 / double( 1 << SCALE_BITS );
//statistics
std::vector<SAOStatData**> m_statData; //[ctu][comp][classes]
......
......@@ -274,8 +274,7 @@ bool IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
const uint32_t uiHeightBit = g_aucLog2[partitioner.currArea().lheight()];
// Lambda calculation at equivalent Qp of 4 is recommended because at that Qp, the quantization divisor is 1.
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda(cu.transQuantBypass) / double(1 << SCALE_BITS);
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda(cu.transQuantBypass) * FRAC_BITS_SCALE;
//===== loop over partitions =====
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment