Commit 6252b387 authored by Frank Bossen's avatar Frank Bossen

Merge branch 'master' into 'JVET-O0655-422-chroma-DM-mapping'

# Conflicts:
#   source/Lib/CommonLib/TypeDef.h
parents ec415a80 ca678b5b
......@@ -453,6 +453,10 @@ static const int PIC_ANALYZE_CW_BINS = 32;
static const int PIC_CODE_CW_BINS = 16;
static const int FP_PREC = 11;
static const int CSCALE_FP_PREC = 11;
#if JVET_O1109_UNFIY_CRS
static const int NEIG_NUM_LOG = 6;
static const int NEIG_NUM = 1 << NEIG_NUM_LOG;
#endif
// ====================================================================================================================
// Macro functions
// ====================================================================================================================
......
......@@ -38,6 +38,9 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#if JVET_O1109_UNFIY_CRS
#include <UnitTools.h>
#endif
//! \ingroup CommonLib
//! \{
......@@ -50,6 +53,9 @@ Reshape::Reshape()
m_CTUFlag = false;
m_recReshaped = false;
m_reshape = true;
#if JVET_O1109_UNFIY_CRS
m_chromaScale = (1 << CSCALE_FP_PREC);
#endif
}
Reshape::~Reshape()
......@@ -128,7 +134,94 @@ int Reshape::calculateChromaAdj(Pel avgLuma)
return(iAdj);
}
#if JVET_O1109_UNFIY_CRS
/** compute chroma residuce scale for TU
* \param average luma pred of TU
* \return chroma residue scale
*/
int Reshape::calculateChromaAdjVpduNei(TransformUnit &tu, const CompArea &areaY)
{
CodingStructure &cs = *tu.cs;
int xPos = areaY.lumaPos().x;
int yPos = areaY.lumaPos().y;
int ctuSize = cs.sps->getCTUSize();
if (ctuSize == 128)
{
xPos = xPos / 64 * 64;
yPos = yPos / 64 * 64;
}
else
{
xPos = xPos / ctuSize * ctuSize;
yPos = yPos / ctuSize * ctuSize;
}
if (isVPDUprocessed(xPos, yPos) && !cs.pcv->isEncoder)
{
return getChromaScale();
}
else
{
setVPDULoc(xPos, yPos);
Position topLeft(xPos, yPos);
CodingUnit *topLeftLuma;
if (CS::isDualITree(cs) && cs.slice->getSliceType() == I_SLICE)
topLeftLuma = tu.cs->picture->cs->getCU(topLeft, CHANNEL_TYPE_LUMA);
else
topLeftLuma = cs.getCU(topLeft, CHANNEL_TYPE_LUMA);
xPos = topLeftLuma->lumaPos().x;
yPos = topLeftLuma->lumaPos().y;
CompArea lumaArea = CompArea(COMPONENT_Y, tu.chromaFormat, topLeftLuma->lumaPos(), topLeftLuma->lumaSize(), true);
PelBuf piRecoY = cs.picture->getRecoBuf(lumaArea);
int strideY = piRecoY.stride;
int chromaScale = (1 << CSCALE_FP_PREC);
int lumaValue = -1;
Pel* recSrc0 = piRecoY.bufAt(0, 0);
const uint32_t picH = tu.cs->picture->lheight();
const uint32_t picW = tu.cs->picture->lwidth();
const Pel valueDC = 1 << (tu.cs->sps->getBitDepth(CHANNEL_TYPE_LUMA) - 1);
int32_t recLuma = 0;
int pelnum = 0;
if (xPos > 0)
{
for (int i = 0; i < NEIG_NUM; i++)
{
int k = (yPos + i) >= picH ? (picH - yPos - 1) : i;
recLuma += recSrc0[-1 + k * strideY];
pelnum++;
}
}
if (yPos > 0)
{
for (int i = 0; i < NEIG_NUM; i++)
{
int k = (xPos + i) >= picW ? (picW - xPos - 1) : i;
recLuma += recSrc0[-strideY + k];
pelnum++;
}
}
if (pelnum == NEIG_NUM)
{
lumaValue = ClipPel((recLuma + (1 << (NEIG_NUM_LOG - 1))) >> NEIG_NUM_LOG, tu.cs->slice->clpRng(COMPONENT_Y));
}
else if (pelnum == (NEIG_NUM << 1))
{
lumaValue = ClipPel((recLuma + (1 << NEIG_NUM_LOG)) >> (NEIG_NUM_LOG + 1), tu.cs->slice->clpRng(COMPONENT_Y));
}
else
{
CHECK(pelnum != 0, "");
lumaValue = ClipPel(valueDC, tu.cs->slice->clpRng(COMPONENT_Y));
}
chromaScale = calculateChromaAdj(lumaValue);
setChromaScale(chromaScale);
return(chromaScale);
}
}
#endif
/** find inx of PWL for inverse mapping
* \param average luma pred of TU
* \return idx of PWL for inverse mapping
......
......@@ -66,6 +66,11 @@ protected:
std::vector<Pel> m_reshapePivot;
int m_lumaBD;
int m_reshapeLUTSize;
#if JVET_O1109_UNFIY_CRS
int m_chromaScale;
int m_vpduX;
int m_vpduY;
#endif
public:
Reshape();
#if ENABLE_SPLIT_PARALLELISM
......@@ -96,6 +101,13 @@ public:
void updateChromaScaleLUT();
bool getReshapeFlag() { return m_reshape; }
void setReshapeFlag(bool b) { m_reshape = b; }
#if JVET_O1109_UNFIY_CRS
int calculateChromaAdjVpduNei(TransformUnit &tu, const CompArea &areaY);
void setVPDULoc(int x, int y) { m_vpduX = x, m_vpduY = y; }
bool isVPDUprocessed(int x, int y) { return ((x == m_vpduX) && (y == m_vpduY)); }
void setChromaScale (int chromaScale) { m_chromaScale = chromaScale; }
int getChromaScale() { return m_chromaScale; }
#endif
};// END CLASS DEFINITION Reshape
//! \}
......
......@@ -52,6 +52,8 @@
#define JVET_O0655_422_CHROMA_DM_MAPPING_FIX 1 // JVET-O0655: modify chroma DM derivation table for 4:2:2 chroma format
#define JVET_O1109_UNFIY_CRS 1 // JVET-O1109: Unified CRS derivation
#define JVET_O0590_REDUCE_DMVR_ORIG_MV_COST 1 // Reduce the DMVR cost of the original MV
#define JVET_O0429_CRS_LAMBDA_FIX 1 // JVET-O0429: fix encoder lambda rounding used in CRS
......
......@@ -211,10 +211,14 @@ void DecCu::xIntraRecBlk( TransformUnit& tu, const ComponentID compID )
{
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);
#if JVET_O1109_UNFIY_CRS
int adj = m_pcReshape->calculateChromaAdjVpduNei(tu, areaY);
#else
PelBuf piPredY;
piPredY = cs.picture->getPredBuf(areaY);
const Pel avgLuma = piPredY.computeAvg();
int adj = m_pcReshape->calculateChromaAdj(avgLuma);
#endif
tu.setChromaAdj(adj);
}
//===== inverse transform =====
......@@ -588,6 +592,9 @@ void DecCu::xDecodeInterTexture(CodingUnit &cu)
if (slice.getLmcsEnabledFlag() && m_pcReshape->getCTUFlag() && slice.getLmcsChromaResidualScaleFlag() && (compID == COMPONENT_Y) && (currTU.cbf[COMPONENT_Cb] || currTU.cbf[COMPONENT_Cr]))
{
const CompArea &areaY = currTU.blocks[COMPONENT_Y];
#if JVET_O1109_UNFIY_CRS
int adj = m_pcReshape->calculateChromaAdjVpduNei(currTU, areaY);
#else
PelBuf predY = cs.getPredBuf(areaY);
CompArea tmpArea(COMPONENT_Y, areaY.chromaFormat, Position(0, 0), areaY.size());
PelBuf tmpPred = m_tmpStorageLCU->getBuf(tmpArea);
......@@ -596,6 +603,7 @@ void DecCu::xDecodeInterTexture(CodingUnit &cu)
tmpPred.rspSignal(m_pcReshape->getFwdLUT());
const Pel avgLuma = tmpPred.computeAvg();
int adj = m_pcReshape->calculateChromaAdj(avgLuma);
#endif
currTU.setChromaAdj(adj);
}
xDecodeInterTU( currTU, compID );
......
......@@ -1363,6 +1363,9 @@ bool DecLib::xDecodeSlice(InputNALUnit &nalu, int &iSkipFrame, int iPOCLastDispl
m_cReshaper.setRecReshaped(false);
}
}
#if JVET_O1109_UNFIY_CRS
m_cReshaper.setVPDULoc(-1, -1);
#endif
}
else
{
......
......@@ -2165,15 +2165,19 @@ void HLSyntaxReader::parseSliceHeader (Slice* pcSlice, ParameterSetManager *para
READ_CODE(5, uiCode, "slice_lmcs_aps_id");
pcSlice->setLmcsAPSId(uiCode);
#if !JVET_O1109_UNFIY_CRS
if (!(sps->getUseDualITree() && pcSlice->isIntra()))
{
#endif
READ_FLAG(uiCode, "slice_chroma_residual_scale_flag");
pcSlice->setLmcsChromaResidualScaleFlag(uiCode == 1);
#if !JVET_O1109_UNFIY_CRS
}
else
{
pcSlice->setLmcsChromaResidualScaleFlag(false);
}
#endif
}
}
......
......@@ -113,8 +113,11 @@ void EncReshape::preAnalyzerHDR(Picture *pcPic, const SliceType sliceType, const
m_sliceReshapeInfo.sliceReshaperEnableFlag = true;
if (sliceType == I_SLICE ) { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true; }
else { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = false; }
#if !JVET_O1109_UNFIY_CRS
if (sliceType == I_SLICE && isDualT) { m_sliceReshapeInfo.enableChromaAdj = 0; }
else { m_sliceReshapeInfo.enableChromaAdj = 1; }
else
#endif
{ m_sliceReshapeInfo.enableChromaAdj = 1; }
}
else
{
......@@ -452,10 +455,12 @@ void EncReshape::preAnalyzerSDR(Picture *pcPic, const SliceType sliceType, const
}
m_chromaAdj = m_sliceReshapeInfo.enableChromaAdj;
#if !JVET_O1109_UNFIY_CRS
if (sliceType == I_SLICE && isDualT)
{
m_sliceReshapeInfo.enableChromaAdj = 0;
}
#endif
}
else // Inter slices
{
......
......@@ -6269,6 +6269,9 @@ void InterSearch::xEstimateInterResidualQT(CodingStructure &cs, Partitioner &par
if (slice.getLmcsEnabledFlag() && m_pcReshape->getCTUFlag() && slice.getLmcsChromaResidualScaleFlag())
{
const CompArea &areaY = tu.blocks[COMPONENT_Y];
#if JVET_O1109_UNFIY_CRS
int adj = m_pcReshape->calculateChromaAdjVpduNei(tu, areaY);
#else
PelBuf piPredY = cs.getPredBuf(areaY);
CompArea tmpArea(COMPONENT_Y, areaY.chromaFormat, Position(0, 0), areaY.size());
PelBuf tmpPred = m_tmpStorageLCU.getBuf(tmpArea);
......@@ -6277,6 +6280,7 @@ void InterSearch::xEstimateInterResidualQT(CodingStructure &cs, Partitioner &par
tmpPred.rspSignal(m_pcReshape->getFwdLUT());
const Pel avgLuma = tmpPred.computeAvg();
int adj = m_pcReshape->calculateChromaAdj(avgLuma);
#endif
tu.setChromaAdj(adj);
}
......
......@@ -1842,10 +1842,14 @@ void IntraSearch::xIntraCodingTUBlock(TransformUnit &tu, const ComponentID &comp
{
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 );
#if JVET_O1109_UNFIY_CRS
int adj = m_pcReshape->calculateChromaAdjVpduNei(tu, areaY);
#else
PelBuf piPredY;
piPredY = cs.picture->getPredBuf(areaY);
const Pel avgLuma = piPredY.computeAvg();
int adj = m_pcReshape->calculateChromaAdj(avgLuma);
#endif
tu.setChromaAdj(adj);
}
//===== get residual signal =====
......
......@@ -1500,7 +1500,9 @@ void HLSWriter::codeSliceHeader ( Slice* pcSlice )
if (pcSlice->getLmcsEnabledFlag())
{
WRITE_CODE(pcSlice->getLmcsAPSId(), 5, "slice_lmcs_aps_id");
#if !JVET_O1109_UNFIY_CRS
if (!(pcSlice->getSPS()->getUseDualITree() && pcSlice->isIntra()))
#endif
WRITE_FLAG(pcSlice->getLmcsChromaResidualScaleFlag(), "slice_chroma_residual_scale_flag");
}
}
......
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