Commit 808c8ddb authored by Christian Helmrich's avatar Christian Helmrich

fix perceptual QP adaptation for unequal Cb and Cr QP offsets and in combination with JCCR

parent 615de54b
......@@ -2274,7 +2274,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
#endif
#if ENABLE_QPA
if (m_bUsePerceptQPA && !m_bUseAdaptiveQP && m_dualTree && (m_cbQpOffsetDualTree != 0 || m_crQpOffsetDualTree != 0))
if (m_bUsePerceptQPA && !m_bUseAdaptiveQP && m_dualTree && (m_cbQpOffsetDualTree != 0 || m_crQpOffsetDualTree != 0 || m_cbCrQpOffsetDualTree != 0))
{
msg( WARNING, "*************************************************************************\n" );
msg( WARNING, "* WARNING: chroma QPA on, ignoring nonzero dual-tree chroma QP offsets! *\n" );
......
......@@ -146,6 +146,9 @@ public:
double getLambda() { return m_dLambda; }
#endif
double getChromaWeight() { return ((m_distortionWeight[COMPONENT_Cb] + m_distortionWeight[COMPONENT_Cr]) / 2.0); }
#if RDOQ_CHROMA_LAMBDA
double getDistortionWeight ( const ComponentID compID ) const { return m_distortionWeight[compID % 3]; }
#endif
void setCostMode(CostMode m) { m_costMode = m; }
......
......@@ -1138,8 +1138,9 @@ void EncCu::updateLambda (Slice* slice, const int dQP,
#endif
const double newLambda = oldLambda * pow (2.0, ((double)dQP - oldQP) / 3.0);
#if RDOQ_CHROMA_LAMBDA
const double chromaLambda = newLambda / m_pcRdCost->getChromaWeight();
const double lambdaArray[MAX_NUM_COMPONENT] = {newLambda, chromaLambda, chromaLambda};
const double lambdaArray[MAX_NUM_COMPONENT] = {newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Y),
newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cb),
newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cr)};
m_pcTrQuant->setLambdas (lambdaArray);
#else
m_pcTrQuant->setLambda (newLambda);
......
......@@ -523,6 +523,7 @@ void EncSlice::initEncSlice(Picture* pcPic, const int pocLast, const int pocCurr
const bool bUseIntraOrPeriodicOffset = (rpcSlice->isIntra() && !rpcSlice->getSPS()->getIBCFlag()) || (m_pcCfg->getSliceChromaOffsetQpPeriodicity() > 0 && (rpcSlice->getPOC() % m_pcCfg->getSliceChromaOffsetQpPeriodicity()) == 0);
int cbQP = bUseIntraOrPeriodicOffset ? m_pcCfg->getSliceChromaOffsetQpIntraOrPeriodic(false) : m_pcCfg->getGOPEntry(iGOPid).m_CbQPoffset;
int crQP = bUseIntraOrPeriodicOffset ? m_pcCfg->getSliceChromaOffsetQpIntraOrPeriodic(true) : m_pcCfg->getGOPEntry(iGOPid).m_CrQPoffset;
int cbCrQP = (cbQP + crQP) >> 1; // use floor of average chroma QP offset for joint-Cb/Cr coding
cbQP = Clip3( -12, 12, cbQP + rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb) ) - rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb);
crQP = Clip3( -12, 12, crQP + rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr) ) - rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr);
......@@ -530,6 +531,11 @@ void EncSlice::initEncSlice(Picture* pcPic, const int pocLast, const int pocCurr
CHECK(!(rpcSlice->getSliceChromaQpDelta(COMPONENT_Cb)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb)<=12 && rpcSlice->getSliceChromaQpDelta(COMPONENT_Cb)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cb)>=-12), "Unspecified error");
rpcSlice->setSliceChromaQpDelta(COMPONENT_Cr, Clip3( -12, 12, crQP));
CHECK(!(rpcSlice->getSliceChromaQpDelta(COMPONENT_Cr)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr)<=12 && rpcSlice->getSliceChromaQpDelta(COMPONENT_Cr)+rpcSlice->getPPS()->getQpOffset(COMPONENT_Cr)>=-12), "Unspecified error");
if (rpcSlice->getSPS()->getJointCbCrEnabledFlag())
{
cbCrQP = Clip3(-12, 12, cbCrQP + rpcSlice->getPPS()->getQpOffset(JOINT_CbCr)) - rpcSlice->getPPS()->getQpOffset(JOINT_CbCr);
rpcSlice->setSliceChromaQpDelta(JOINT_CbCr, Clip3( -12, 12, cbCrQP ));
}
}
else
{
......@@ -553,6 +559,9 @@ void EncSlice::initEncSlice(Picture* pcPic, const int pocLast, const int pocCurr
dLambda *= lambdaModifier;
#endif
#if RDOQ_CHROMA_LAMBDA
m_pcRdCost->setDistortionWeight (COMPONENT_Y, 1.0); // no chroma weighting for luma
#endif
setUpLambda(rpcSlice, dLambda, iQP);
#if WCG_EXT
......@@ -1617,9 +1626,9 @@ void EncSlice::encodeCtus( Picture* pcPic, const bool bCompressEntireSlice, cons
pRdCost->setLambda(estLambda, pcSlice->getSPS()->getBitDepths());
#if RDOQ_CHROMA_LAMBDA
// set lambda for RDOQ
const double chromaLambda = estLambda / pRdCost->getChromaWeight();
const double lambdaArray[MAX_NUM_COMPONENT] = { estLambda, chromaLambda, chromaLambda };
const double lambdaArray[MAX_NUM_COMPONENT] = {estLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Y),
estLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cb),
estLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cr)};
pTrQuant->setLambdas( lambdaArray );
#else
pTrQuant->setLambda( estLambda );
......@@ -1641,8 +1650,9 @@ void EncSlice::encodeCtus( Picture* pcPic, const bool bCompressEntireSlice, cons
#if !ENABLE_QPA_SUB_CTU
#if RDOQ_CHROMA_LAMBDA
pTrQuant->getLambdas (oldLambdaArray); // save the old lambdas
const double chromaLambda = newLambda / pRdCost->getChromaWeight();
const double lambdaArray[MAX_NUM_COMPONENT] = {newLambda, chromaLambda, chromaLambda};
const double lambdaArray[MAX_NUM_COMPONENT] = {newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Y),
newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cb),
newLambda / m_pcRdCost->getDistortionWeight (COMPONENT_Cr)};
pTrQuant->setLambdas (lambdaArray);
#else
pTrQuant->setLambda (newLambda);
......
Markdown is supported
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