Commit 058998c8 authored by Taoran Lu's avatar Taoran Lu

address discussion points and rebase

parent 442a0444
......@@ -708,6 +708,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
int warnUnknowParameter = 0;
#if JVET_M0427_INLOOP_RESHAPER
const int CW_NUMS = 3;
const uint32_t defaultBinCW[CW_NUMS - 1] = { 38, 28 };
const uint32_t defaultBinThr[CW_NUMS - 1] = { 2500, 4000 };
SMultiValueInput<uint32_t> cfg_BinCW (0, 64, CW_NUMS - 1, CW_NUMS - 1, defaultBinCW, sizeof(defaultBinCW) / sizeof(uint32_t));
......@@ -1852,7 +1853,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
m_reshapeCW.RspFps = m_iFrameRate;
m_reshapeCW.RspIntraPeriod = m_iIntraPeriod;
m_reshapeCW.RspPicSize = m_iSourceWidth*m_iSourceHeight;
const int FpsToIpTable[MAX_FRAME_RATE + 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 128, 128, 128, 128, 128, 128, 128, 128, 128 };
const int FpsToIpTable[129] = { 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 128, 128, 128, 128, 128, 128, 128, 128, 128 };
m_reshapeCW.RspFpsToIp = FpsToIpTable[m_iFrameRate];
m_reshapeCW.RspBaseQP = m_iQP;
#endif
......@@ -2243,7 +2244,7 @@ bool EncAppCfg::xCheckParameter()
if (m_bLumaReshapeEnable && (m_internalBitDepth[CHANNEL_TYPE_LUMA] != 10))
{
m_bLumaReshapeEnable = false;
msg(WARNING, "Reshaping is implemented for 10bit luma internal bitdepth.\n");
msg(WARNING, "Reshaping is turned off for luma internal bitdepth not equal to 10.\n");
}
if (!m_bLumaReshapeEnable)
{
......
......@@ -368,11 +368,12 @@ void AreaBuf<Pel>::rspSignal(std::vector<Pel>& pLUT)
}
template<>
void AreaBuf<Pel>::scaleSignal(const int scale, const bool dir)
void AreaBuf<Pel>::scaleSignal(const int scale, const bool dir, const ClpRng& clpRng)
{
Pel* dst = buf;
Pel* src = buf;
int sign, absval;
int maxAbsclipBD = (1<<clpRng.bd) - 1;
if (dir) // forward
{
......@@ -388,8 +389,7 @@ void AreaBuf<Pel>::scaleSignal(const int scale, const bool dir)
{
sign = src[x] >= 0 ? 1 : -1;
absval = sign * src[x];
dst[x] = sign * (((absval << CSCALE_FP_PREC) + (scale >> 1)) / scale);
dst[x] = dst[x] > 1023 ? 1023 : dst[x] < -1023 ? -1023 : dst[x];
dst[x] = (Pel)Clip3(-maxAbsclipBD, maxAbsclipBD, sign * (((absval << CSCALE_FP_PREC) + (scale >> 1)) / scale));
}
dst += stride;
src += stride;
......
......@@ -134,7 +134,7 @@ struct AreaBuf : public Size
#if JVET_M0427_INLOOP_RESHAPER
void rspSignal ( std::vector<Pel>& pLUT );
void scaleSignal ( const int scale, const bool dir );
void scaleSignal ( const int scale, const bool dir , const ClpRng& clpRng);
T computeAvg ( ) const;
#endif
T& at( const int &x, const int &y ) { return buf[y * stride + x]; }
......
......@@ -405,17 +405,10 @@ static const int IBC_FAST_METHOD_NOINTRA_IBCCBF0 = 0x01;
static const int IBC_FAST_METHOD_BUFFERBV = 0X02;
static const int IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE = 0X04;
#if JVET_M0427_INLOOP_RESHAPER
static const int MAX_LUMA_RESHAPING_LUT_SIZE = 1024;
static const int CSCALE_FP_PREC = 11;
static const int PIC_ANALYZE_CW_BINS = 32;
static const int FP_PREC = 14;
static const int log2_MAX_LUMA_RESHAPING_LUT_SIZE = 10;
static const int log2_PIC_ANALYZE_CW_BINS = 5;
static const int PIC_ANALYZE_WIN_SIZE = 5;
static const int CW_NUMS = 3;
static const int MAX_FRAME_RATE = 128;
static const int PIC_CODE_CW_BINS = 16;
static const int log2_PIC_CODE_CW_BINS = 4;
static const int FP_PREC = 14;
static const int CSCALE_FP_PREC = 11;
#endif
#if JVET_M0512_MOTION_BUFFER_COMPRESSION
static constexpr int MV_EXPONENT_BITCOUNT = 4;
......
......@@ -177,8 +177,9 @@ void RdCost::init()
m_motionLambda = 0;
m_iCostScale = 0;
#if JVET_M0427_INLOOP_RESHAPER
m_iSignalType = RESHAPE_SIGNAL_NULL;
m_chroma_weight = 1.0;
m_signalType = RESHAPE_SIGNAL_NULL;
m_chromaWeight = 1.0;
m_lumaBD = 10;
#endif
}
......@@ -2862,11 +2863,14 @@ Distortion RdCost::xGetHADs( const DistParam &rcDtParam )
#if WCG_EXT
double RdCost::m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#if JVET_M0427_INLOOP_RESHAPER
double RdCost::m_reshapeLumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
uint32_t RdCost::m_iSignalType;
double RdCost::m_chroma_weight;
uint32_t RdCost::m_signalType;
double RdCost::m_chromaWeight;
int RdCost::m_lumaBD;
std::vector<double> RdCost::m_reshapeLumaLevelToWeightPLUT;
std::vector<double> RdCost::m_lumaLevelToWeightPLUT;
#else
double RdCost::m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#endif
void RdCost::saveUnadjustedLambda()
......@@ -2877,18 +2881,6 @@ void RdCost::saveUnadjustedLambda()
void RdCost::initLumaLevelToWeightTable()
{
#if JVET_M0427_INLOOP_RESHAPER
if (m_iSignalType == RESHAPE_SIGNAL_SDR)
{
double weight = 1.0;
for (int i = 0; i < LUMA_LEVEL_TO_DQP_LUT_MAXSIZE; i++)
{
m_lumaLevelToWeightPLUT[i] = weight;
}
return;
}
#endif
for (int i = 0; i < LUMA_LEVEL_TO_DQP_LUT_MAXSIZE; i++) {
double x = i;
double y;
......@@ -2910,15 +2902,33 @@ void RdCost::initLumaLevelToWeightTable()
m_lumaLevelToWeightPLUT[i] = pow(2.0, y / 3.0); // or power(10, dQp/10) they are almost equal
}
#if JVET_M0427_INLOOP_RESHAPER
memcpy(m_reshapeLumaLevelToWeightPLUT, m_lumaLevelToWeightPLUT, LUMA_LEVEL_TO_DQP_LUT_MAXSIZE * sizeof(double));
#endif
}
#if JVET_M0427_INLOOP_RESHAPER
void RdCost::initLumaLevelToWeightTableReshape()
{
int lutSize = 1 << m_lumaBD;
if (m_reshapeLumaLevelToWeightPLUT.empty())
m_reshapeLumaLevelToWeightPLUT.resize(lutSize, 1.0);
if (m_lumaLevelToWeightPLUT.empty())
m_lumaLevelToWeightPLUT.resize(lutSize, 1.0);
if (m_signalType == RESHAPE_SIGNAL_PQ)
{
for (int i = 0; i < (1 << m_lumaBD); i++)
{
double x = m_lumaBD < 10 ? i << (10 - m_lumaBD) : m_lumaBD > 10 ? i >> (m_lumaBD - 10) : i;
double y;
y = 0.015*x - 1.5 - 6;
y = y < -3 ? -3 : (y > 6 ? 6 : y);
m_reshapeLumaLevelToWeightPLUT[i] = pow(2.0, y / 3.0);
m_lumaLevelToWeightPLUT[i] = m_reshapeLumaLevelToWeightPLUT[i];
}
}
}
void RdCost::updateReshapeLumaLevelToWeightTableChromaMD(std::vector<Pel>& ILUT)
{
for (int i = 0; i < LUMA_LEVEL_TO_DQP_LUT_MAXSIZE; i++) // idx in reshaped domain;
for (int i = 0; i < (1 << m_lumaBD); i++)
{
m_reshapeLumaLevelToWeightPLUT[i] = m_lumaLevelToWeightPLUT[ILUT[i]];
}
......@@ -2926,19 +2936,21 @@ void RdCost::updateReshapeLumaLevelToWeightTableChromaMD(std::vector<Pel>& ILUT)
void RdCost::restoreReshapeLumaLevelToWeightTable()
{
memcpy(m_reshapeLumaLevelToWeightPLUT, m_lumaLevelToWeightPLUT, LUMA_LEVEL_TO_DQP_LUT_MAXSIZE * sizeof(double));
for (int i = 0; i < (1 << m_lumaBD); i++)
{
m_reshapeLumaLevelToWeightPLUT.at(i) = m_lumaLevelToWeightPLUT.at(i);
}
}
void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape, Pel *wt_table, double cwt)
void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape, Pel *wtTable, double cwt)
{
if (m_iSignalType == RESHAPE_SIGNAL_SDR)
if (m_signalType == RESHAPE_SIGNAL_SDR)
{
if (sliceReshape.getSliceReshapeModelPresentFlag())
{
double w_bin = 1.0;
double wBin = 1.0;
double weight = 1.0;
int hist_lens = MAX_LUMA_RESHAPING_LUT_SIZE / PIC_CODE_CW_BINS;
int histLens = (1 << m_lumaBD) / PIC_CODE_CW_BINS;
for (int i = 0; i < PIC_CODE_CW_BINS; i++)
{
......@@ -2946,21 +2958,21 @@ void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape,
weight = 1.0;
else
{
if (sliceReshape.reshape_model_bin_CW_delta[i] == 1 || sliceReshape.reshape_model_bin_CW_delta[i] == -1 * MAX_LUMA_RESHAPING_LUT_SIZE / PIC_CODE_CW_BINS)
weight = w_bin;
if (sliceReshape.reshape_model_bin_CW_delta[i] == 1 || (sliceReshape.reshape_model_bin_CW_delta[i] == -1 * histLens))
weight = wBin;
else
{
weight = (double)wt_table[i] / (double)hist_lens;
weight = (double)wtTable[i] / (double)histLens;
weight = weight*weight;
}
}
for (int j = 0; j < hist_lens; j++)
for (int j = 0; j < histLens; j++)
{
int ii = i*hist_lens + j;
int ii = i*histLens + j;
m_reshapeLumaLevelToWeightPLUT[ii] = weight;
}
}
m_chroma_weight = cwt;
m_chromaWeight = cwt;
}
else
{
......@@ -2987,13 +2999,13 @@ Distortion RdCost::getWeightedMSE(int compIdx, const Pel org, const Pel cur, con
// use luma to get weight
#if JVET_M0427_INLOOP_RESHAPER
double weight = 1.0;
if (m_iSignalType == RESHAPE_SIGNAL_SDR)
if (m_signalType == RESHAPE_SIGNAL_SDR)
{
if (compIdx == COMPONENT_Y)
weight = m_reshapeLumaLevelToWeightPLUT[orgLuma];
else
{
weight = m_chroma_weight;
weight = m_chromaWeight;
}
}
else
......
......@@ -107,11 +107,14 @@ private:
#if WCG_EXT
double m_dLambda_unadjusted; // TODO: check is necessary
double m_DistScaleUnadjusted;
static double m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#if JVET_M0427_INLOOP_RESHAPER
static double m_reshapeLumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
static uint32_t m_iSignalType;
static double m_chroma_weight;
static std::vector<double> m_reshapeLumaLevelToWeightPLUT;
static std::vector<double> m_lumaLevelToWeightPLUT;
static uint32_t m_signalType;
static double m_chromaWeight;
static int m_lumaBD;
#else
static double m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#endif
#endif
double m_DistScale;
......@@ -296,13 +299,13 @@ public:
void initLumaLevelToWeightTable ();
inline double getWPSNRLumaLevelWeight (int val) { return m_lumaLevelToWeightPLUT[val]; }
#if JVET_M0427_INLOOP_RESHAPER
void initLumaLevelToWeightTableReshape();
void updateReshapeLumaLevelToWeightTableChromaMD (std::vector<Pel>& ILUT);
void restoreReshapeLumaLevelToWeightTable ();
inline double getWPSNRReshapeLumaLevelWeight (int val) { return m_reshapeLumaLevelToWeightPLUT[val]; }
uint32_t getReshapeSignalType () const { return m_iSignalType; }
void setReshapeSignalType (uint32_t type) { m_iSignalType = type; }
void updateReshapeLumaLevelToWeightTable (sliceReshapeInfo &sliceReshape, Pel *wt_table, double cwt);
inline double* getLumaLevelWeightTable() { return m_lumaLevelToWeightPLUT; }
inline double getWPSNRReshapeLumaLevelWeight (int val) { return m_reshapeLumaLevelToWeightPLUT[val]; }
void setReshapeInfo (uint32_t type, int lumaBD) { m_signalType = type; m_lumaBD = lumaBD; }
void updateReshapeLumaLevelToWeightTable (sliceReshapeInfo &sliceReshape, Pel *wtTable, double cwt);
inline std::vector<double>& getLumaLevelWeightTable () { return m_lumaLevelToWeightPLUT; }
#endif
#endif
......
......@@ -51,25 +51,27 @@ Reshape::Reshape()
m_bCTUFlag = false;
m_bRecReshaped = false;
m_bReshape = true;
m_uiCWOrg = MAX_LUMA_RESHAPING_LUT_SIZE / PIC_CODE_CW_BINS;
}
Reshape::~Reshape()
{
}
void Reshape::create_dec()
void Reshape::createDec(int bitDepth)
{
m_lumaBD = bitDepth;
m_reshapeLUTSize = 1 << m_lumaBD;
m_initCW = m_reshapeLUTSize / PIC_CODE_CW_BINS;
if (forwardReshapingLUT.empty())
forwardReshapingLUT.resize(MAX_LUMA_RESHAPING_LUT_SIZE, 0);
forwardReshapingLUT.resize(m_reshapeLUTSize, 0);
if (inverseReshapingLUT.empty())
inverseReshapingLUT.resize(MAX_LUMA_RESHAPING_LUT_SIZE, 0);
if (m_uiBinCWAll.empty())
m_uiBinCWAll.resize(PIC_CODE_CW_BINS, 0);
if (m_ReshapePivot.empty())
m_ReshapePivot.resize(PIC_CODE_CW_BINS + 1, 0);
if (ChromaAdjHelpLUT.empty())
ChromaAdjHelpLUT.resize(PIC_CODE_CW_BINS, 2048);
inverseReshapingLUT.resize(m_reshapeLUTSize, 0);
if (m_binCW.empty())
m_binCW.resize(PIC_CODE_CW_BINS, 0);
if (m_reshapePivot.empty())
m_reshapePivot.resize(PIC_CODE_CW_BINS + 1, 0);
if (m_chromaAdjHelpLUT.empty())
m_chromaAdjHelpLUT.resize(PIC_CODE_CW_BINS, 1<<CSCALE_FP_PREC);
}
void Reshape::destroy()
......@@ -82,38 +84,38 @@ void Reshape::destroy()
\retval OutputLUT describing the inversed LUT of InputLUT
\param lut_size size of LUT in number of samples
*/
void Reshape::ReverseLUT(std::vector<Pel>& InputLUT, std::vector<Pel>& OutputLUT, uint16_t lut_size)
void Reshape::reverseLUT(std::vector<Pel>& inputLUT, std::vector<Pel>& outputLUT, uint16_t lutSize)
{
int i, j;
OutputLUT[m_ReshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]] = m_sliceReshapeInfo.reshape_model_min_bin_idx*m_uiCWOrg;
outputLUT[m_reshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]] = m_sliceReshapeInfo.reshape_model_min_bin_idx*m_initCW;
for (i = m_sliceReshapeInfo.reshape_model_min_bin_idx; i <= m_sliceReshapeInfo.reshape_model_max_bin_idx; i++)
{
int16_t X1 = m_ReshapePivot[i];
int16_t X2 = m_ReshapePivot[i + 1];
OutputLUT[X2] = (i + 1)*m_uiCWOrg;
int16_t Y1 = OutputLUT[X1];
int16_t Y2 = OutputLUT[X2];
int16_t X1 = m_reshapePivot[i];
int16_t X2 = m_reshapePivot[i + 1];
outputLUT[X2] = (i + 1)*m_initCW;
int16_t Y1 = outputLUT[X1];
int16_t Y2 = outputLUT[X2];
if (X2 !=X1)
{
int32_t scale = (int32_t)(Y2 - Y1) * (1 << FP_PREC) / (int32_t)(X2 - X1);
for (j = X1 + 1; j < X2; j++)
{
OutputLUT[j] = (Pel)((scale*(int32_t)(j - X1) + (1 << (FP_PREC - 1))) >> FP_PREC) + Y1;
outputLUT[j] = (Pel)((scale*(int32_t)(j - X1) + (1 << (FP_PREC - 1))) >> FP_PREC) + Y1;
}
}
}
for (i = 0; i < m_ReshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]; i++)
OutputLUT[i] = OutputLUT[m_ReshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]];
for (i = m_ReshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx + 1]; i < MAX_LUMA_RESHAPING_LUT_SIZE; i++)
OutputLUT[i] = OutputLUT[m_ReshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx + 1]];
for (i = 0; i < m_reshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]; i++)
outputLUT[i] = outputLUT[m_reshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx]];
for (i = m_reshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx + 1]; i < m_reshapeLUTSize; i++)
outputLUT[i] = outputLUT[m_reshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx + 1]];
bool clipRange = ((m_sliceReshapeInfo.reshape_model_min_bin_idx > 0) && (m_sliceReshapeInfo.reshape_model_max_bin_idx < (PIC_CODE_CW_BINS - 1)));
for (i = 0; i < lut_size; i++)
for (i = 0; i < lutSize; i++)
{
if (clipRange) OutputLUT[i] = Clip3((Pel)64, (Pel)940, OutputLUT[i]);
else OutputLUT[i] = Clip3((Pel)0, (Pel)1023, OutputLUT[i]);
if (clipRange) outputLUT[i] = Clip3((Pel)(16<<(m_lumaBD-8)), (Pel)(235<<(m_lumaBD-8)), outputLUT[i]);
else outputLUT[i] = Clip3((Pel)0, (Pel)((1<<m_lumaBD)-1), outputLUT[i]);
}
}
......@@ -124,8 +126,8 @@ void Reshape::ReverseLUT(std::vector<Pel>& InputLUT, std::vector<Pel>& OutputLUT
*/
int Reshape::calculateChromaAdj(Pel avgLuma)
{
int lumaIdx = Clip3<int>(0, int(LUMA_LEVEL_TO_DQP_LUT_MAXSIZE) - 1, avgLuma);
int iAdj = ChromaAdjHelpLUT[getPWLIdxInv(lumaIdx)];
int lumaIdx = Clip3<int>(0, (1<<m_lumaBD) - 1, avgLuma);
int iAdj = m_chromaAdjHelpLUT[getPWLIdxInv(lumaIdx)];
return(iAdj);
}
......@@ -137,15 +139,15 @@ int Reshape::calculateChromaAdj(Pel avgLuma)
int Reshape::getPWLIdxInv(int lumaVal)
{
int idxS = 0;
if (lumaVal < m_ReshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx + 1])
if (lumaVal < m_reshapePivot[m_sliceReshapeInfo.reshape_model_min_bin_idx + 1])
return m_sliceReshapeInfo.reshape_model_min_bin_idx;
else if (lumaVal >= m_ReshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx])
else if (lumaVal >= m_reshapePivot[m_sliceReshapeInfo.reshape_model_max_bin_idx])
return m_sliceReshapeInfo.reshape_model_max_bin_idx;
else
{
for (idxS = m_sliceReshapeInfo.reshape_model_min_bin_idx; (idxS < m_sliceReshapeInfo.reshape_model_max_bin_idx); idxS++)
{
if (lumaVal < m_ReshapePivot[idxS + 1]) break;
if (lumaVal < m_reshapePivot[idxS + 1]) break;
}
return idxS;
}
......@@ -180,33 +182,33 @@ void Reshape::copySliceReshaperInfo(sliceReshapeInfo& tInfo, sliceReshapeInfo& s
void Reshape::constructReshaper()
{
int pwlFwdLUTsize = PIC_CODE_CW_BINS;
int pwlFwdBinLen = MAX_LUMA_RESHAPING_LUT_SIZE / PIC_CODE_CW_BINS;
int pwlFwdBinLen = m_reshapeLUTSize / PIC_CODE_CW_BINS;
for (int i = 0; i < m_sliceReshapeInfo.reshape_model_min_bin_idx; i++)
m_uiBinCWAll[i] = 0;
m_binCW[i] = 0;
for (int i = m_sliceReshapeInfo.reshape_model_max_bin_idx + 1; i < PIC_CODE_CW_BINS; i++)
m_uiBinCWAll[i] = 0;
m_binCW[i] = 0;
for (int i = m_sliceReshapeInfo.reshape_model_min_bin_idx; i <= m_sliceReshapeInfo.reshape_model_max_bin_idx; i++)
m_uiBinCWAll[i] = (uint16_t)(m_sliceReshapeInfo.reshape_model_bin_CW_delta[i] + (int)m_uiCWOrg);
m_binCW[i] = (uint16_t)(m_sliceReshapeInfo.reshape_model_bin_CW_delta[i] + (int)m_initCW);
for (int i = 0; i < pwlFwdLUTsize; i++)
{
m_ReshapePivot[i + 1] = m_ReshapePivot[i] + m_uiBinCWAll[i];
int16_t Y1 = m_ReshapePivot[i];
int16_t Y2 = m_ReshapePivot[i + 1];
m_reshapePivot[i + 1] = m_reshapePivot[i] + m_binCW[i];
int16_t Y1 = m_reshapePivot[i];
int16_t Y2 = m_reshapePivot[i + 1];
forwardReshapingLUT[i*pwlFwdBinLen] = Clip3((Pel)0, (Pel)1023, (Pel)Y1);
forwardReshapingLUT[i*pwlFwdBinLen] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)Y1);
int log2_pwlFwdBinLen = log2_MAX_LUMA_RESHAPING_LUT_SIZE - log2_PIC_CODE_CW_BINS;
int log2_pwlFwdBinLen = g_aucLog2[pwlFwdBinLen];
int32_t scale = ((int32_t)(Y2 - Y1) * (1 << FP_PREC) + (1 << (log2_pwlFwdBinLen - 1))) >> (log2_pwlFwdBinLen);
for (int j = 1; j < pwlFwdBinLen; j++)
{
int tempVal = Y1 + (((int32_t)scale * (int32_t)j + (1 << (FP_PREC - 1))) >> FP_PREC);
forwardReshapingLUT[i*pwlFwdBinLen + j] = Clip3((Pel)0, (Pel)1023, (Pel)tempVal);
forwardReshapingLUT[i*pwlFwdBinLen + j] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)tempVal);
}
}
ReverseLUT(forwardReshapingLUT, inverseReshapingLUT, MAX_LUMA_RESHAPING_LUT_SIZE);
reverseLUT(forwardReshapingLUT, inverseReshapingLUT, m_reshapeLUTSize);
updateChromaDQPLUT();
}
......@@ -219,10 +221,11 @@ void Reshape::updateChromaDQPLUT()
const int16_t CW_bin_SC_LUT[2 * PIC_ANALYZE_CW_BINS] = { 16384, 16384, 16384, 16384, 16384, 16384, 16384, 8192, 8192, 8192, 8192, 5461, 5461, 5461, 5461, 4096, 4096, 4096, 4096, 3277, 3277, 3277, 3277, 2731, 2731, 2731, 2731, 2341, 2341, 2341, 2048, 2048, 2048, 1820, 1820, 1820, 1638, 1638, 1638, 1638, 1489, 1489, 1489, 1489, 1365, 1365, 1365, 1365, 1260, 1260, 1260, 1260, 1170, 1170, 1170, 1170, 1092, 1092, 1092, 1092, 1024, 1024, 1024, 1024 }; //p=11
for (int i = 0; i < PIC_CODE_CW_BINS; i++)
{
uint16_t binCW = m_lumaBD > 10 ? (m_binCW[i] >> (m_lumaBD - 10)) : m_lumaBD < 10 ? (m_binCW[i] << (10 -m_lumaBD)): m_binCW[i];
if ((i < m_sliceReshapeInfo.reshape_model_min_bin_idx) || (i > m_sliceReshapeInfo.reshape_model_max_bin_idx))
ChromaAdjHelpLUT[i] = 1 << CSCALE_FP_PREC;
m_chromaAdjHelpLUT[i] = 1 << CSCALE_FP_PREC;
else
ChromaAdjHelpLUT[i] = CW_bin_SC_LUT[Clip3((uint16_t)1, (uint16_t)64, (uint16_t)(m_uiBinCWAll[i] >> 1)) - 1];
m_chromaAdjHelpLUT[i] = CW_bin_SC_LUT[Clip3((uint16_t)1, (uint16_t)64, (uint16_t)(binCW >> 1)) - 1];
}
}
#endif
......
......@@ -60,22 +60,24 @@ protected:
bool m_bRecReshaped;
std::vector<Pel> inverseReshapingLUT;
std::vector<Pel> forwardReshapingLUT;
std::vector<int> ChromaAdjHelpLUT;
std::vector<uint16_t> m_uiBinCWAll;
uint16_t m_uiCWOrg;
std::vector<int> m_chromaAdjHelpLUT;
std::vector<uint16_t> m_binCW;
uint16_t m_initCW;
bool m_bReshape;
std::vector<Pel> m_ReshapePivot;
std::vector<Pel> m_reshapePivot;
int m_lumaBD;
int m_reshapeLUTSize;
public:
Reshape();
~Reshape();
void create_dec();
void createDec(int bitDepth);
void destroy();
void ReverseLUT(std::vector<Pel>& InputLUT, std::vector<Pel>& OutputLUT, uint16_t lut_size);
void reverseLUT(std::vector<Pel>& inputLUT, std::vector<Pel>& outputLUT, uint16_t lutSize);
std::vector<Pel>& getFwdLUT() { return forwardReshapingLUT; }
std::vector<Pel>& getInvLUT() { return inverseReshapingLUT; }
std::vector<int>& getChromaAdjHelpLUT() { return ChromaAdjHelpLUT; }
std::vector<int>& getChromaAdjHelpLUT() { return m_chromaAdjHelpLUT; }
bool getCTUFlag() { return m_bCTUFlag; }
void setCTUFlag(bool bCTUFlag) { m_bCTUFlag = bCTUFlag; }
......
......@@ -278,6 +278,10 @@ CodingUnit& CodingUnit::operator=( const CodingUnit& other )
shareParentSize = other.shareParentSize;
#endif
ibc = other.ibc;
#if JVET_M0444_SMVD
smvdMode = other.smvdMode;
#endif
#if JVET_M0444_SMVD
smvdMode = other.smvdMode;
#endif
......@@ -323,6 +327,9 @@ void CodingUnit::initData()
#if JVET_M0444_SMVD
smvdMode = 0;
#endif
#if JVET_M0444_SMVD
smvdMode = 0;
#endif
}
......
......@@ -317,6 +317,9 @@ struct CodingUnit : public UnitArea
Size shareParentSize;
#endif
bool ibc;
#if JVET_M0444_SMVD
uint8_t smvdMode;
#endif
#if JVET_M0444_SMVD
uint8_t smvdMode;
#endif
......
......@@ -243,7 +243,7 @@ void DecCu::xIntraRecBlk( TransformUnit& tu, const ComponentID compID )
bFlag = bFlag && (tu.blocks[compID].width*tu.blocks[compID].height > 4);
if (bFlag && TU::getCbf(tu, compID) && isChroma(compID) && slice.getReshapeInfo().getSliceReshapeChromaAdj())
{
piResi.scaleSignal(tu.getChromaAdj(), 0);
piResi.scaleSignal(tu.getChromaAdj(), 0, tu.cu->cs->slice->clpRng(compID));
}
#endif
if( isChroma(compID) && tu.compAlpha[compID] != 0 )
......@@ -570,7 +570,7 @@ void DecCu::xDecodeInterTU( TransformUnit & currTU, const ComponentID compID )
const Slice &slice = *cs.slice;
if ( slice.getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag() && isChroma(compID) && TU::getCbf(currTU, compID) && slice.getReshapeInfo().getSliceReshapeChromaAdj() && currTU.blocks[compID].width*currTU.blocks[compID].height > 4 )
{
resiBuf.scaleSignal(currTU.getChromaAdj(), 0);
resiBuf.scaleSignal(currTU.getChromaAdj(), 0, currTU.cu->cs->slice->clpRng(compID));
}
#endif
if( isChroma( compID ) && currTU.compAlpha[compID] != 0 )
......
......@@ -756,7 +756,7 @@ void DecLib::xActivateParameterSets()
#if JVET_M0427_INLOOP_RESHAPER
if (sps->getUseReshaper())
{
m_cReshaper.create_dec();
m_cReshaper.createDec(sps->getBitDepth(CHANNEL_TYPE_LUMA));
}
#endif
......
......@@ -854,25 +854,29 @@ void HLSyntaxReader::parseSPSNext( SPSNext& spsNext, const bool usePCM )
}
#if JVET_M0427_INLOOP_RESHAPER
void HLSyntaxReader::parseReshaper (sliceReshapeInfo& info, const SPS* pcSPS, const bool isIntra)
void HLSyntaxReader::parseReshaper(sliceReshapeInfo& info, const SPS* pcSPS, const bool isIntra)
{
unsigned symbol = 0;
READ_FLAG(symbol, "slice_reshape_model_present_flag"); info.setSliceReshapeModelPresentFlag(symbol == 1);
READ_FLAG(symbol, "slice_reshape_model_present_flag"); info.setSliceReshapeModelPresentFlag(symbol == 1);
if (info.getSliceReshapeModelPresentFlag())
{
// parse slice reshaper model
memset(info.reshape_model_bin_CW_delta, 0, PIC_CODE_CW_BINS * sizeof(int));
READ_UVLC(symbol, "reshaper_model_min_bin_idx"); info.reshape_model_min_bin_idx = symbol;
READ_UVLC(symbol, "max_bin_minus_reshape_model_max_bin_idx"); info.reshape_model_max_bin_idx = PIC_CODE_CW_BINS - 1 - symbol;
READ_UVLC(symbol, "reshaper_model_bin_delta_abs_cw_prec_minus1"); info.maxNbitsNeededDeltaCW = symbol+1;
assert(info.maxNbitsNeededDeltaCW > 0);
for (uint32_t i = info.reshape_model_min_bin_idx; i <= info.reshape_model_max_bin_idx; i++)
READ_UVLC(symbol, "reshaper_model_min_bin_idx"); info.reshape_model_min_bin_idx = symbol;
READ_UVLC(symbol, "max_bin_minus_reshape_model_max_bin_idx"); info.reshape_model_max_bin_idx = PIC_CODE_CW_BINS - 1 - symbol;
READ_UVLC(symbol, "reshaper_model_bin_delta_abs_cw_prec_minus1"); info.maxNbitsNeededDeltaCW = symbol + 1;
assert(info.maxNbitsNeededDeltaCW > 0);
for (uint32_t i = info.reshape_model_min_bin_idx; i <= info.reshape_model_max_bin_idx; i++)
{
READ_CODE(info.maxNbitsNeededDeltaCW, symbol, "reshape_model_abs_CW");
int absCW = symbol;
if (absCW > 0)
{
READ_CODE(info.maxNbitsNeededDeltaCW, symbol, "reshape_model_abs_CW"); int absCW = symbol;
if (absCW > 0)
READ_CODE(1, symbol, "reshape_model_sign_CW"); int signCW = symbol;
info.reshape_model_bin_CW_delta[i] = (1 - 2 * signCW) * absCW;
READ_CODE(1, symbol, "reshape_model_sign_CW");
}
int signCW = symbol;
info.reshape_model_bin_CW_delta[i] = (1 - 2 * signCW) * absCW;
}
}