Commit b4a45775 authored by Xiaoyu Xiu's avatar Xiaoyu Xiu

initial check-in of JVET-S0234 on ACT and CRS fix

parent ffa9403d
......@@ -83,7 +83,11 @@ void RdCost::setLambda( double dLambda, const BitDepths &bitDepths )
m_dLambdaMotionSAD = sqrt(m_dLambda);
}
#if ACT_LMCS_FIX
void RdCost::lambdaAdjustColorTrans(bool forward, ComponentID componentID, bool bCS, int* pcResScaleInv)
#else
void RdCost::lambdaAdjustColorTrans(bool forward, ComponentID componentID)
#endif
{
if (m_resetStore)
{
......@@ -115,6 +119,15 @@ void RdCost::lambdaAdjustColorTrans(bool forward, ComponentID componentID)
m_dLambda = m_lambdaStore[m_pairCheck][componentID];
m_DistScale = m_DistScaleStore[m_pairCheck][componentID];
#if ACT_LMCS_FIX
if (bCS)
{
CHECK(m_pairCheck == 0 || componentID == COMPONENT_Y, "wrong lambda adjustment for CS");
double cResScale = (double)(1 << CSCALE_FP_PREC) / (double)(*pcResScaleInv);
m_dLambda = m_dLambda / (cResScale*cResScale);
m_DistScale = double(1 << SCALE_BITS) / m_dLambda;
}
#endif
if (m_pairCheck == 0)
{
CHECK(m_DistScale != m_DistScaleUnadjusted, "lambda should be adjusted to the original value");
......
......@@ -326,7 +326,11 @@ public:
inline std::vector<double>& getLumaLevelWeightTable () { return m_lumaLevelToWeightPLUT; }
#endif
#if ACT_LMCS_FIX
void lambdaAdjustColorTrans(bool forward, ComponentID compID, bool bCS = false, int* pcResScaleInv = NULL);
#else
void lambdaAdjustColorTrans(bool forward, ComponentID compID);
#endif
void resetStore() { m_resetStore = true; }
private:
......
......@@ -53,7 +53,7 @@
//########### place macros to be removed in next cycle below this line ###############
#define ACT_LMCS_FIX 1 // JVET-S0234: perform chroma residual scaling in RGB domain when ACT is on
//########### place macros to be be kept below this line ###############
#define JVET_R0351_HIGH_BIT_DEPTH_SUPPORT 1 // JVET-R0351: high bit depth coding support (syntax changes, no mathematical differences for CTCs)
......
......@@ -347,7 +347,11 @@ void DecCu::xIntraRecACTBlk(TransformUnit& tu)
CHECK(pu.intraDir[CHANNEL_TYPE_CHROMA] != DM_CHROMA_IDX, "chroma should use DM mode for adaptive color transform");
bool flag = slice.getLmcsEnabledFlag() && (slice.isIntra() || (!slice.isIntra() && m_pcReshape->getCTUFlag()));
#if ACT_LMCS_FIX
if (flag && slice.getPicHeader()->getLmcsChromaResidualScaleFlag())
#else
if (flag && slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && (tu.cbf[COMPONENT_Cb] || tu.cbf[COMPONENT_Cr]))
#endif
{
const Area area = tu.Y().valid() ? tu.Y() : Area(recalcPosition(tu.chromaFormat, tu.chType, CHANNEL_TYPE_LUMA, tu.blocks[tu.chType].pos()), recalcSize(tu.chromaFormat, tu.chType, CHANNEL_TYPE_LUMA, tu.blocks[tu.chType].size()));
const CompArea &areaY = CompArea(COMPONENT_Y, tu.chromaFormat, area);
......@@ -407,11 +411,13 @@ void DecCu::xIntraRecACTBlk(TransformUnit& tu)
}
}
flag = flag && (tu.blocks[compID].width*tu.blocks[compID].height > 4);
#if !ACT_LMCS_FIX
flag = flag && (tu.blocks[compID].width*tu.blocks[compID].height > 4);
if (flag && (TU::getCbf(tu, compID) || tu.jointCbCr) && isChroma(compID) && slice.getPicHeader()->getLmcsChromaResidualScaleFlag())
{
piResi.scaleSignal(tu.getChromaAdj(), 0, tu.cu->cs->slice->clpRng(compID));
}
#endif
cs.setDecomp(area);
}
......@@ -435,6 +441,12 @@ void DecCu::xIntraRecACTBlk(TransformUnit& tu)
tmpPred.copyFrom(piPred);
}
#if ACT_LMCS_FIX
if (flag && isChroma(compID) && (tu.blocks[compID].width*tu.blocks[compID].height > 4) && slice.getPicHeader()->getLmcsChromaResidualScaleFlag())
{
piResi.scaleSignal(tu.getChromaAdj(), 0, tu.cu->cs->slice->clpRng(compID));
}
#endif
piPred.reconstruct(piPred, piResi, tu.cu->cs->slice->clpRng(compID));
piReco.copyFrom(piPred);
......@@ -694,10 +706,12 @@ void DecCu::xReconInter(CodingUnit &cu)
if (cu.rootCbf)
{
#if !ACT_LMCS_FIX
if (cu.colorTransform)
{
cs.getResiBuf(cu).colorSpaceConvert(cs.getResiBuf(cu), false, cu.cs->slice->clpRng(COMPONENT_Y));
}
#endif
#if REUSE_CU_RESULTS
const CompArea &area = cu.blocks[COMPONENT_Y];
CompArea tmpArea(COMPONENT_Y, area.chromaFormat, Position(0, 0), area.size());
......@@ -788,7 +802,11 @@ void DecCu::xDecodeInterTU( TransformUnit & currTU, const ComponentID compID )
//===== reconstruction =====
const Slice &slice = *cs.slice;
#if ACT_LMCS_FIX
if (!currTU.cu->colorTransform && slice.getPicHeader()->getLmcsEnabledFlag() && isChroma(compID) && (TU::getCbf(currTU, compID) || currTU.jointCbCr)
#else
if (slice.getLmcsEnabledFlag() && isChroma(compID) && (TU::getCbf(currTU, compID) || currTU.jointCbCr)
#endif
&& slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && currTU.blocks[compID].width * currTU.blocks[compID].height > 4)
{
resiBuf.scaleSignal(currTU.getChromaAdj(), 0, currTU.cu->cs->slice->clpRng(compID));
......@@ -804,6 +822,36 @@ void DecCu::xDecodeInterTexture(CodingUnit &cu)
const uint32_t uiNumVaildComp = getNumberValidComponents(cu.chromaFormat);
#if ACT_LMCS_FIX
if (cu.colorTransform)
{
CodingStructure &cs = *cu.cs;
const Slice &slice = *cs.slice;
for (auto& currTU : CU::traverseTUs(cu))
{
for (uint32_t ch = 0; ch < uiNumVaildComp; ch++)
{
const ComponentID compID = ComponentID(ch);
if (slice.getPicHeader()->getLmcsEnabledFlag() && slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && (compID == COMPONENT_Y))
{
const CompArea &areaY = currTU.blocks[COMPONENT_Y];
int adj = m_pcReshape->calculateChromaAdjVpduNei(currTU, areaY);
currTU.setChromaAdj(adj);
}
xDecodeInterTU(currTU, compID);
}
cs.getResiBuf(currTU).colorSpaceConvert(cs.getResiBuf(currTU), false, cu.cs->slice->clpRng(COMPONENT_Y));
if (slice.getPicHeader()->getLmcsEnabledFlag() && slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && currTU.blocks[COMPONENT_Cb].width * currTU.blocks[COMPONENT_Cb].height > 4)
{
cs.getResiBuf(currTU.blocks[COMPONENT_Cb]).scaleSignal(currTU.getChromaAdj(), 0, currTU.cu->cs->slice->clpRng(COMPONENT_Cb));
cs.getResiBuf(currTU.blocks[COMPONENT_Cr]).scaleSignal(currTU.getChromaAdj(), 0, currTU.cu->cs->slice->clpRng(COMPONENT_Cr));
}
}
}
else
{
#endif
for (uint32_t ch = 0; ch < uiNumVaildComp; ch++)
{
const ComponentID compID = ComponentID(ch);
......@@ -821,6 +869,9 @@ void DecCu::xDecodeInterTexture(CodingUnit &cu)
xDecodeInterTU( currTU, compID );
}
}
#if ACT_LMCS_FIX
}
#endif
}
void DecCu::xDeriveCUMV( CodingUnit &cu )
......
This diff is collapsed.
......@@ -3458,6 +3458,7 @@ void IntraSearch::xIntraCodingACTTUBlock(TransformUnit &tu, const ComponentID &c
}
}
#if !ACT_LMCS_FIX
if (flag && uiAbsSum > 0 && isChroma(compID) && slice.getPicHeader()->getLmcsChromaResidualScaleFlag())
{
piResi.scaleSignal(tu.getChromaAdj(), 0, slice.clpRng(compID));
......@@ -3466,6 +3467,7 @@ void IntraSearch::xIntraCodingACTTUBlock(TransformUnit &tu, const ComponentID &c
crResi.scaleSignal(tu.getChromaAdj(), 0, slice.clpRng(COMPONENT_Cr));
}
}
#endif
if (m_pcEncCfg->getCostMode() != COST_LOSSLESS_CODING || !slice.isLossless())
m_pcTrQuant->lambdaAdjustColorTrans(false);
......@@ -4156,6 +4158,16 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
PelUnitBuf predBuf = csFull->getPredBuf(tu);
PelUnitBuf resiBuf = csFull->getResiBuf(tu);
PelUnitBuf orgResiBuf = csFull->getOrgResiBuf(tu);
#if ACT_LMCS_FIX
bool doReshaping = (slice.getPicHeader()->getLmcsEnabledFlag() && slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && (slice.isIntra() || m_pcReshape->getCTUFlag()) && (tu.blocks[COMPONENT_Cb].width * tu.blocks[COMPONENT_Cb].height > 4));
if (doReshaping)
{
const Area area = tu.Y().valid() ? tu.Y() : Area(recalcPosition(tu.chromaFormat, tu.chType, CHANNEL_TYPE_LUMA, tu.blocks[tu.chType].pos()), recalcSize(tu.chromaFormat, tu.chType, CHANNEL_TYPE_LUMA, tu.blocks[tu.chType].size()));
const CompArea &areaY = CompArea(COMPONENT_Y, tu.chromaFormat, area);
int adj = m_pcReshape->calculateChromaAdjVpduNei(tu, areaY);
tu.setChromaAdj(adj);
}
#endif
for (int i = 0; i < getNumberValidComponents(tu.chromaFormat); i++)
{
......@@ -4187,6 +4199,14 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
piResi.rspSignal(m_pcReshape->getFwdLUT());
piResi.subtract(tmpPred);
}
#if ACT_LMCS_FIX
else if (doReshaping && (compID != COMPONENT_Y))
{
piResi.subtract(piPred);
int cResScaleInv = tu.getChromaAdj();
piResi.scaleSignal(cResScaleInv, 1, slice.clpRng(compID));
}
#endif
else
piResi.subtract(piPred);
}
......@@ -4482,6 +4502,7 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
tu.jointCbCr = 0;
#if !ACT_LMCS_FIX
bool doReshaping = (slice.getLmcsEnabledFlag() && slice.getPicHeader()->getLmcsChromaResidualScaleFlag() && (slice.isIntra() || m_pcReshape->getCTUFlag()) && (cbArea.width * cbArea.height > 4));
if (doReshaping)
{
......@@ -4490,18 +4511,21 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
int adj = m_pcReshape->calculateChromaAdjVpduNei(tu, areaY);
tu.setChromaAdj(adj);
}
#endif
CompStorage orgResiCb[5], orgResiCr[5]; // 0:std, 1-3:jointCbCr (placeholder at this stage), 4:crossComp
orgResiCb[0].create(cbArea);
orgResiCr[0].create(crArea);
orgResiCb[0].copyFrom(csFull->getOrgResiBuf(cbArea));
orgResiCr[0].copyFrom(csFull->getOrgResiBuf(crArea));
#if !ACT_LMCS_FIX
if (doReshaping)
{
int cResScaleInv = tu.getChromaAdj();
orgResiCb[0].scaleSignal(cResScaleInv, 1, slice.clpRng(COMPONENT_Cb));
orgResiCr[0].scaleSignal(cResScaleInv, 1, slice.clpRng(COMPONENT_Cr));
}
#endif
// 3.1 regular chroma residual coding
csFull->getResiBuf(cbArea).copyFrom(orgResiCb[0]);
......@@ -4539,7 +4563,21 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
}
}
if (m_pcEncCfg->getCostMode() != COST_LOSSLESS_CODING || !slice.isLossless())
#if ACT_LMCS_FIX
{
if (doReshaping)
{
int cResScaleInv = tu.getChromaAdj();
m_pcRdCost->lambdaAdjustColorTrans(true, compID, true, &cResScaleInv);
}
else
{
m_pcRdCost->lambdaAdjustColorTrans(true, compID);
}
}
#else
m_pcRdCost->lambdaAdjustColorTrans(true, compID);
#endif
TempCtx ctxBegin(m_CtxCache);
ctxBegin = m_CABACEstimator->getCtx();
......@@ -4616,6 +4654,12 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
PelBuf piPred = csFull->getPredBuf(area);
PelBuf piResi = invColorTransResidual.bufs[compID];
#if ACT_LMCS_FIX
if (doReshaping && (compID != COMPONENT_Y))
{
piResi.scaleSignal(tu.getChromaAdj(), 0, slice.clpRng(compID));
}
#endif
piReco.reconstruct(piPred, piResi, cs.slice->clpRng(compID));
if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() || (m_pcEncCfg->getLmcs()
......@@ -4724,6 +4768,12 @@ bool IntraSearch::xRecurIntraCodingACTQT(CodingStructure &cs, Partitioner &parti
PelBuf piPred = csFull->getPredBuf(area);
PelBuf piResi = invColorTransResidual.bufs[compID];
#if ACT_LMCS_FIX
if (doReshaping && (compID != COMPONENT_Y))
{
piResi.scaleSignal(tu.getChromaAdj(), 0, slice.clpRng(compID));
}
#endif
piReco.reconstruct(piPred, piResi, cs.slice->clpRng(compID));
if (m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() || (m_pcEncCfg->getLmcs()
& slice.getLmcsEnabledFlag() && (m_pcReshape->getCTUFlag() || (isChroma(compID) && m_pcEncCfg->getReshapeIntraCMD()))))
......
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