Commit e72fc404 authored by Xiang Li's avatar Xiang Li
Browse files

Merge branch 'JVET_N0302_SIMPLFIED_CIIP' into 'master'

JVET-N0302: Simplified CIIP

See merge request jvet/VVCSoftware_VTM!494
parents f454b9ad a62384c2
......@@ -790,7 +790,7 @@ const CtxSet ContextSetCfg::MHIntraFlag = ContextSetCfg::addCtxSet
{ CNU, },
{ 1, },
});
#if !JVET_N0302_SIMPLFIED_CIIP
const CtxSet ContextSetCfg::MHIntraPredMode = ContextSetCfg::addCtxSet
({
{ 156, CNU, CNU, CNU, },
......@@ -798,7 +798,7 @@ const CtxSet ContextSetCfg::MHIntraPredMode = ContextSetCfg::addCtxSet
{ CNU, CNU, CNU, CNU, },
{ 9, DWS, DWS, DWS, },
});
#endif
const CtxSet ContextSetCfg::TriangleFlag = ContextSetCfg::addCtxSet
({
#if JVET_N600_AMVR_TPM_CTX_REDUCTION
......
......@@ -259,7 +259,9 @@ public:
static const CtxSet GBiIdx;
static const CtxSet ctbAlfFlag;
static const CtxSet MHIntraFlag;
#if !JVET_N0302_SIMPLFIED_CIIP
static const CtxSet MHIntraPredMode;
#endif
static const CtxSet TriangleFlag;
static const CtxSet TriangleIdx;
static const CtxSet SmvdFlag;
......
......@@ -902,6 +902,48 @@ bool IntraPrediction::useDPCMForFirstPassIntraEstimation(const PredictionUnit &p
return CU::isRDPCMEnabled(*pu.cu) && pu.cu->transQuantBypass && (uiDirMode == HOR_IDX || uiDirMode == VER_IDX);
}
#if JVET_N0302_SIMPLFIED_CIIP
void IntraPrediction::geneWeightedPred(const ComponentID compId, PelBuf &pred, const PredictionUnit &pu, Pel *srcBuf)
{
const int width = pred.width;
const int height = pred.height;
const int srcStride = width;
const int dstStride = pred.stride;
Pel* dstBuf = pred.buf;
int wIntra, wMerge;
const Position posBL = pu.Y().bottomLeft();
const Position posTR = pu.Y().topRight();
const PredictionUnit *neigh0 = pu.cs->getPURestricted(posBL.offset(-1, 0), pu, CHANNEL_TYPE_LUMA);
const PredictionUnit *neigh1 = pu.cs->getPURestricted(posTR.offset(0, -1), pu, CHANNEL_TYPE_LUMA);
bool isNeigh0Intra = neigh0 && (CU::isIntra(*neigh0->cu));
bool isNeigh1Intra = neigh1 && (CU::isIntra(*neigh1->cu));
if (isNeigh0Intra && isNeigh1Intra)
{
wIntra = 3; wMerge = 1;
}
else
{
if (!isNeigh0Intra && !isNeigh1Intra)
{
wIntra = 1; wMerge = 3;
}
else
{
wIntra = 2; wMerge = 2;
}
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
dstBuf[y*dstStride + x] = (wMerge * dstBuf[y*dstStride + x] + wIntra * srcBuf[y*srcStride + x] + 2) >> 2;
}
}
}
#else
void IntraPrediction::geneWeightedPred(const ComponentID compId, PelBuf &pred, const PredictionUnit &pu, Pel *srcBuf)
{
const int width = pred.width;
......@@ -984,6 +1026,7 @@ void IntraPrediction::geneWeightedPred(const ComponentID compId, PelBuf &pred, c
}
}
}
#endif
void IntraPrediction::switchBuffer(const PredictionUnit &pu, ComponentID compID, PelBuf srcBuff, Pel *dst)
{
Pel *src = srcBuff.bufAt(0, 0);
......
......@@ -346,6 +346,7 @@ void LoopFilter::xDeblockCU( CodingUnit& cu, const DeblockEdgeDir edgeDir )
xSetMaxFilterLengthPQForCodingSubBlocks( edgeDir, cu, currPU, mvSubBlocks, subBlockSize, areaPu );
#endif
}
#if !JVET_N0302_SIMPLFIED_CIIP
if (cu.firstPU->mhIntraFlag)
{
const uint32_t dirMode = PU::getFinalIntraMode(*(cu.firstPU), cu.chType);
......@@ -384,6 +385,7 @@ void LoopFilter::xDeblockCU( CodingUnit& cu, const DeblockEdgeDir edgeDir )
xSetMaxFilterLengthPQForCodingSubBlocks( edgeDir, cu, currPU, mvSubBlocks, subBlockSize, areaPu );
#endif
}
#endif
const unsigned uiPelsInPart = pcv.minCUWidth;
......@@ -1032,6 +1034,9 @@ void LoopFilter::xEdgeFilterLuma(const CodingUnit& cu, const DeblockEdgeDir edge
#endif
{
// restrict filter length if sub-blocks are used (e.g affine or ATMVP)
#if JVET_N0302_SIMPLFIED_CIIP
if (cuP.affine)
#else
bool ciipSubBlock = false;
if (cuP.firstPU->mhIntraFlag)
{
......@@ -1039,6 +1044,7 @@ void LoopFilter::xEdgeFilterLuma(const CodingUnit& cu, const DeblockEdgeDir edge
ciipSubBlock = edgeDir == EDGE_HOR ? dirMode == VER_IDX : dirMode == HOR_IDX;
}
if (cuP.affine || ciipSubBlock)
#endif
{
maxFilterLengthP = std::min(maxFilterLengthP, 5);
}
......
......@@ -56,6 +56,8 @@
#define JVET_N0340_TRI_MERGE_CAND 1
#define JVET_N0302_SIMPLFIED_CIIP 1
#define JVET_N0324_REGULAR_MRG_FLAG 1
#define JVET_N0251_ITEM4_IBC_LOCAL_SEARCH_RANGE 1
......
......@@ -837,6 +837,7 @@ bool PU::isChromaIntraModeCrossCheckMode( const PredictionUnit &pu )
return pu.intraDir[CHANNEL_TYPE_CHROMA] == DM_CHROMA_IDX;
}
#if !JVET_N0302_SIMPLFIED_CIIP
int PU::getMHIntraMPMs(const PredictionUnit &pu, unsigned* mpm, const ChannelType &channelType /*= CHANNEL_TYPE_LUMA*/, const bool isChromaMDMS /*= false*/, const unsigned startIdx /*= 0*/)
{
const int numMPMs = 3; // Multi-hypothesis intra uses only 3 MPM
......@@ -964,6 +965,7 @@ int PU::getMHIntraMPMs(const PredictionUnit &pu, unsigned* mpm, const ChannelTyp
return numCand;
}
}
#endif
int PU::getNarrowShape(const int width, const int height)
{
int longSide = (width > height) ? width : height;
......
......@@ -182,7 +182,9 @@ namespace PU
bool isLMCMode ( unsigned mode);
bool isLMCModeEnabled (const PredictionUnit &pu, unsigned mode);
bool isChromaIntraModeCrossCheckMode(const PredictionUnit &pu);
#if !JVET_N0302_SIMPLFIED_CIIP
int getMHIntraMPMs (const PredictionUnit &pu, unsigned *mpm, const ChannelType &channelType = CHANNEL_TYPE_LUMA, const bool isChromaMDMS = false, const unsigned startIdx = 0);
#endif
int getNarrowShape (const int width, const int height);
void getTriangleMergeCandidates (const PredictionUnit &pu, MergeCtx &triangleMrgCtx);
bool isUniqueTriangleCandidates (const PredictionUnit &pu, MergeCtx &triangleMrgCtx);
......
......@@ -1548,7 +1548,11 @@ void CABACReader::prediction_unit( PredictionUnit& pu, MergeCtx& mrgCtx )
MHIntra_flag(pu);
if (pu.mhIntraFlag)
{
#if JVET_N0302_SIMPLFIED_CIIP
pu.intraDir[0] = PLANAR_IDX;
#else
MHIntra_luma_pred_modes(*pu.cu);
#endif
pu.intraDir[1] = DM_CHROMA_IDX;
}
#if JVET_N0324_REGULAR_MRG_FLAG
......@@ -2077,6 +2081,7 @@ void CABACReader::MHIntra_flag(PredictionUnit& pu)
DTRACE(g_trace_ctx, D_SYNTAX, "MHIntra_flag() MHIntra=%d pos=(%d,%d) size=%dx%d\n", pu.mhIntraFlag ? 1 : 0, pu.lumaPos().x, pu.lumaPos().y, pu.lumaSize().width, pu.lumaSize().height);
}
#if !JVET_N0302_SIMPLFIED_CIIP
void CABACReader::MHIntra_luma_pred_modes(CodingUnit &cu)
{
if (!cu.Y().valid())
......@@ -2170,6 +2175,7 @@ void CABACReader::MHIntra_luma_pred_modes(CodingUnit &cu)
pu = pu->next;
}
}
#endif
void CABACReader::triangle_mode( CodingUnit& cu )
{
......
......@@ -1477,6 +1477,7 @@ void CABACWriter::prediction_unit( const PredictionUnit& pu )
#endif
subblock_merge_flag( *pu.cu );
MHIntra_flag( pu );
#if !JVET_N0302_SIMPLFIED_CIIP
if ( pu.mhIntraFlag )
{
MHIntra_luma_pred_modes( *pu.cu );
......@@ -1491,6 +1492,19 @@ void CABACWriter::prediction_unit( const PredictionUnit& pu )
}
#else
triangle_mode( *pu.cu );
#endif
#else
#if JVET_N0324_REGULAR_MRG_FLAG
if (!pu.mhIntraFlag)
{
if (!pu.cu->affine && !pu.mmvdMergeFlag && !pu.cu->mmvdSkip)
{
CHECK(!pu.cu->triangle, "triangle_flag must be true");
}
}
#else
triangle_mode(*pu.cu);
#endif
#endif
if (pu.mmvdMergeFlag)
{
......@@ -2003,6 +2017,7 @@ void CABACWriter::MHIntra_flag(const PredictionUnit& pu)
DTRACE(g_trace_ctx, D_SYNTAX, "MHIntra_flag() MHIntra=%d pos=(%d,%d) size=%dx%d\n", pu.mhIntraFlag ? 1 : 0, pu.lumaPos().x, pu.lumaPos().y, pu.lumaSize().width, pu.lumaSize().height);
}
#if !JVET_N0302_SIMPLFIED_CIIP
void CABACWriter::MHIntra_luma_pred_modes(const CodingUnit& cu)
{
if (!cu.Y().valid())
......@@ -2062,6 +2077,7 @@ void CABACWriter::MHIntra_luma_pred_modes(const CodingUnit& cu)
pu = pu->next;
}
}
#endif
void CABACWriter::triangle_mode( const CodingUnit& cu )
{
......
......@@ -1796,8 +1796,9 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
const double sqrtLambdaForFirstPass = m_pcRdCost->getMotionLambda( encTestMode.lossless );
CodingUnit &cu = tempCS->addCU( tempCS->area, partitioner.chType );
#if !JVET_N0302_SIMPLFIED_CIIP
const double sqrtLambdaForFirstPassIntra = m_pcRdCost->getMotionLambda(cu.transQuantBypass) / double(1 << SCALE_BITS);
#endif
partitioner.setCUData( cu );
cu.slice = tempCS->slice;
cu.tileIdx = tempCS->picture->tileMap->getTileIdxMap( tempCS->area.lumaPos() );
......@@ -1893,15 +1894,18 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
if (isIntrainterEnabled)
{
#if !JVET_N0302_SIMPLFIED_CIIP
int numTestIntraMode = 4;
#endif
// prepare for Intra bits calculation
const TempCtx ctxStart(m_CtxCache, m_CABACEstimator->getCtx());
#if !JVET_N0302_SIMPLFIED_CIIP
const TempCtx ctxStartIntraMode(m_CtxCache, SubCtx(Ctx::MHIntraPredMode, m_CABACEstimator->getCtx()));
// for Intrainter fast, recored the best intra mode during the first round for mrege 0
int bestMHIntraMode = -1;
double bestMHIntraCost = MAX_DOUBLE;
#endif
pu.mhIntraFlag = true;
// save the to-be-tested merge candidates
......@@ -1923,6 +1927,50 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
}
// first round
#if JVET_N0302_SIMPLFIED_CIIP
pu.intraDir[0] = PLANAR_IDX;
uint32_t intraCnt = 0;
// generate intrainter Y prediction
if (mergeCnt == 0)
{
m_pcIntraSearch->initIntraPatternChType(*pu.cu, pu.Y());
m_pcIntraSearch->predIntraAng(COMPONENT_Y, pu.cs->getPredBuf(pu).Y(), pu);
m_pcIntraSearch->switchBuffer(pu, COMPONENT_Y, pu.cs->getPredBuf(pu).Y(), m_pcIntraSearch->getPredictorPtr2(COMPONENT_Y, intraCnt));
}
pu.cs->getPredBuf(pu).copyFrom(acMergeBuffer[mergeCand]);
if (pu.cs->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())
{
pu.cs->getPredBuf(pu).Y().rspSignal(m_pcReshape->getFwdLUT());
}
m_pcIntraSearch->geneWeightedPred(COMPONENT_Y, pu.cs->getPredBuf(pu).Y(), pu, m_pcIntraSearch->getPredictorPtr2(COMPONENT_Y, intraCnt));
// calculate cost
if (pu.cs->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())
{
pu.cs->getPredBuf(pu).Y().rspSignal(m_pcReshape->getInvLUT());
}
distParam.cur = pu.cs->getPredBuf(pu).Y();
Distortion sadValue = distParam.distFunc(distParam);
if (pu.cs->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())
{
pu.cs->getPredBuf(pu).Y().rspSignal(m_pcReshape->getFwdLUT());
}
#if JVET_N0324_REGULAR_MRG_FLAG
double cost = (double)sadValue + (double)(bitsCand + 9) * sqrtLambdaForFirstPass;
#else
double cost = (double)sadValue + (double)(bitsCand + 1) * sqrtLambdaForFirstPass;
#endif
insertPos = -1;
updateDoubleCandList(mergeCand + MRG_MAX_NUM_CANDS + MMVD_ADD_NUM, cost, RdModeList, candCostList, RdModeList2, pu.intraDir[0], uiNumMrgSATDCand, &insertPos);
if (insertPos != -1)
{
for (int i = int(RdModeList.size()) - 1; i > insertPos; i--)
{
swap(acMergeTempBuffer[i - 1], acMergeTempBuffer[i]);
}
swap(singleMergeTempBuffer, acMergeTempBuffer[insertPos]);
}
#else
for (uint32_t intraCnt = 0; intraCnt < numTestIntraMode; intraCnt++)
{
pu.intraDir[0] = (intraCnt < 2) ? intraCnt : ((intraCnt == 2) ? HOR_IDX : VER_IDX);
......@@ -1990,6 +2038,7 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
bestMHIntraCost = cost;
}
}
#endif
}
pu.mhIntraFlag = false;
m_CABACEstimator->getCtx() = ctxStart;
......@@ -2089,8 +2138,11 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
{
pu.intraDir[0] = RdModeList2[mergeCnt];
pu.intraDir[1] = DM_CHROMA_IDX;
#if JVET_N0302_SIMPLFIED_CIIP
uint32_t bufIdx = 0;
#else
uint32_t bufIdx = (pu.intraDir[0] > 1) ? (pu.intraDir[0] == HOR_IDX ? 2 : 3) : pu.intraDir[0];
#endif
m_pcIntraSearch->initIntraPatternChType(*pu.cu, pu.Cb());
m_pcIntraSearch->predIntraAng(COMPONENT_Cb, pu.cs->getPredBuf(pu).Cb(), pu);
m_pcIntraSearch->switchBuffer(pu, COMPONENT_Cb, pu.cs->getPredBuf(pu).Cb(), m_pcIntraSearch->getPredictorPtr2(COMPONENT_Cb, bufIdx));
......@@ -2228,7 +2280,11 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
}
if (pu.mhIntraFlag)
{
#if JVET_N0302_SIMPLFIED_CIIP
uint32_t bufIdx = 0;
#else
uint32_t bufIdx = (pu.intraDir[0] > 1) ? (pu.intraDir[0] == HOR_IDX ? 2 : 3) : pu.intraDir[0];
#endif
PelBuf tmpBuf = tempCS->getPredBuf(pu).Y();
tmpBuf.copyFrom(acMergeBuffer[uiMergeCand].Y());
if (pu.cs->slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag())
......
......@@ -281,7 +281,9 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
const TempCtx ctxStart ( m_CtxCache, m_CABACEstimator->getCtx() );
const TempCtx ctxStartIntraMode(m_CtxCache, SubCtx(Ctx::IntraLumaMpmFlag, m_CABACEstimator->getCtx()));
#if !JVET_N0302_SIMPLFIED_CIIP
const TempCtx ctxStartMHIntraMode ( m_CtxCache, SubCtx( Ctx::MHIntraPredMode, m_CABACEstimator->getCtx() ) );
#endif
const TempCtx ctxStartMrlIdx ( m_CtxCache, SubCtx( Ctx::MultiRefLineIdx, m_CABACEstimator->getCtx() ) );
CHECK( !cu.firstPU, "CU has no PUs" );
......@@ -482,7 +484,9 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
#if !JVET_N0302_SIMPLFIED_CIIP
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
#endif
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
uint64_t fracModeBits = xFracModeBitsIntra(pu, uiMode, CHANNEL_TYPE_LUMA);
......@@ -555,7 +559,9 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
#if !JVET_N0302_SIMPLFIED_CIIP
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
#endif
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
uint64_t fracModeBits = xFracModeBitsIntra(pu, mode, CHANNEL_TYPE_LUMA);
......@@ -635,7 +641,9 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
// NB xFracModeBitsIntra will not affect the mode for chroma that may have already been pre-estimated.
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
#if !JVET_N0302_SIMPLFIED_CIIP
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
#endif
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
uint64_t fracModeBits = xFracModeBitsIntra(pu, mode, CHANNEL_TYPE_LUMA);
......@@ -792,7 +800,9 @@ void IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
//===== reset context models =====
m_CABACEstimator->getCtx() = SubCtx(Ctx::IntraLumaMpmFlag, ctxStartIntraMode);
#if !JVET_N0302_SIMPLFIED_CIIP
m_CABACEstimator->getCtx() = SubCtx( Ctx::MHIntraPredMode, ctxStartMHIntraMode );
#endif
m_CABACEstimator->getCtx() = SubCtx( Ctx::MultiRefLineIdx, ctxStartMrlIdx );
return;
......@@ -2684,9 +2694,13 @@ uint64_t IntraSearch::xFracModeBitsIntra(PredictionUnit &pu, const uint32_t &uiM
if( isLuma( chType ) )
{
#if !JVET_N0302_SIMPLFIED_CIIP
if ( pu.mhIntraFlag )
m_CABACEstimator->MHIntra_luma_pred_modes(*pu.cu);
else
#else
if (!pu.mhIntraFlag)
#endif
{
m_CABACEstimator->extend_ref_line(pu);
m_CABACEstimator->intra_luma_pred_mode(pu);
......
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