source/Lib/CommonLib/Reshape.cpp
void Reshape::constructReshaper()
{
  int pwlFwdLUTsize = PIC_CODE_CW_BINS;
  int pwlFwdBinLen = m_reshapeLUTSize / PIC_CODE_CW_BINS;

  for (int i = 0; i < m_sliceReshapeInfo.reshaperModelMinBinIdx; i++)
    m_binCW[i] = 0;
  for (int i = m_sliceReshapeInfo.reshaperModelMaxBinIdx + 1; i < PIC_CODE_CW_BINS; i++)
    m_binCW[i] = 0;
  for (int i = m_sliceReshapeInfo.reshaperModelMinBinIdx; i <= m_sliceReshapeInfo.reshaperModelMaxBinIdx; i++)
    m_binCW[i] = (uint16_t)(m_sliceReshapeInfo.reshaperModelBinCWDelta[i] + (int)m_initCW);

  for (int i = 0; i < pwlFwdLUTsize; i++)
  {
    m_reshapePivot[i + 1] = m_reshapePivot[i] + m_binCW[i];
    m_inputPivot[i + 1] = m_inputPivot[i] + m_initCW;
    m_fwdScaleCoef[i] = ((int32_t)m_binCW[i] * (1 << FP_PREC) + (1 << (getLog2(pwlFwdBinLen) - 1))) >> getLog2(pwlFwdBinLen);
    if (m_binCW[i] == 0)
    {
      m_invScaleCoef[i] = 0;
      m_chromaAdjHelpLUT[i] = 1 << CSCALE_FP_PREC;
    }
    else
    {
      CHECK( m_initCW * (1 << FP_PREC) / m_binCW[i] > (1 << 15) - 1, "Inverse scale coeff doesn't fit in a short!" );
      m_invScaleCoef[i] = (int32_t)(m_initCW * (1 << FP_PREC) / m_binCW[i]);
      m_chromaAdjHelpLUT[i] = (int32_t)(m_initCW * (1 << FP_PREC) / ( m_binCW[i] + m_sliceReshapeInfo.chrResScalingOffset ) );
    }
  }
  for (int lumaSample = 0; lumaSample < m_reshapeLUTSize; lumaSample++)
  {
    int idxY = lumaSample / m_initCW;
    int tempVal = m_reshapePivot[idxY] + ((m_fwdScaleCoef[idxY] * (lumaSample - m_inputPivot[idxY]) + (1 << (FP_PREC - 1))) >> FP_PREC);
    m_fwdLUT[lumaSample] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)(tempVal));

    int idxYInv = getPWLIdxInv(lumaSample);
    int invSample = m_inputPivot[idxYInv] + ((m_invScaleCoef[idxYInv] * (lumaSample - m_reshapePivot[idxYInv]) + (1 << (FP_PREC - 1))) >> FP_PREC);
    m_invLUT[lumaSample] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)(invSample));
  }
}
/** Construct reshaper from syntax
* \param void
* \return void
*/
Construct reshaper from syntax
\param void
\return void
Construct reshaper from syntax \ param void \ return void
void Reshape::constructReshaper()
{
  int pwlFwdLUTsize = PIC_CODE_CW_BINS;
  int pwlFwdBinLen = m_reshapeLUTSize / PIC_CODE_CW_BINS;
  for (int i = 0; i < m_sliceReshapeInfo.reshaperModelMinBinIdx; i++)
    m_binCW[i] = 0;
  for (int i = m_sliceReshapeInfo.reshaperModelMaxBinIdx + 1; i < PIC_CODE_CW_BINS; i++)
    m_binCW[i] = 0;
  for (int i = m_sliceReshapeInfo.reshaperModelMinBinIdx; i <= m_sliceReshapeInfo.reshaperModelMaxBinIdx; i++)
    m_binCW[i] = (uint16_t)(m_sliceReshapeInfo.reshaperModelBinCWDelta[i] + (int)m_initCW);
  for (int i = 0; i < pwlFwdLUTsize; i++)
  {
    m_reshapePivot[i + 1] = m_reshapePivot[i] + m_binCW[i];
    m_inputPivot[i + 1] = m_inputPivot[i] + m_initCW;
    m_fwdScaleCoef[i] = ((int32_t)m_binCW[i] * (1 << FP_PREC) + (1 << (getLog2(pwlFwdBinLen) - 1))) >> getLog2(pwlFwdBinLen);
    if (m_binCW[i] == 0)
    {
      m_invScaleCoef[i] = 0;
      m_chromaAdjHelpLUT[i] = 1 << CSCALE_FP_PREC;
    }
    else
    {
      CHECK( m_initCW * (1 << FP_PREC) / m_binCW[i] > (1 << 15) - 1, "Inverse scale coeff doesn't fit in a short!" );
      m_invScaleCoef[i] = (int32_t)(m_initCW * (1 << FP_PREC) / m_binCW[i]);
      m_chromaAdjHelpLUT[i] = (int32_t)(m_initCW * (1 << FP_PREC) / ( m_binCW[i] + m_sliceReshapeInfo.chrResScalingOffset ) );
    }
  }
  for (int lumaSample = 0; lumaSample < m_reshapeLUTSize; lumaSample++)
  {
    int idxY = lumaSample / m_initCW;
    int tempVal = m_reshapePivot[idxY] + ((m_fwdScaleCoef[idxY] * (lumaSample - m_inputPivot[idxY]) + (1 << (FP_PREC - 1))) >> FP_PREC);
    m_fwdLUT[lumaSample] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)(tempVal));
    int idxYInv = getPWLIdxInv(lumaSample);
    int invSample = m_inputPivot[idxYInv] + ((m_invScaleCoef[idxYInv] * (lumaSample - m_reshapePivot[idxYInv]) + (1 << (FP_PREC - 1))) >> FP_PREC);
    m_invLUT[lumaSample] = Clip3((Pel)0, (Pel)((1 << m_lumaBD) - 1), (Pel)(invSample));
  }
}
void Reshape :: constructReshaper ( ) { int pwlFwdLUTsize = PIC_CODE_CW_BINS ; int pwlFwdBinLen = m_reshapeLUTSize / PIC_CODE_CW_BINS ; for ( int i = 0 ; i < m_sliceReshapeInfo . reshaperModelMinBinIdx ; i ++ ) m_binCW [ i ] = 0 ; for ( int i = m_sliceReshapeInfo . reshaperModelMaxBinIdx + 1 ; i < PIC_CODE_CW_BINS ; i ++ ) m_binCW [ i ] = 0 ; for ( int i = m_sliceReshapeInfo . reshaperModelMinBinIdx ; i <= m_sliceReshapeInfo . reshaperModelMaxBinIdx ; i ++ ) m_binCW [ i ] = ( uint16_t ) ( m_sliceReshapeInfo . reshaperModelBinCWDelta [ i ] + ( int ) m_initCW ) ; for ( int i = 0 ; i < pwlFwdLUTsize ; i ++ ) { m_reshapePivot [ i + 1 ] = m_reshapePivot [ i ] + m_binCW [ i ] ; m_inputPivot [ i + 1 ] = m_inputPivot [ i ] + m_initCW ; m_fwdScaleCoef [ i ] = ( ( int32_t ) m_binCW [ i ] * ( 1 << FP_PREC ) + ( 1 << ( getLog2 ( pwlFwdBinLen ) - 1 ) ) ) >> getLog2 ( pwlFwdBinLen ) ; if ( m_binCW [ i ] == 0 ) { m_invScaleCoef [ i ] = 0 ; m_chromaAdjHelpLUT [ i ] = 1 << CSCALE_FP_PREC ; } else { CHECK ( m_initCW * ( 1 << FP_PREC ) / m_binCW [ i ] > ( 1 << 15 ) - 1 , " " ) ; m_invScaleCoef [ i ] = ( int32_t ) ( m_initCW * ( 1 << FP_PREC ) / m_binCW [ i ] ) ; m_chromaAdjHelpLUT [ i ] = ( int32_t ) ( m_initCW * ( 1 << FP_PREC ) / ( m_binCW [ i ] + m_sliceReshapeInfo . chrResScalingOffset ) ) ; } } for ( int lumaSample = 0 ; lumaSample < m_reshapeLUTSize ; lumaSample ++ ) { int idxY = lumaSample / m_initCW ; int tempVal = m_reshapePivot [ idxY ] + ( ( m_fwdScaleCoef [ idxY ] * ( lumaSample - m_inputPivot [ idxY ] ) + ( 1 << ( FP_PREC - 1 ) ) ) >> FP_PREC ) ; m_fwdLUT [ lumaSample ] = Clip3 ( ( Pel ) 0 , ( Pel ) ( ( 1 << m_lumaBD ) - 1 ) , ( Pel ) ( tempVal ) ) ; int idxYInv = getPWLIdxInv ( lumaSample ) ; int invSample = m_inputPivot [ idxYInv ] + ( ( m_invScaleCoef [ idxYInv ] * ( lumaSample - m_reshapePivot [ idxYInv ] ) + ( 1 << ( FP_PREC - 1 ) ) ) >> FP_PREC ) ; m_invLUT [ lumaSample ] = Clip3 ( ( Pel ) 0 , ( Pel ) ( ( 1 << m_lumaBD ) - 1 ) , ( Pel ) ( invSample ) ) ; } }
Construct reshaper from syntax
\param void
\return void
Construct reshaper from syntax \ param void \ return void