Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2019, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file EncReshape.cpp
\brief encoder reshaper class
*/
#include "EncReshape.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#if JVET_M0427_INLOOP_RESHAPER
//! \ingroup EncLib
//! \{
// ====================================================================================================================
// Constructor / destructor / create / destroy
// ====================================================================================================================
EncReshape::EncReshape()
{
m_CTUFlag = false;
m_srcReshaped = false;
m_recReshaped = false;
m_reshape = true;
m_exceedSTD = false;
m_tcase = 0;
m_rateAdpMode = 0;
m_chromaAdj = 0;
}
EncReshape::~EncReshape()
{
}
void EncReshape::createEnc(int picWidth, int picHeight, uint32_t maxCUWidth, uint32_t maxCUHeight, int bitDepth)
m_lumaBD = bitDepth;
m_reshapeLUTSize = 1 << m_lumaBD;
m_initCWAnalyze = m_reshapeLUTSize / PIC_ANALYZE_CW_BINS;
m_initCW = m_reshapeLUTSize / PIC_CODE_CW_BINS;
if (m_fwdLUT.empty())
m_fwdLUT.resize(m_reshapeLUTSize, 0);
if (m_invLUT.empty())
m_invLUT.resize(m_reshapeLUTSize,0);
if (m_binCW.empty())
m_binCW.resize(PIC_ANALYZE_CW_BINS);
if (m_binImportance.empty())
m_binImportance.resize(PIC_ANALYZE_CW_BINS);
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);
m_sliceReshapeInfo.setUseSliceReshaper(true);
m_sliceReshapeInfo.setSliceReshapeChromaAdj(true);
m_sliceReshapeInfo.setSliceReshapeModelPresentFlag(true);
m_sliceReshapeInfo.reshaperModelMinBinIdx = 0;
m_sliceReshapeInfo.reshaperModelMaxBinIdx = PIC_CODE_CW_BINS - 1;
memset(m_sliceReshapeInfo.reshaperModelBinCWDelta, 0, (PIC_CODE_CW_BINS) * sizeof(int));
m_picWidth = picWidth;
m_picHeight = picHeight;
m_maxCUWidth = maxCUWidth;
m_maxCUHeight = maxCUHeight;
m_widthInCtus = (m_picWidth + m_maxCUWidth - 1) / m_maxCUWidth;
m_heightInCtus = (m_picHeight + m_maxCUHeight - 1) / m_maxCUHeight;
m_numCtuInFrame = m_widthInCtus * m_heightInCtus;
}
void EncReshape::destroy()
{
}
/**
-Perform HDR set up
\param pcPic describe pointer of current coding picture
\param sliceType describe the slice type
*/
void EncReshape::preAnalyzerHDR(Picture *pcPic, const SliceType sliceType, const ReshapeCW& reshapeCW, bool isDualT)
#else
void EncReshape::preAnalyzerHDR(Picture *pcPic, const SliceType sliceType, const ReshapeCW& reshapeCW, bool isDualT, bool isIBC)
#endif
m_sliceReshapeInfo.sliceReshaperEnableFlag = true;
if (reshapeCW.rspIntraPeriod == 1)
if (pcPic->getPOC() == 0) { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true; }
else { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = false; }
if (sliceType == I_SLICE ) { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true; }
#else
if (sliceType == I_SLICE || (sliceType == P_SLICE && isIBC)) { m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true; }
#endif
if (sliceType == I_SLICE && isDualT) { m_sliceReshapeInfo.enableChromaAdj = 0; }
#else
if ((sliceType == I_SLICE || (sliceType == P_SLICE && isIBC)) && isDualT) { m_sliceReshapeInfo.enableChromaAdj = 0; }
#endif
m_sliceReshapeInfo.sliceReshaperEnableFlag = false;
m_sliceReshapeInfo.sliceReshaperModelPresentFlag = false;
}
}
/**
-Perform picture analysis for SDR
\param pcPic describe pointer of current coding picture
\param sliceType describe the slice type
\param reshapeCW describe some input info
*/
void EncReshape::preAnalyzerSDR(Picture *pcPic, const SliceType sliceType, const ReshapeCW& reshapeCW, bool isDualT)
#else
void EncReshape::preAnalyzerSDR(Picture *pcPic, const SliceType sliceType, const ReshapeCW& reshapeCW, bool isDualT, bool isIBC)
#endif
m_sliceReshapeInfo.sliceReshaperModelPresentFlag = true;
m_sliceReshapeInfo.sliceReshaperEnableFlag = true;
int modIP = pcPic->getPOC() - pcPic->getPOC() / reshapeCW.rspFpsToIp * reshapeCW.rspFpsToIp;
if (sliceType == I_SLICE || (reshapeCW.rspIntraPeriod == -1 && modIP == 0))
#else
if (sliceType == I_SLICE || (reshapeCW.rspIntraPeriod == -1 && modIP == 0) || (sliceType == P_SLICE && isIBC))
#endif
int stdMin = 16 <<(m_lumaBD-8);
int stdMax = 235 << (m_lumaBD - 8);
int binLen = m_reshapeLUTSize / PIC_ANALYZE_CW_BINS;
for (int b = 0; b < PIC_ANALYZE_CW_BINS; b++)
{
int startBinIdx = stdMin / binLen;
int endBinIdx = stdMax / binLen;
m_sliceReshapeInfo.reshaperModelMinBinIdx = startBinIdx;
m_sliceReshapeInfo.reshaperModelMaxBinIdx = endBinIdx;
PelBuf picY = pcPic->getOrigBuf(COMPONENT_Y);
const int width = picY.width;
const int height = picY.height;
const int stride = picY.stride;
double blockBinVarSum[PIC_ANALYZE_CW_BINS] = { 0.0 };
uint32_t bockBinCnt[PIC_ANALYZE_CW_BINS] = { 0 };
const uint32_t winSize = PIC_ANALYZE_WIN_SIZE;
const uint32_t winLens = (winSize - 1) >> 1;
Loading
Loading full blame...