Commit 2b20df8a authored by Frank Bossen's avatar Frank Bossen

Merge branch 'HDR-reshaper-generalBD-support' into 'master'

HDR reshaping general bitdepth support

See merge request !365
parents 2b3defa5 0774d1ef
Pipeline #1118 passed with stage
......@@ -113,7 +113,7 @@ void EncReshape::preAnalyzerHDR(Picture *pcPic, const SliceType sliceType, const
void EncReshape::preAnalyzerHDR(Picture *pcPic, const SliceType sliceType, const ReshapeCW& reshapeCW, bool isDualT, bool isIBC)
#endif
{
if (m_lumaBD == 10)
if (m_lumaBD >= 10)
{
m_sliceReshapeInfo.sliceReshaperEnableFlag = true;
if (reshapeCW.rspIntraPeriod == 1)
......@@ -1028,54 +1028,33 @@ void EncReshape::deriveReshapeParameters(double *array, int start, int end, Resh
*/
void EncReshape::initLUTfromdQPModel()
{
initModelParam();
int pwlFwdLUTsize = PIC_CODE_CW_BINS;
int pwlFwdBinLen = m_reshapeLUTSize / PIC_CODE_CW_BINS;
int p1 = m_dQPModel.scaleFracPrec;
int p2 = m_dQPModel.offsetFracPrec;
int totalShift = p1 + p2;
int scaleFP = (1 - 2 * m_dQPModel.scaleSign) * m_dQPModel.scaleAbs;
int offsetFP = (1 - 2 * m_dQPModel.offsetSign) * m_dQPModel.offsetAbs;
int maxQP = (1 - 2 * m_dQPModel.maxQPSign) * m_dQPModel.maxQPAbs;
int minQP = (1 - 2 * m_dQPModel.minQPSign) * m_dQPModel.minQPAbs;
int maxFP = maxQP * (1 << totalShift);
int minFP = minQP * (1 << totalShift);
int temp, signval, absval;
int dQPDiv6FP;
int32_t * slopeLUT = new int32_t[m_reshapeLUTSize]();
int32_t * fwdLUTHighPrec = new int32_t[m_reshapeLUTSize]();
double lumaDQP = 0.0;
double * slopeLUT = new double[m_reshapeLUTSize]();
double * fwdLUTHighPrec = new double[m_reshapeLUTSize]();
for (int i = 0; i < m_reshapeLUTSize; i++)
{
int inputY = m_lumaBD < 10 ? i << (10 - m_lumaBD) : m_lumaBD > 10 ? i >> (m_lumaBD - 10) : i;
temp = int64_t((scaleFP*inputY) * (1 << p2)) + int64_t(offsetFP * (1 << p1));
temp = temp > maxFP ? maxFP : temp < minFP ? minFP : temp;
signval = temp >= 0 ? 1 : -1;
absval = signval * temp;
dQPDiv6FP = signval * (((absval + 3) / 6 + (1 << (totalShift - 17))) >> (totalShift - 16));
slopeLUT[i] = calcEXP2(dQPDiv6FP);
}
if (m_dQPModel.fullRangeInputFlag == 0)
{
for (int i = 0; i < (16 << (m_lumaBD - 8)); i++) { slopeLUT[i] = 0; }
for (int i = (235 << (m_lumaBD - 8)); i < m_reshapeLUTSize; i++) { slopeLUT[i] = 0; }
lumaDQP = 0.015*(double)inputY - 7.5;
lumaDQP = lumaDQP<-3 ? -3 : (lumaDQP>6 ? 6 : lumaDQP);
slopeLUT[i] = pow(2.0, lumaDQP / 6.0);
}
for (int i = 0; i < (16 << (m_lumaBD - 8)); i++) { slopeLUT[i] = 0.0; }
for (int i = (235 << (m_lumaBD - 8)); i < m_reshapeLUTSize; i++) { slopeLUT[i] = 0.0; }
for (int i = 0; i < m_reshapeLUTSize - 1; i++)
fwdLUTHighPrec[i + 1] = fwdLUTHighPrec[i] + slopeLUT[i];
if (slopeLUT != nullptr) { delete[] slopeLUT; slopeLUT = nullptr; }
if (slopeLUT != nullptr) { delete[] slopeLUT; slopeLUT = nullptr; }
int max_Y = (fwdLUTHighPrec[m_reshapeLUTSize - 1] + (1 << 7)) >> 8;
int Roffset = max_Y >> 1;
double maxY = fwdLUTHighPrec[m_reshapeLUTSize - 1];
for (int i = 0; i < m_reshapeLUTSize; i++)
{
m_fwdLUT[i] = (short)(((fwdLUTHighPrec[i] >> 8) * (m_reshapeLUTSize - 1) + Roffset) / max_Y);
m_fwdLUT[i] = (int16_t)((fwdLUTHighPrec[i] / maxY * (double)(m_reshapeLUTSize - 1)) + 0.5);
}
if (fwdLUTHighPrec != nullptr) { delete[] fwdLUTHighPrec; fwdLUTHighPrec = nullptr; }
m_sliceReshapeInfo.reshaperModelMinBinIdx = 1;
m_sliceReshapeInfo.reshaperModelMaxBinIdx = 14;
m_sliceReshapeInfo.reshaperModelMaxBinIdx = PIC_CODE_CW_BINS-2;
for (int i = 0; i < pwlFwdLUTsize; i++)
{
......@@ -1116,27 +1095,6 @@ void EncReshape::initLUTfromdQPModel()
updateChromaScaleLUT();
}
/**
-Perform fixe point exp2 calculation
\param val input value
\retval output value = exp2(val)
*/
int EncReshape::calcEXP2(int val)
{
int32_t i, f, r, s;
r = 0x00000e20;
i = ((int32_t)(val)+0x8000) & ~0xffff;
f = (int32_t)(val)-i;
s = ((15 << 16) - i) >> 16;
r = (r * f + 0x3e1cc333) >> 17;
r = (r * f + 0x58bd46a6) >> 16;
r = r * f + 0x7ffde4a3;
return (uint32_t)r >> s;
}
void EncReshape::constructReshaperSDR()
{
int bdShift = m_lumaBD - 10;
......
......@@ -51,28 +51,6 @@
// Class definition
// ====================================================================================================================
struct ModelInfo
{
unsigned fullRangeInputFlag;
unsigned scaleIntPrec;
unsigned scaleInt;
unsigned scaleFracPrec;
unsigned scaleFrac;
unsigned scaleSign;
unsigned offsetIntPrec;
unsigned offsetInt;
unsigned offsetFracPrec;
unsigned offsetFrac;
unsigned offsetSign;
unsigned minMaxQPAbsPrec;
unsigned maxQPAbs;
unsigned maxQPSign;
unsigned minQPAbs;
unsigned minQPSign;
unsigned scaleAbs;
unsigned offsetAbs;
};
class EncReshape : public Reshape
{
private:
......@@ -90,7 +68,6 @@ private:
int m_rateAdpMode;
bool m_useAdpCW;
uint16_t m_initCWAnalyze;
ModelInfo m_dQPModel;
ReshapeCW m_reshapeCW;
Pel m_cwLumaWeight[PIC_CODE_CW_BINS];
double m_chromaWeight;
......@@ -118,34 +95,10 @@ public:
void deriveReshapeParametersSDRfromStats(uint32_t *, double*, double* reshapeTH1, double* reshapeTH2, bool *intraAdp, bool *interAdp);
void deriveReshapeParameters(double *array, int start, int end, ReshapeCW respCW, double &alpha, double &beta);
void initLUTfromdQPModel();
int calcEXP2(int val);
void constructReshaperSDR();
ReshapeCW * getReshapeCW() { return &m_reshapeCW; }
Pel * getWeightTable() { return m_cwLumaWeight; }
double getCWeight() { return m_chromaWeight; }
void initModelParam(double scale = 0.015, double offset = -7.5, int QPMax = 6, int QPMin = -3)
{
/// dQP model: dQP = clip3(QPMin, QPMax, dScale*Y+dOffset);
m_dQPModel.fullRangeInputFlag = 0;
m_dQPModel.scaleIntPrec = 0;
m_dQPModel.scaleFracPrec = 16;
m_dQPModel.offsetIntPrec = 3;
m_dQPModel.offsetFracPrec = 1;
m_dQPModel.minMaxQPAbsPrec = 3;
m_dQPModel.scaleSign = scale < 0 ? 1 : 0;
m_dQPModel.scaleAbs = unsigned((scale < 0 ? -scale : scale) * (1 << m_dQPModel.scaleFracPrec));
m_dQPModel.scaleInt = m_dQPModel.scaleAbs >> m_dQPModel.scaleFracPrec;
m_dQPModel.scaleFrac = m_dQPModel.scaleAbs - (m_dQPModel.scaleInt << m_dQPModel.scaleFracPrec);
m_dQPModel.offsetSign = offset < 0 ? 1 : 0;
m_dQPModel.offsetAbs = unsigned((offset < 0 ? -offset : offset) * (1 << m_dQPModel.offsetFracPrec));
m_dQPModel.offsetInt = m_dQPModel.offsetAbs >> m_dQPModel.offsetFracPrec;
m_dQPModel.offsetFrac = m_dQPModel.offsetAbs - (m_dQPModel.offsetInt << m_dQPModel.offsetFracPrec);
m_dQPModel.maxQPSign = QPMax < 0 ? 1 : 0;
m_dQPModel.maxQPAbs = m_dQPModel.maxQPSign ? -QPMax : QPMax;
m_dQPModel.minQPSign = QPMin < 0 ? 1 : 0;
m_dQPModel.minQPAbs = m_dQPModel.minQPSign ? -QPMin : QPMin;
}
};// END CLASS DEFINITION EncReshape
//! \}
......
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