Commit 56f2bee0 authored by Xiang Li's avatar Xiang Li

Merge branch 'clean19' into 'master'

Cleanup weighted predition related code

See merge request !1803
parents e275b6f4 1a04b7dd
......@@ -517,12 +517,12 @@ void InterPrediction::xPredInterBi(PredictionUnit &pu, PelUnitBuf &pcYuvPred, co
const PPS &pps = *pu.cs->pps;
const Slice &slice = *pu.cs->slice;
CHECK( !pu.cu->affine && pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0 && ( pu.lwidth() + pu.lheight() == 12 ), "invalid 4x8/8x4 bi-predicted blocks" );
WPScalingParam *wp0;
WPScalingParam *wp1;
int refIdx0 = pu.refIdx[REF_PIC_LIST_0];
int refIdx1 = pu.refIdx[REF_PIC_LIST_1];
pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0, wp0);
pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1, wp1);
const WPScalingParam *wp0 = pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0);
const WPScalingParam *wp1 = pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1);
bool bioApplied = false;
if (pu.cs->sps->getBDOFEnabledFlag() && (!pu.cs->picHeader->getDisBdofFlag()))
......@@ -533,7 +533,8 @@ void InterPrediction::xPredInterBi(PredictionUnit &pu, PelUnitBuf &pcYuvPred, co
}
else
{
const bool biocheck0 = !((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag || wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag) && slice.getSliceType() == B_SLICE);
const bool biocheck0 =
!((WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1)) && slice.getSliceType() == B_SLICE);
const bool biocheck1 = !(pps.getUseWP() && slice.getSliceType() == P_SLICE);
if (biocheck0
&& biocheck1
......@@ -1496,12 +1497,12 @@ void InterPrediction::motionCompensation( PredictionUnit &pu, PelUnitBuf &predBu
{
CHECK( !pu.cu->affine && pu.refIdx[0] >= 0 && pu.refIdx[1] >= 0 && ( pu.lwidth() + pu.lheight() == 12 ), "invalid 4x8/8x4 bi-predicted blocks" );
WPScalingParam *wp0;
WPScalingParam *wp1;
int refIdx0 = pu.refIdx[REF_PIC_LIST_0];
int refIdx1 = pu.refIdx[REF_PIC_LIST_1];
pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0, wp0);
pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1, wp1);
const WPScalingParam *wp0 = pu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0);
const WPScalingParam *wp1 = pu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1);
bool bioApplied = false;
const Slice &slice = *pu.cs->slice;
if (pu.cs->sps->getBDOFEnabledFlag() && (!pu.cs->picHeader->getDisBdofFlag()))
......@@ -1513,7 +1514,8 @@ void InterPrediction::motionCompensation( PredictionUnit &pu, PelUnitBuf &predBu
}
else
{
const bool biocheck0 = !((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag || wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag) && slice.getSliceType() == B_SLICE);
const bool biocheck0 =
!((WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1)) && slice.getSliceType() == B_SLICE);
const bool biocheck1 = !(pps.getUseWP() && slice.getSliceType() == P_SLICE);
if (biocheck0
&& biocheck1
......
......@@ -2227,10 +2227,30 @@ void Slice::initWpAcDcParam()
}
//! get tables for weighted prediction
void Slice::getWpScaling( RefPicList e, int iRefIdx, WPScalingParam *&wp ) const
const WPScalingParam *Slice::getWpScaling(const RefPicList refPicList, const int refIdx) const
{
CHECK(e>=NUM_REF_PIC_LIST_01, "Invalid picture reference list");
wp = (WPScalingParam*) m_weightPredTable[e][iRefIdx];
CHECK(refPicList >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
if (refIdx < 0)
{
return nullptr;
}
else
{
return m_weightPredTable[refPicList][refIdx];
}
}
WPScalingParam *Slice::getWpScaling(const RefPicList refPicList, const int refIdx)
{
CHECK(refPicList >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
if (refIdx < 0)
{
return nullptr;
}
else
{
return m_weightPredTable[refPicList][refIdx];
}
}
//! reset Default WP tables settings : no weight.
......@@ -2243,11 +2263,11 @@ void Slice::resetWpScaling()
for ( int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
{
WPScalingParam *pwp = &(m_weightPredTable[e][i][yuv]);
pwp->bPresentFlag = false;
pwp->uiLog2WeightDenom = 0;
pwp->uiLog2WeightDenom = 0;
pwp->iWeight = 1;
pwp->iOffset = 0;
pwp->presentFlag = false;
pwp->log2WeightDenom = 0;
pwp->log2WeightDenom = 0;
pwp->codedWeight = 1;
pwp->codedOffset = 0;
}
}
}
......@@ -2264,19 +2284,20 @@ void Slice::initWpScaling(const SPS *sps)
for ( int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
{
WPScalingParam *pwp = &(m_weightPredTable[e][i][yuv]);
if ( !pwp->bPresentFlag )
if (!pwp->presentFlag)
{
// Inferring values not present :
pwp->iWeight = (1 << pwp->uiLog2WeightDenom);
pwp->iOffset = 0;
pwp->codedWeight = (1 << pwp->log2WeightDenom);
pwp->codedOffset = 0;
}
const int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : (1 << (sps->getBitDepth(toChannelType(ComponentID(yuv)))-8));
pwp->w = pwp->iWeight;
pwp->o = pwp->iOffset * offsetScalingFactor; //NOTE: This value of the ".o" variable is never used - .o is set immediately before it gets used
pwp->shift = pwp->uiLog2WeightDenom;
pwp->round = (pwp->uiLog2WeightDenom>=1) ? (1 << (pwp->uiLog2WeightDenom-1)) : (0);
pwp->w = pwp->codedWeight;
pwp->o = pwp->codedOffset * offsetScalingFactor; // NOTE: This value of the ".o" variable is never used - .o
// is set immediately before it gets used
pwp->shift = pwp->log2WeightDenom;
pwp->round = (pwp->log2WeightDenom >= 1) ? (1 << (pwp->log2WeightDenom - 1)) : (0);
}
}
}
......@@ -2749,10 +2770,30 @@ void PicHeader::initPicHeader()
m_alfApsId.resize(0);
}
void PicHeader::getWpScaling(RefPicList e, int iRefIdx, WPScalingParam *&wp) const
const WPScalingParam *PicHeader::getWpScaling(const RefPicList refPicList, const int refIdx) const
{
CHECK(e >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
wp = (WPScalingParam *) m_weightPredTable[e][iRefIdx];
CHECK(refPicList >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
if (refIdx < 0)
{
return nullptr;
}
else
{
return m_weightPredTable[refPicList][refIdx];
}
}
WPScalingParam *PicHeader::getWpScaling(const RefPicList refPicList, const int refIdx)
{
CHECK(refPicList >= NUM_REF_PIC_LIST_01, "Invalid picture reference list");
if (refIdx < 0)
{
return nullptr;
}
else
{
return m_weightPredTable[refPicList][refIdx];
}
}
void PicHeader::resetWpScaling()
......@@ -2764,10 +2805,10 @@ void PicHeader::resetWpScaling()
for ( int yuv=0 ; yuv<MAX_NUM_COMPONENT ; yuv++ )
{
WPScalingParam *pwp = &(m_weightPredTable[e][i][yuv]);
pwp->bPresentFlag = false;
pwp->uiLog2WeightDenom = 0;
pwp->iWeight = 1;
pwp->iOffset = 0;
pwp->presentFlag = false;
pwp->log2WeightDenom = 0;
pwp->codedWeight = 1;
pwp->codedOffset = 0;
}
}
}
......
......@@ -2325,10 +2325,10 @@ struct WPScalingParam
{
// Explicit weighted prediction parameters parsed in slice header,
// or Implicit weighted prediction parameters (8 bits depth values).
bool bPresentFlag;
uint32_t uiLog2WeightDenom;
int iWeight;
int iOffset;
bool presentFlag;
uint32_t log2WeightDenom;
int codedWeight;
int codedOffset;
// Weighted prediction scaling values built from above parameters (bitdepth scaled):
int w;
......@@ -2337,7 +2337,14 @@ struct WPScalingParam
int shift;
int round;
static bool isWeighted(const WPScalingParam *wp);
};
inline bool WPScalingParam::isWeighted(const WPScalingParam *wp)
{
return wp != nullptr && (wp[COMPONENT_Y].presentFlag || wp[COMPONENT_Cb].presentFlag || wp[COMPONENT_Cr].presentFlag);
}
struct WPACDCParam
{
int64_t iAC;
......@@ -2605,7 +2612,8 @@ public:
{
memcpy(m_weightPredTable, wp, sizeof(WPScalingParam) * NUM_REF_PIC_LIST_01 * MAX_NUM_REF * MAX_NUM_COMPONENT);
}
void getWpScaling(RefPicList e, int iRefIdx, WPScalingParam *&wp) const;
const WPScalingParam * getWpScaling(const RefPicList refPicList, const int refIdx) const;
WPScalingParam * getWpScaling(const RefPicList refPicList, const int refIdx);
WPScalingParam* getWpScalingAll() { return (WPScalingParam *) m_weightPredTable; }
void resetWpScaling();
void setNumL0Weights(int b) { m_numL0Weights = b; }
......@@ -2975,7 +2983,8 @@ public:
memcpy(m_weightPredTable, wp, sizeof(WPScalingParam) * NUM_REF_PIC_LIST_01 * MAX_NUM_REF * MAX_NUM_COMPONENT);
}
WPScalingParam * getWpScalingAll() { return (WPScalingParam *) m_weightPredTable; }
void getWpScaling( RefPicList e, int iRefIdx, WPScalingParam *&wp) const;
WPScalingParam * getWpScaling(const RefPicList refPicList, const int refIdx);
const WPScalingParam * getWpScaling(const RefPicList refPicList, const int refIdx) const;
void resetWpScaling();
void initWpScaling(const SPS *sps);
......
......@@ -1403,29 +1403,23 @@ void PU::getInterMergeCandidates( const PredictionUnit &pu, MergeCtx& mrgCtx,
bool PU::checkDMVRCondition(const PredictionUnit& pu)
{
WPScalingParam *wp0;
WPScalingParam *wp1;
int refIdx0 = pu.refIdx[REF_PIC_LIST_0];
int refIdx1 = pu.refIdx[REF_PIC_LIST_1];
pu.cu->slice->getWpScaling(REF_PIC_LIST_0, refIdx0, wp0);
pu.cu->slice->getWpScaling(REF_PIC_LIST_1, refIdx1, wp1);
if (pu.cs->sps->getUseDMVR() && (!pu.cs->picHeader->getDisDmvrFlag()))
{
return pu.mergeFlag
&& pu.mergeType == MRG_TYPE_DEFAULT_N
&& !pu.ciipFlag
&& !pu.cu->affine
&& !pu.mmvdMergeFlag
&& !pu.cu->mmvdSkip
&& PU::isBiPredFromDifferentDirEqDistPoc(pu)
&& (pu.lheight() >= 8)
&& (pu.lwidth() >= 8)
&& ((pu.lheight() * pu.lwidth()) >= 128)
&& (pu.cu->BcwIdx == BCW_DEFAULT)
&& ((!wp0[COMPONENT_Y].bPresentFlag) && (!wp0[COMPONENT_Cb].bPresentFlag) && (!wp0[COMPONENT_Cr].bPresentFlag) && (!wp1[COMPONENT_Y].bPresentFlag) && (!wp1[COMPONENT_Cb].bPresentFlag) && (!wp1[COMPONENT_Cr].bPresentFlag))
&& ( refIdx0 < 0 ? true : (pu.cu->slice->getRefPic( REF_PIC_LIST_0, refIdx0 )->isRefScaled( pu.cs->pps ) == false) )
&& ( refIdx1 < 0 ? true : (pu.cu->slice->getRefPic( REF_PIC_LIST_1, refIdx1 )->isRefScaled( pu.cs->pps ) == false) )
;
if (pu.cs->sps->getUseDMVR() && !pu.cs->picHeader->getDisDmvrFlag())
{
const int refIdx0 = pu.refIdx[REF_PIC_LIST_0];
const int refIdx1 = pu.refIdx[REF_PIC_LIST_1];
const WPScalingParam *wp0 = pu.cu->slice->getWpScaling(REF_PIC_LIST_0, refIdx0);
const WPScalingParam *wp1 = pu.cu->slice->getWpScaling(REF_PIC_LIST_1, refIdx1);
const bool ref0IsScaled =
refIdx0 < 0 ? false : pu.cu->slice->getRefPic(REF_PIC_LIST_0, refIdx0)->isRefScaled(pu.cs->pps);
const bool ref1IsScaled =
refIdx1 < 0 ? false : pu.cu->slice->getRefPic(REF_PIC_LIST_1, refIdx1)->isRefScaled(pu.cs->pps);
return pu.mergeFlag && pu.mergeType == MRG_TYPE_DEFAULT_N && !pu.ciipFlag && !pu.cu->affine && !pu.mmvdMergeFlag
&& !pu.cu->mmvdSkip && PU::isBiPredFromDifferentDirEqDistPoc(pu) && (pu.lheight() >= 8) && (pu.lwidth() >= 8)
&& ((pu.lheight() * pu.lwidth()) >= 128) && (pu.cu->BcwIdx == BCW_DEFAULT)
&& !WPScalingParam::isWeighted(wp0) && !WPScalingParam::isWeighted(wp1) && !ref0IsScaled && !ref1IsScaled;
}
else
{
......@@ -3733,19 +3727,13 @@ bool CU::isBcwIdxCoded( const CodingUnit &cu )
{
if( cu.firstPU->interDir == 3 )
{
WPScalingParam *wp0;
WPScalingParam *wp1;
int refIdx0 = cu.firstPU->refIdx[REF_PIC_LIST_0];
int refIdx1 = cu.firstPU->refIdx[REF_PIC_LIST_1];
const int refIdx0 = cu.firstPU->refIdx[REF_PIC_LIST_0];
const int refIdx1 = cu.firstPU->refIdx[REF_PIC_LIST_1];
cu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0, wp0);
cu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1, wp1);
if ((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag
|| wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag))
{
return false;
}
return true;
const WPScalingParam *wp0 = cu.cs->slice->getWpScaling(REF_PIC_LIST_0, refIdx0);
const WPScalingParam *wp1 = cu.cs->slice->getWpScaling(REF_PIC_LIST_1, refIdx1);
return !(WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1));
}
}
......
......@@ -72,14 +72,8 @@ WeightPrediction::WeightPrediction()
{
}
void WeightPrediction::getWpScaling(const Slice *pcSlice,
const int &iRefIdx0,
const int &iRefIdx1,
WPScalingParam *&wp0,
WPScalingParam *&wp1,
const ComponentID maxNumComp)
void WeightPrediction::getWpScaling(Slice *pcSlice, const int &iRefIdx0, const int &iRefIdx1, WPScalingParam *&wp0,
WPScalingParam *&wp1, const ComponentID maxNumComp)
{
CHECK(iRefIdx0 < 0 && iRefIdx1 < 0, "Both picture reference list indizes smaller than '0'");
......@@ -90,14 +84,8 @@ void WeightPrediction::getWpScaling(const Slice *pcSlice,
if (bUniPred || wpBiPred)
{
// explicit --------------------
if (iRefIdx0 >= 0)
{
pcSlice->getWpScaling(REF_PIC_LIST_0, iRefIdx0, wp0);
}
if (iRefIdx1 >= 0)
{
pcSlice->getWpScaling(REF_PIC_LIST_1, iRefIdx1, wp1);
}
wp0 = pcSlice->getWpScaling(REF_PIC_LIST_0, iRefIdx0);
wp1 = pcSlice->getWpScaling(REF_PIC_LIST_1, iRefIdx1);
}
else
{
......@@ -106,11 +94,11 @@ void WeightPrediction::getWpScaling(const Slice *pcSlice,
if (iRefIdx0 < 0)
{
wp0 = NULL;
wp0 = nullptr;
}
if (iRefIdx1 < 0)
{
wp1 = NULL;
wp1 = nullptr;
}
const uint32_t numValidComponent = getNumberValidComponents(pcSlice->getSPS()->getChromaFormatIdc());
......@@ -124,13 +112,13 @@ void WeightPrediction::getWpScaling(const Slice *pcSlice,
const int bitDepth = pcSlice->getSPS()->getBitDepth(toChannelType(ComponentID(yuv)));
const int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : (1 << (bitDepth - 8));
wp0[yuv].w = wp0[yuv].iWeight;
wp1[yuv].w = wp1[yuv].iWeight;
wp0[yuv].o = wp0[yuv].iOffset * offsetScalingFactor;
wp1[yuv].o = wp1[yuv].iOffset * offsetScalingFactor;
wp0[yuv].w = wp0[yuv].codedWeight;
wp1[yuv].w = wp1[yuv].codedWeight;
wp0[yuv].o = wp0[yuv].codedOffset * offsetScalingFactor;
wp1[yuv].o = wp1[yuv].codedOffset * offsetScalingFactor;
wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o;
wp0[yuv].shift = wp0[yuv].uiLog2WeightDenom + 1;
wp0[yuv].round = (1 << wp0[yuv].uiLog2WeightDenom);
wp0[yuv].shift = wp0[yuv].log2WeightDenom + 1;
wp0[yuv].round = (1 << wp0[yuv].log2WeightDenom);
wp1[yuv].offset = wp0[yuv].offset;
wp1[yuv].shift = wp0[yuv].shift;
wp1[yuv].round = wp0[yuv].round;
......@@ -146,10 +134,10 @@ void WeightPrediction::getWpScaling(const Slice *pcSlice,
const int bitDepth = pcSlice->getSPS()->getBitDepth(toChannelType(ComponentID(yuv)));
const int offsetScalingFactor = bUseHighPrecisionPredictionWeighting ? 1 : (1 << (bitDepth - 8));
pwp[yuv].w = pwp[yuv].iWeight;
pwp[yuv].offset = pwp[yuv].iOffset * offsetScalingFactor;
pwp[yuv].shift = pwp[yuv].uiLog2WeightDenom;
pwp[yuv].round = (pwp[yuv].uiLog2WeightDenom >= 1) ? (1 << (pwp[yuv].uiLog2WeightDenom - 1)) : (0);
pwp[yuv].w = pwp[yuv].codedWeight;
pwp[yuv].offset = pwp[yuv].codedOffset * offsetScalingFactor;
pwp[yuv].shift = pwp[yuv].log2WeightDenom;
pwp[yuv].round = (pwp[yuv].log2WeightDenom >= 1) ? (1 << (pwp[yuv].log2WeightDenom - 1)) : (0);
}
}
}
......
......@@ -55,12 +55,8 @@ class WeightPrediction
public:
WeightPrediction();
void getWpScaling( const Slice *slice,
const int &iRefIdx0,
const int &iRefIdx1,
WPScalingParam *&wp0,
WPScalingParam *&wp1,
const ComponentID maxNumComp = MAX_NUM_COMPONENT );
void getWpScaling(Slice *slice, const int &iRefIdx0, const int &iRefIdx1, WPScalingParam *&wp0, WPScalingParam *&wp1,
const ComponentID maxNumComp = MAX_NUM_COMPONENT);
void addWeightBi( const CPelUnitBuf &pcYuvSrc0,
const CPelUnitBuf &pcYuvSrc1,
......
This diff is collapsed.
......@@ -2832,10 +2832,9 @@ void InterSearch::predInterSearch(CodingUnit& cu, Partitioner& partitioner)
{
CHECK(iRefIdxBi[0]<0, "Invalid picture reference index");
CHECK(iRefIdxBi[1]<0, "Invalid picture reference index");
cu.cs->slice->getWpScaling(REF_PIC_LIST_0, iRefIdxBi[0], wp0);
cu.cs->slice->getWpScaling(REF_PIC_LIST_1, iRefIdxBi[1], wp1);
if ((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag
|| wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag))
wp0 = cu.cs->slice->getWpScaling(REF_PIC_LIST_0, iRefIdxBi[0]);
wp1 = cu.cs->slice->getWpScaling(REF_PIC_LIST_1, iRefIdxBi[1]);
if (WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1))
{
uiCostBi = MAX_UINT;
enforceBcwPred = false;
......@@ -5125,10 +5124,10 @@ void InterSearch::xPredAffineInterSearch( PredictionUnit& pu,
{
CHECK(iRefIdxBi[0]<0, "Invalid picture reference index");
CHECK(iRefIdxBi[1]<0, "Invalid picture reference index");
pu.cs->slice->getWpScaling(REF_PIC_LIST_0, iRefIdxBi[0], wp0);
pu.cs->slice->getWpScaling(REF_PIC_LIST_1, iRefIdxBi[1], wp1);
if ((wp0[COMPONENT_Y].bPresentFlag || wp0[COMPONENT_Cb].bPresentFlag || wp0[COMPONENT_Cr].bPresentFlag
|| wp1[COMPONENT_Y].bPresentFlag || wp1[COMPONENT_Cb].bPresentFlag || wp1[COMPONENT_Cr].bPresentFlag))
wp0 = pu.cs->slice->getWpScaling(REF_PIC_LIST_0, iRefIdxBi[0]);
wp1 = pu.cs->slice->getWpScaling(REF_PIC_LIST_1, iRefIdxBi[1]);
if (WPScalingParam::isWeighted(wp0) || WPScalingParam::isWeighted(wp1))
{
uiCostBi = MAX_UINT;
enforceBcwPred = false;
......
......@@ -2843,61 +2843,65 @@ void HLSWriter::xCodePredWeightTable( Slice* pcSlice )
{
RefPicList eRefPicList = ( iNumRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
// NOTE: wp[].uiLog2WeightDenom and wp[].bPresentFlag are actually per-channel-type settings.
// NOTE: wp[].log2WeightDenom and wp[].presentFlag are actually per-channel-type settings.
for ( int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
{
pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
wp = pcSlice->getWpScaling(eRefPicList, iRefIdx);
if ( !bDenomCoded )
{
int iDeltaDenom;
WRITE_UVLC( wp[COMPONENT_Y].uiLog2WeightDenom, "luma_log2_weight_denom" );
WRITE_UVLC(wp[COMPONENT_Y].log2WeightDenom, "luma_log2_weight_denom");
if( bChroma )
{
CHECK( wp[COMPONENT_Cb].uiLog2WeightDenom != wp[COMPONENT_Cr].uiLog2WeightDenom, "Chroma blocks of different size not supported" );
iDeltaDenom = (wp[COMPONENT_Cb].uiLog2WeightDenom - wp[COMPONENT_Y].uiLog2WeightDenom);
CHECK(wp[COMPONENT_Cb].log2WeightDenom != wp[COMPONENT_Cr].log2WeightDenom,
"Chroma blocks of different size not supported");
iDeltaDenom = (wp[COMPONENT_Cb].log2WeightDenom - wp[COMPONENT_Y].log2WeightDenom);
WRITE_SVLC( iDeltaDenom, "delta_chroma_log2_weight_denom" );
}
bDenomCoded = true;
}
WRITE_FLAG( wp[COMPONENT_Y].bPresentFlag, iNumRef==0?"luma_weight_l0_flag[i]":"luma_weight_l1_flag[i]" );
uiTotalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
WRITE_FLAG(wp[COMPONENT_Y].presentFlag, iNumRef == 0 ? "luma_weight_l0_flag[i]" : "luma_weight_l1_flag[i]");
uiTotalSignalledWeightFlags += wp[COMPONENT_Y].presentFlag;
}
if (bChroma)
{
for ( int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
{
pcSlice->getWpScaling( eRefPicList, iRefIdx, wp );
CHECK( wp[COMPONENT_Cb].bPresentFlag != wp[COMPONENT_Cr].bPresentFlag, "Inconsistent settings for chroma channels" );
WRITE_FLAG( wp[COMPONENT_Cb].bPresentFlag, iNumRef==0?"chroma_weight_l0_flag[i]":"chroma_weight_l1_flag[i]" );
uiTotalSignalledWeightFlags += 2*wp[COMPONENT_Cb].bPresentFlag;
wp = pcSlice->getWpScaling(eRefPicList, iRefIdx);
CHECK(wp[COMPONENT_Cb].presentFlag != wp[COMPONENT_Cr].presentFlag,
"Inconsistent settings for chroma channels");
WRITE_FLAG(wp[COMPONENT_Cb].presentFlag,
iNumRef == 0 ? "chroma_weight_l0_flag[i]" : "chroma_weight_l1_flag[i]");
uiTotalSignalledWeightFlags += 2 * wp[COMPONENT_Cb].presentFlag;
}
}
for ( int iRefIdx=0 ; iRefIdx<pcSlice->getNumRefIdx(eRefPicList) ; iRefIdx++ )
{
pcSlice->getWpScaling(eRefPicList, iRefIdx, wp);
if ( wp[COMPONENT_Y].bPresentFlag )
wp = pcSlice->getWpScaling(eRefPicList, iRefIdx);
if (wp[COMPONENT_Y].presentFlag)
{
int iDeltaWeight = (wp[COMPONENT_Y].iWeight - (1<<wp[COMPONENT_Y].uiLog2WeightDenom));
int iDeltaWeight = (wp[COMPONENT_Y].codedWeight - (1 << wp[COMPONENT_Y].log2WeightDenom));
WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_luma_weight_l0[i]":"delta_luma_weight_l1[i]" );
WRITE_SVLC( wp[COMPONENT_Y].iOffset, iNumRef==0?"luma_offset_l0[i]":"luma_offset_l1[i]" );
WRITE_SVLC(wp[COMPONENT_Y].codedOffset, iNumRef == 0 ? "luma_offset_l0[i]" : "luma_offset_l1[i]");
}
if ( bChroma )
{
if ( wp[COMPONENT_Cb].bPresentFlag )
if (wp[COMPONENT_Cb].presentFlag)
{
for ( int j = COMPONENT_Cb ; j < numberValidComponents ; j++ )
{
CHECK(wp[COMPONENT_Cb].uiLog2WeightDenom != wp[COMPONENT_Cr].uiLog2WeightDenom, "Chroma blocks of different size not supported");
int iDeltaWeight = (wp[j].iWeight - (1<<wp[COMPONENT_Cb].uiLog2WeightDenom));
CHECK(wp[COMPONENT_Cb].log2WeightDenom != wp[COMPONENT_Cr].log2WeightDenom,
"Chroma blocks of different size not supported");
int iDeltaWeight = (wp[j].codedWeight - (1 << wp[COMPONENT_Cb].log2WeightDenom));
WRITE_SVLC( iDeltaWeight, iNumRef==0?"delta_chroma_weight_l0[i]":"delta_chroma_weight_l1[i]" );
int range=pcSlice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag() ? (1<<pcSlice->getSPS()->getBitDepth(CHANNEL_TYPE_CHROMA))/2 : 128;
int pred = ( range - ( ( range*wp[j].iWeight)>>(wp[j].uiLog2WeightDenom) ) );
int iDeltaChroma = (wp[j].iOffset - pred);
int pred = (range - ((range * wp[j].codedWeight) >> (wp[j].log2WeightDenom)));
int iDeltaChroma = (wp[j].codedOffset - pred);
WRITE_SVLC( iDeltaChroma, iNumRef==0?"delta_chroma_offset_l0[i]":"delta_chroma_offset_l1[i]" );
}
}
......@@ -2922,61 +2926,64 @@ void HLSWriter::xCodePredWeightTable(PicHeader *picHeader, const SPS *sps)
for (int numRef = 0; numRef < NUM_REF_PIC_LIST_01 && moreSyntaxToBeParsed; numRef++) // loop over l0 and l1 syntax elements
{
RefPicList refPicList = (numRef ? REF_PIC_LIST_1 : REF_PIC_LIST_0);
// NOTE: wp[].uiLog2WeightDenom and wp[].bPresentFlag are actually per-channel-type settings.
// NOTE: wp[].log2WeightDenom and wp[].presentFlag are actually per-channel-type settings.
for (int refIdx = 0; refIdx < numLxWeights; refIdx++)
{
picHeader->getWpScaling(refPicList, refIdx, wp);
wp = picHeader->getWpScaling(refPicList, refIdx);
if (!denomCoded)
{
int deltaDenom;
WRITE_UVLC(wp[COMPONENT_Y].uiLog2WeightDenom, "luma_log2_weight_denom");
WRITE_UVLC(wp[COMPONENT_Y].log2WeightDenom, "luma_log2_weight_denom");
if (chroma)
{
CHECK(wp[COMPONENT_Cb].uiLog2WeightDenom != wp[COMPONENT_Cr].uiLog2WeightDenom, "Chroma blocks of different size not supported");
deltaDenom = (wp[COMPONENT_Cb].uiLog2WeightDenom - wp[COMPONENT_Y].uiLog2WeightDenom);
CHECK(wp[COMPONENT_Cb].log2WeightDenom != wp[COMPONENT_Cr].log2WeightDenom,
"Chroma blocks of different size not supported");
deltaDenom = (wp[COMPONENT_Cb].log2WeightDenom - wp[COMPONENT_Y].log2WeightDenom);
WRITE_SVLC(deltaDenom, "delta_chroma_log2_weight_denom");
}
denomCoded = true;
}
WRITE_FLAG(wp[COMPONENT_Y].bPresentFlag, numRef == 0 ? "luma_weight_l0_flag[i]" : "luma_weight_l1_flag[i]");
totalSignalledWeightFlags += wp[COMPONENT_Y].bPresentFlag;
WRITE_FLAG(wp[COMPONENT_Y].presentFlag, numRef == 0 ? "luma_weight_l0_flag[i]" : "luma_weight_l1_flag[i]");
totalSignalledWeightFlags += wp[COMPONENT_Y].presentFlag;
}
if (chroma)
{
for (int refIdx = 0; refIdx < numLxWeights; refIdx++)
{
picHeader->getWpScaling(refPicList, refIdx, wp);
CHECK(wp[COMPONENT_Cb].bPresentFlag != wp[COMPONENT_Cr].bPresentFlag, "Inconsistent settings for chroma channels");
WRITE_FLAG(wp[COMPONENT_Cb].bPresentFlag, numRef == 0 ? "chroma_weight_l0_flag[i]" : "chroma_weight_l1_flag[i]");
totalSignalledWeightFlags += 2 * wp[COMPONENT_Cb].bPresentFlag;
wp = picHeader->getWpScaling(refPicList, refIdx);
CHECK(wp[COMPONENT_Cb].presentFlag != wp[COMPONENT_Cr].presentFlag,
"Inconsistent settings for chroma channels");
WRITE_FLAG(wp[COMPONENT_Cb].presentFlag, numRef == 0 ? "chroma_weight_l0_flag[i]" : "chroma_weight_l1_flag[i]");
totalSignalledWeightFlags += 2 * wp[COMPONENT_Cb].presentFlag;
}
}
for (int refIdx = 0; refIdx < numLxWeights; refIdx++)
{
picHeader->getWpScaling(refPicList, refIdx, wp);
if (wp[COMPONENT_Y].bPresentFlag)
wp = picHeader->getWpScaling(refPicList, refIdx);
if (wp[COMPONENT_Y].presentFlag)
{
int deltaWeight = (wp[COMPONENT_Y].iWeight - (1 << wp[COMPONENT_Y].uiLog2WeightDenom));
int deltaWeight = (wp[COMPONENT_Y].codedWeight - (1 << wp[COMPONENT_Y].log2WeightDenom));
WRITE_SVLC(deltaWeight, numRef == 0 ? "delta_luma_weight_l0[i]" : "delta_luma_weight_l1[i]");
WRITE_SVLC(wp[COMPONENT_Y].iOffset, numRef == 0 ? "luma_offset_l0[i]" : "luma_offset_l1[i]");
WRITE_SVLC(wp[COMPONENT_Y].codedOffset, numRef == 0 ? "luma_offset_l0[i]" : "luma_offset_l1[i]");
}
if (chroma)
{
if (wp[COMPONENT_Cb].bPresentFlag)
if (wp[COMPONENT_Cb].presentFlag)
{
for (int j = COMPONENT_Cb; j < numberValidComponents; j++)
{
CHECK(wp[COMPONENT_Cb].uiLog2WeightDenom != wp[COMPONENT_Cr].uiLog2WeightDenom, "Chroma blocks of different size not supported");