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[] ) ...@@ -708,6 +708,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
int warnUnknowParameter = 0; int warnUnknowParameter = 0;
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
const int CW_NUMS = 3;
const uint32_t defaultBinCW[CW_NUMS - 1] = { 38, 28 }; const uint32_t defaultBinCW[CW_NUMS - 1] = { 38, 28 };
const uint32_t defaultBinThr[CW_NUMS - 1] = { 2500, 4000 }; 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)); 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[] ) ...@@ -1852,7 +1853,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
m_reshapeCW.RspFps = m_iFrameRate; m_reshapeCW.RspFps = m_iFrameRate;
m_reshapeCW.RspIntraPeriod = m_iIntraPeriod; m_reshapeCW.RspIntraPeriod = m_iIntraPeriod;
m_reshapeCW.RspPicSize = m_iSourceWidth*m_iSourceHeight; 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.RspFpsToIp = FpsToIpTable[m_iFrameRate];
m_reshapeCW.RspBaseQP = m_iQP; m_reshapeCW.RspBaseQP = m_iQP;
#endif #endif
...@@ -2243,7 +2244,7 @@ bool EncAppCfg::xCheckParameter() ...@@ -2243,7 +2244,7 @@ bool EncAppCfg::xCheckParameter()
if (m_bLumaReshapeEnable && (m_internalBitDepth[CHANNEL_TYPE_LUMA] != 10)) if (m_bLumaReshapeEnable && (m_internalBitDepth[CHANNEL_TYPE_LUMA] != 10))
{ {
m_bLumaReshapeEnable = false; 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) if (!m_bLumaReshapeEnable)
{ {
......
...@@ -368,11 +368,12 @@ void AreaBuf<Pel>::rspSignal(std::vector<Pel>& pLUT) ...@@ -368,11 +368,12 @@ void AreaBuf<Pel>::rspSignal(std::vector<Pel>& pLUT)
} }
template<> 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* dst = buf;
Pel* src = buf; Pel* src = buf;
int sign, absval; int sign, absval;
int maxAbsclipBD = (1<<clpRng.bd) - 1;
if (dir) // forward if (dir) // forward
{ {
...@@ -388,8 +389,7 @@ void AreaBuf<Pel>::scaleSignal(const int scale, const bool dir) ...@@ -388,8 +389,7 @@ void AreaBuf<Pel>::scaleSignal(const int scale, const bool dir)
{ {
sign = src[x] >= 0 ? 1 : -1; sign = src[x] >= 0 ? 1 : -1;
absval = sign * src[x]; absval = sign * src[x];
dst[x] = sign * (((absval << CSCALE_FP_PREC) + (scale >> 1)) / scale); dst[x] = (Pel)Clip3(-maxAbsclipBD, maxAbsclipBD, sign * (((absval << CSCALE_FP_PREC) + (scale >> 1)) / scale));
dst[x] = dst[x] > 1023 ? 1023 : dst[x] < -1023 ? -1023 : dst[x];
} }
dst += stride; dst += stride;
src += stride; src += stride;
......
...@@ -134,7 +134,7 @@ struct AreaBuf : public Size ...@@ -134,7 +134,7 @@ struct AreaBuf : public Size
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
void rspSignal ( std::vector<Pel>& pLUT ); 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; T computeAvg ( ) const;
#endif #endif
T& at( const int &x, const int &y ) { return buf[y * stride + x]; } 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; ...@@ -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_BUFFERBV = 0X02;
static const int IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE = 0X04; static const int IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE = 0X04;
#if JVET_M0427_INLOOP_RESHAPER #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 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 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 #endif
#if JVET_M0512_MOTION_BUFFER_COMPRESSION #if JVET_M0512_MOTION_BUFFER_COMPRESSION
static constexpr int MV_EXPONENT_BITCOUNT = 4; static constexpr int MV_EXPONENT_BITCOUNT = 4;
......
...@@ -177,8 +177,9 @@ void RdCost::init() ...@@ -177,8 +177,9 @@ void RdCost::init()
m_motionLambda = 0; m_motionLambda = 0;
m_iCostScale = 0; m_iCostScale = 0;
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
m_iSignalType = RESHAPE_SIGNAL_NULL; m_signalType = RESHAPE_SIGNAL_NULL;
m_chroma_weight = 1.0; m_chromaWeight = 1.0;
m_lumaBD = 10;
#endif #endif
} }
...@@ -2862,11 +2863,14 @@ Distortion RdCost::xGetHADs( const DistParam &rcDtParam ) ...@@ -2862,11 +2863,14 @@ Distortion RdCost::xGetHADs( const DistParam &rcDtParam )
#if WCG_EXT #if WCG_EXT
double RdCost::m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
double RdCost::m_reshapeLumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE]; uint32_t RdCost::m_signalType;
uint32_t RdCost::m_iSignalType; double RdCost::m_chromaWeight;
double RdCost::m_chroma_weight; 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 #endif
void RdCost::saveUnadjustedLambda() void RdCost::saveUnadjustedLambda()
...@@ -2877,18 +2881,6 @@ void RdCost::saveUnadjustedLambda() ...@@ -2877,18 +2881,6 @@ void RdCost::saveUnadjustedLambda()
void RdCost::initLumaLevelToWeightTable() 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++) { for (int i = 0; i < LUMA_LEVEL_TO_DQP_LUT_MAXSIZE; i++) {
double x = i; double x = i;
double y; double y;
...@@ -2910,15 +2902,33 @@ void RdCost::initLumaLevelToWeightTable() ...@@ -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 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 #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) 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]]; m_reshapeLumaLevelToWeightPLUT[i] = m_lumaLevelToWeightPLUT[ILUT[i]];
} }
...@@ -2926,19 +2936,21 @@ void RdCost::updateReshapeLumaLevelToWeightTableChromaMD(std::vector<Pel>& ILUT) ...@@ -2926,19 +2936,21 @@ void RdCost::updateReshapeLumaLevelToWeightTableChromaMD(std::vector<Pel>& ILUT)
void RdCost::restoreReshapeLumaLevelToWeightTable() 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 *wtTable, double cwt)
void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape, Pel *wt_table, double cwt)
{ {
if (m_iSignalType == RESHAPE_SIGNAL_SDR) if (m_signalType == RESHAPE_SIGNAL_SDR)
{ {
if (sliceReshape.getSliceReshapeModelPresentFlag()) if (sliceReshape.getSliceReshapeModelPresentFlag())
{ {
double w_bin = 1.0; double wBin = 1.0;
double weight = 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++) for (int i = 0; i < PIC_CODE_CW_BINS; i++)
{ {
...@@ -2946,21 +2958,21 @@ void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape, ...@@ -2946,21 +2958,21 @@ void RdCost::updateReshapeLumaLevelToWeightTable(sliceReshapeInfo &sliceReshape,
weight = 1.0; weight = 1.0;
else 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) if (sliceReshape.reshape_model_bin_CW_delta[i] == 1 || (sliceReshape.reshape_model_bin_CW_delta[i] == -1 * histLens))
weight = w_bin; weight = wBin;
else else
{ {
weight = (double)wt_table[i] / (double)hist_lens; weight = (double)wtTable[i] / (double)histLens;
weight = weight*weight; 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_reshapeLumaLevelToWeightPLUT[ii] = weight;
} }
} }
m_chroma_weight = cwt; m_chromaWeight = cwt;
} }
else else
{ {
...@@ -2987,13 +2999,13 @@ Distortion RdCost::getWeightedMSE(int compIdx, const Pel org, const Pel cur, con ...@@ -2987,13 +2999,13 @@ Distortion RdCost::getWeightedMSE(int compIdx, const Pel org, const Pel cur, con
// use luma to get weight // use luma to get weight
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
double weight = 1.0; double weight = 1.0;
if (m_iSignalType == RESHAPE_SIGNAL_SDR) if (m_signalType == RESHAPE_SIGNAL_SDR)
{ {
if (compIdx == COMPONENT_Y) if (compIdx == COMPONENT_Y)
weight = m_reshapeLumaLevelToWeightPLUT[orgLuma]; weight = m_reshapeLumaLevelToWeightPLUT[orgLuma];
else else
{ {
weight = m_chroma_weight; weight = m_chromaWeight;
} }
} }
else else
......
...@@ -107,11 +107,14 @@ private: ...@@ -107,11 +107,14 @@ private:
#if WCG_EXT #if WCG_EXT
double m_dLambda_unadjusted; // TODO: check is necessary double m_dLambda_unadjusted; // TODO: check is necessary
double m_DistScaleUnadjusted; double m_DistScaleUnadjusted;
static double m_lumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE];
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
static double m_reshapeLumaLevelToWeightPLUT[LUMA_LEVEL_TO_DQP_LUT_MAXSIZE]; static std::vector<double> m_reshapeLumaLevelToWeightPLUT;
static uint32_t m_iSignalType; static std::vector<double> m_lumaLevelToWeightPLUT;
static double m_chroma_weight; 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
#endif #endif
double m_DistScale; double m_DistScale;
...@@ -296,13 +299,13 @@ public: ...@@ -296,13 +299,13 @@ public:
void initLumaLevelToWeightTable (); void initLumaLevelToWeightTable ();
inline double getWPSNRLumaLevelWeight (int val) { return m_lumaLevelToWeightPLUT[val]; } inline double getWPSNRLumaLevelWeight (int val) { return m_lumaLevelToWeightPLUT[val]; }
#if JVET_M0427_INLOOP_RESHAPER #if JVET_M0427_INLOOP_RESHAPER
void initLumaLevelToWeightTableReshape();
void updateReshapeLumaLevelToWeightTableChromaMD (std::vector<Pel>& ILUT); void updateReshapeLumaLevelToWeightTableChromaMD (std::vector<Pel>& ILUT);
void restoreReshapeLumaLevelToWeightTable (); void restoreReshapeLumaLevelToWeightTable ();
inline double getWPSNRReshapeLumaLevelWeight (int val) { return m_reshapeLumaLevelToWeightPLUT[val]; } inline double getWPSNRReshapeLumaLevelWeight (int val) { return m_reshapeLumaLevelToWeightPLUT[val]; }
uint32_t getReshapeSignalType () const { return m_iSignalType; } void setReshapeInfo (uint32_t type, int lumaBD) { m_signalType = type; m_lumaBD = lumaBD; }
void setReshapeSignalType (uint32_t type) { m_iSignalType = type; } void updateReshapeLumaLevelToWeightTable (sliceReshapeInfo &sliceReshape, Pel *wtTable, double cwt);
void updateReshapeLumaLevelToWeightTable (sliceReshapeInfo &sliceReshape, Pel *wt_table, double cwt); inline std::vector<double>& getLumaLevelWeightTable () { return m_lumaLevelToWeightPLUT; }
inline double* getLumaLevelWeightTable() { return m_lumaLevelToWeightPLUT; }
#endif #endif
#endif #endif
......
...@@ -51,25 +51,27 @@ Reshape::Reshape() ...@@ -51,25 +51,27 @@ Reshape::Reshape()
m_bCTUFlag = false; m_bCTUFlag = false;
m_bRecReshaped = false; m_bRecReshaped = false;
m_bReshape = true; m_bReshape = true;
m_uiCWOrg = MAX_LUMA_RESHAPING_LUT_SIZE / PIC_CODE_CW_BINS;
} }
Reshape::~Reshape() 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()) if (forwardReshapingLUT.empty())
forwardReshapingLUT.resize(MAX_LUMA_RESHAPING_LUT_SIZE, 0); forwardReshapingLUT.resize(m_reshapeLUTSize, 0);
if (inverseReshapingLUT.empty()) if (inverseReshapingLUT.empty())
inverseReshapingLUT.resize(MAX_LUMA_RESHAPING_LUT_SIZE, 0); inverseReshapingLUT.resize(m_reshapeLUTSize, 0);
if (m_uiBinCWAll.empty()) if (m_binCW.empty())
m_uiBinCWAll.resize(PIC_CODE_CW_BINS, 0); m_binCW.resize(PIC_CODE_CW_BINS, 0);
if (m_ReshapePivot.empty()) if (m_reshapePivot.empty())
m_ReshapePivot.resize(PIC_CODE_CW_BINS + 1, 0); m_reshapePivot.resize(PIC_CODE_CW_BINS + 1, 0);
if (ChromaAdjHelpLUT.empty()) if (m_chromaAdjHelpLUT.empty())
ChromaAdjHelpLUT.resize(PIC_CODE_CW_BINS, 2048); m_chromaAdjHelpLUT.resize(PIC_CODE_CW_BINS, 1<<CSCALE_FP_PREC);
} }
void Reshape::destroy() void Reshape::destroy()
...@@ -82,38 +84,38 @@ void Reshape::destroy() ...@@ -82,38 +84,38 @@ void Reshape::destroy()
\retval OutputLUT describing the inversed LUT of InputLUT \retval OutputLUT describing the inversed LUT of InputLUT
\param lut_size size of LUT in number of samples \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; 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++) 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 X1 = m_reshapePivot[i];
int16_t X2 = m_ReshapePivot[i + 1]; int16_t X2 = m_reshapePivot[i + 1];
OutputLUT[X2] = (i + 1)*m_uiCWOrg; outputLUT[X2] = (i + 1)*m_initCW;
int16_t Y1 = OutputLUT[X1]; int16_t Y1 = outputLUT[X1];
int16_t Y2 = OutputLUT[X2]; int16_t Y2 = outputLUT[X2];
if (X2 !=X1) if (X2 !=X1)
{ {
int32_t scale = (int32_t)(Y2 - Y1) * (1 << FP_PREC) / (int32_t)(X2 - X1); int32_t scale = (int32_t)(Y2 - Y1) * (1 << FP_PREC) / (int32_t)(X2 - X1);
for (j = X1 + 1; j < X2; j++) 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++) 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]]; 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++) 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]]; 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))); 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]); if (clipRange) outputLUT[i] = Clip3((Pel)(16<<(m_lumaBD-8)), (Pel)(235<<(m_lumaBD-8)), outputLUT[i]);
else OutputLUT[i] = Clip3((Pel)0, (Pel)1023, 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 ...@@ -124,8 +126,8 @@ void Reshape::ReverseLUT(std::vector<Pel>& InputLUT, std::vector<Pel>& OutputLUT
*/ */
int Reshape::calculateChromaAdj(Pel avgLuma) int Reshape::calculateChromaAdj(Pel avgLuma)
{ {
int lumaIdx = Clip3<int>(0, int(LUMA_LEVEL_TO_DQP_LUT_MAXSIZE) - 1, avgLuma); int lumaIdx = Clip3<int>(0, (1<<m_lumaBD) - 1, avgLuma);
int iAdj = ChromaAdjHelpLUT[getPWLIdxInv(lumaIdx)]; int iAdj = m_chromaAdjHelpLUT[getPWLIdxInv(lumaIdx)];
return(iAdj); return(iAdj);
} }
...@@ -137,15 +139,15 @@ int Reshape::calculateChromaAdj(Pel avgLuma) ...@@ -137,15 +139,15 @@ int Reshape::calculateChromaAdj(Pel avgLuma)
int Reshape::getPWLIdxInv(int lumaVal) int Reshape::getPWLIdxInv(int lumaVal)
{ {
int idxS = 0; 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; 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; return m_sliceReshapeInfo.reshape_model_max_bin_idx;
else else
{ {
for (idxS = m_sliceReshapeInfo.reshape_model_min_bin_idx; (idxS < m_sliceReshapeInfo.reshape_model_max_bin_idx); idxS++) 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; return idxS;
} }
...@@ -180,33 +182,33 @@ void Reshape::copySliceReshaperInfo(sliceReshapeInfo& tInfo, sliceReshapeInfo& s ...@@ -180,33 +182,33 @@ void Reshape::copySliceReshaperInfo(sliceReshapeInfo& tInfo, sliceReshapeInfo& s
void Reshape::constructReshaper() void Reshape::constructReshaper()
{ {
int pwlFwdLUTsize = PIC_CODE_CW_BINS; 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++) 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++) 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++) 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++) for (int i = 0; i < pwlFwdLUTsize; i++)
{ {
m_ReshapePivot[i + 1] = m_ReshapePivot[i] + m_uiBinCWAll[i]; m_reshapePivot[i + 1] = m_reshapePivot[i] + m_binCW[i];
int16_t Y1 = m_ReshapePivot[i]; int16_t Y1 = m_reshapePivot[i];
int16_t Y2 = m_ReshapePivot[i + 1]; 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); int32_t scale = ((int32_t)(Y2 - Y1) * (1 << FP_PREC) + (1 << (log2_pwlFwdBinLen - 1))) >> (log2_pwlFwdBinLen);
for (int j = 1; j < pwlFwdBinLen; j++) for (int j = 1; j < pwlFwdBinLen; j++)
{ {
int tempVal = Y1 + (((int32_t)scale * (int32_t)j + (1 << (FP_PREC - 1))) >> FP_PREC); 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(); updateChromaDQPLUT();
} }
...@@ -219,10 +221,11 @@ void Reshape::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 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++) 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)) 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 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 #endif
......
...@@ -60,22 +60,24 @@ protected: ...@@ -60,22 +60,24 @@ protected:
bool m_bRecReshaped; bool m_bRecReshaped;
std::vector<Pel> inverseReshapingLUT; std::vector<Pel> inverseReshapingLUT;
std::vector<Pel> forwardReshapingLUT; std::vector<Pel> forwardReshapingLUT;
std::vector<int> ChromaAdjHelpLUT;