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;
int64_t tempSq = 0;
int64_t leftSum = 0, leftSumSq = 0;
int64_t *leftColSum = new int64_t[width];
int64_t *leftColSumSq = new int64_t[width];
memset(leftColSum, 0, width * sizeof(int64_t));
memset(leftColSumSq, 0, width * sizeof(int64_t));
int64_t *topRowSum = new int64_t[height];
int64_t *topRowSumSq = new int64_t[height];
memset(topRowSum, 0, height * sizeof(int64_t));
memset(topRowSumSq, 0, height * sizeof(int64_t));
int64_t *topColSum = new int64_t[width];
int64_t *topColSumSq = new int64_t[width];
memset(topColSum, 0, width * sizeof(int64_t));
memset(topColSumSq, 0, width * sizeof(int64_t));
for (uint32_t y = 0; y < height; y++)
const Pel pxlY = picY.buf[x];
int64_t sum = 0;
int64_t sumSq = 0;
uint32_t numPixInPart = 0;
uint32_t y1 = std::max((int)(y - winLens), 0);
uint32_t y2 = std::min((int)(y + winLens), (height - 1));
uint32_t x1 = std::max((int)(x - winLens), 0);
uint32_t x2 = std::min((int)(x + winLens), (width - 1));
uint32_t bx = 0, by = 0;
const Pel *pWinY = &picY.buf[0];
if (x == 0 && y == 0) // for the 1st Pixel, calc all points
{
for (by = y1; by <= y2; by++)
{
for (bx = x1; bx <= x2; bx++)
{
tempSq = pWinY[bx] * pWinY[bx];
leftSum += pWinY[bx];
leftSumSq += tempSq;
leftColSum[bx] += pWinY[bx];
leftColSumSq[bx] += tempSq;
topColSum[bx] += pWinY[bx];
topColSumSq[bx] += tempSq;
topRowSum[by] += pWinY[bx];
topRowSumSq[by] += tempSq;
}
}
topSum = leftSum;
topSumSq = leftSumSq;
}
else if (x == 0 && y > 0) // for the 1st column, calc the bottom stripe
{
if (y < height - winLens)
pWinY += winLens*stride;
topRowSum[y + winLens] = 0;
topRowSumSq[y + winLens] = 0;
topRowSum[y + winLens] += pWinY[bx];
topRowSumSq[y + winLens] += pWinY[bx] * pWinY[bx];
topSum += topRowSum[y + winLens];
topSumSq += topRowSumSq[y + winLens];
topSum -= topRowSum[y - 1 - winLens];
topSumSq -= topRowSumSq[y - 1 - winLens];
memset(leftColSum, 0, width * sizeof(int64_t));
memset(leftColSumSq, 0, width * sizeof(int64_t));
pWinY -= (y <= winLens ? y : winLens)*stride;
for (by = y1; by <= y2; by++)
{
for (bx = x1; bx <= x2; bx++)
{
leftColSum[bx] += pWinY[bx];
leftColSumSq[bx] += pWinY[bx] * pWinY[bx];
}
}
leftSum = topSum;
leftSumSq = topSumSq;
if (x < width - winLens)
pWinY -= (y <= winLens ? y : winLens)*stride;
if (y == 0) // for the 1st row, calc the right stripe
{
leftColSum[x + winLens] = 0;
leftColSumSq[x + winLens] = 0;
leftColSum[x + winLens] += pWinY[x + winLens];
leftColSumSq[x + winLens] += pWinY[x + winLens] * pWinY[x + winLens];
else // for the main area, calc the B-R point
leftColSum[x + winLens] = topColSum[x + winLens];
leftColSumSq[x + winLens] = topColSumSq[x + winLens];
if (y < height - winLens)
pWinY += winLens * stride;
leftColSum[x + winLens] += pWinY[x + winLens];
leftColSumSq[x + winLens] += pWinY[x + winLens] * pWinY[x + winLens];
pWinY -= (winLens + 1) * stride;
leftColSum[x + winLens] -= pWinY[x + winLens];
leftColSumSq[x + winLens] -= pWinY[x + winLens] * pWinY[x + winLens];
topColSum[x + winLens] = leftColSum[x + winLens];
topColSumSq[x + winLens] = leftColSumSq[x + winLens];
leftSum += leftColSum[x + winLens];
leftSumSq += leftColSumSq[x + winLens];
leftSum -= leftColSum[x - 1 - winLens];
leftSumSq -= leftColSumSq[x - 1 - winLens];
double average = double(sum) / numPixInPart;
double variance = double(sumSq) / numPixInPart - average * average;
uint32_t binNum = (uint32_t)(pxlY/PIC_ANALYZE_CW_BINS);
average = average / (double)(1<<(m_lumaBD - 10));
variance = variance / (double)(1 << (2*m_lumaBD - 20));
binNum = (uint32_t)((pxlY>>(m_lumaBD - 10)) / PIC_ANALYZE_CW_BINS);
average = average * (double)(1 << (10 - m_lumaBD));
variance = variance * (double)(1 << (20-2*m_lumaBD));
binNum = (uint32_t)((pxlY << (10 - m_lumaBD)) / PIC_ANALYZE_CW_BINS);
blockBinVarSum[binNum] += varLog10;
bockBinCnt[binNum]++;
}
delete[] topColSum;
delete[] topColSumSq;
delete[] topRowSum;
delete[] topRowSumSq;
delete[] leftColSum;
delete[] leftColSumSq;
for (int b = 0; b < PIC_ANALYZE_CW_BINS; b++)
{
if (bockBinCnt[b] > 0)
blockBinVarSum[b] = blockBinVarSum[b] / bockBinCnt[b];
m_rateAdpMode = 0;
m_tcase = 0;
bool intraAdp = false;
bool interAdp = true;
double reshapeTH1 = 0.0;
double reshapeTH2 = 5.0;
deriveReshapeParametersSDRfromStats(bockBinCnt, blockBinVarSum, &reshapeTH1, &reshapeTH2, &intraAdp, &interAdp);
if (m_rateAdpMode == 2 && reshapeCW.rspBaseQP <= 22)
m_sliceReshapeInfo.sliceReshaperModelPresentFlag = false;
m_reshape = false;
for (int b = 0; b < PIC_ANALYZE_CW_BINS; b++)
{
m_sliceReshapeInfo.reshaperModelMinBinIdx = startBinIdx;
m_sliceReshapeInfo.reshaperModelMaxBinIdx = endBinIdx;
m_initCWAnalyze = m_lumaBD > 10 ? (m_initCWAnalyze >> (m_lumaBD - 10)) : m_lumaBD < 10 ? (m_initCWAnalyze << (10 - m_lumaBD)) : m_initCWAnalyze;
{
for (int i = 0; i < PIC_ANALYZE_CW_BINS; i++)
{
if (i >= startBinIdx && i <= endBinIdx)
m_binCW[i] = m_initCWAnalyze + 1;
deriveReshapeParameters(blockBinVarSum, startBinIdx, endBinIdx, m_reshapeCW, Alpha, Beta);
for (int i = 0; i < PIC_ANALYZE_CW_BINS; i++)
{
if (i >= startBinIdx && i <= endBinIdx)
for (int b = startBinIdx; b <= endBinIdx; b++)
if (blockBinVarSum[b] < reshapeTH1)
m_binImportance[b] = 2;
else if (blockBinVarSum[b] > reshapeTH2)
m_binImportance[b] = 3;
}
for (int i = 0; i < PIC_ANALYZE_CW_BINS; i++)
{
else if (m_binImportance[i] == 2)
m_binCW[i] = m_reshapeCW.binCW[0];
else if (m_binImportance[i] == 3)
m_binCW[i] = m_reshapeCW.binCW[1];
else
THROW("SDR Reshape Bin Importance not supported");
}
}
if (m_reshapeCW.rspPicSize <= 1497600 && reshapeCW.rspIntraPeriod == -1 && modIP == 0 && sliceType != I_SLICE)
#else
if ((sliceType == I_SLICE || (sliceType == P_SLICE && isIBC)) && isDualT)
#endif
m_sliceReshapeInfo.sliceReshaperModelPresentFlag = false;
m_sliceReshapeInfo.enableChromaAdj = m_chromaAdj;
bool enableRsp = m_tcase == 5 ? false : (m_tcase < 5 ? (cTid < m_tcase + 1 ? false : true) : (cTid <= 10 - m_tcase ? true : false));
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
}
}
}
// Bubble Sort to descending order with index
void EncReshape::bubbleSortDsd(double* array, int * idx, int n)
{
int i, j;
bool swapped;
for (i = 0; i < n - 1; i++)
{
swapped = false;
for (j = 0; j < n - i - 1; j++)
{
if (array[j] < array[j + 1])
{
swap(&array[j], &array[j + 1]);
swap(&idx[j], &idx[j + 1]);
swapped = true;
}
}
if (swapped == false)
break;
}
}
void EncReshape::deriveReshapeParametersSDRfromStats(uint32_t * blockBinCnt, double *blockBinVarSum, double* reshapeTH1, double* reshapeTH2, bool *intraAdp, bool *interAdp)
int binIdxSortDsd[PIC_ANALYZE_CW_BINS] = { 0 };
double binVarSortDsd[PIC_ANALYZE_CW_BINS] = { 0.0 };
double binHist[PIC_ANALYZE_CW_BINS] = { 0.0 };
double binVarSortDsdCDF[PIC_ANALYZE_CW_BINS] = { 0.0 };
double maxBinVar = 0.0, meanBinVar = 0.0, minBinVar = 5.0;
int nonZeroBinCt = 0;
int firstBinVarLessThanVal1 = 0;
int firstBinVarLessThanVal2 = 0;
int firstBinVarLessThanVal3 = 0;
int firstBinVarLessThanVal4 = 0;
for (int b = 0; b < PIC_ANALYZE_CW_BINS; b++)
{
binHist[b] = (double) blockBinCnt[b] / (double)(m_reshapeCW.rspPicSize);
if (binHist[b] > 0.001)
meanBinVar += blockBinVarSum[b];
if (blockBinVarSum[b] > maxBinVar) { maxBinVar = blockBinVarSum[b]; }
if (blockBinVarSum[b] < minBinVar) { minBinVar = blockBinVarSum[b]; }
if ((binHist[0] + binHist[1] + binHist[PIC_ANALYZE_CW_BINS - 2] + binHist[PIC_ANALYZE_CW_BINS - 1]) > 0.01) { m_exceedSTD = true; }
if ((binHist[PIC_ANALYZE_CW_BINS - 2] + binHist[PIC_ANALYZE_CW_BINS - 1]) > 0.01) { *interAdp = false; return; }
else { *interAdp = true; }
meanBinVar = meanBinVar / (double)nonZeroBinCt;
bubbleSortDsd(binVarSortDsd, binIdxSortDsd, PIC_ANALYZE_CW_BINS);
binVarSortDsdCDF[0] = binHist[binIdxSortDsd[0]];
for (int b = 1; b < PIC_ANALYZE_CW_BINS; b++)
{
binVarSortDsdCDF[b] = binVarSortDsdCDF[b - 1] + binHist[binIdxSortDsd[b]];
}
for (int b = 0; b < PIC_ANALYZE_CW_BINS - 1; b++)
{
if (binVarSortDsd[b] > 3.5) { firstBinVarLessThanVal1 = b + 1; }
if (binVarSortDsd[b] > 3.0) { firstBinVarLessThanVal2 = b + 1; }
if (binVarSortDsd[b] > 2.5) { firstBinVarLessThanVal3 = b + 1; }
if (binVarSortDsd[b] > 2.0) { firstBinVarLessThanVal4 = b + 1; }
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.4;
*reshapeTH2 = 4.5;
m_rateAdpMode = 2;
if (meanBinVar >= 2.52)
{
else if (binVarSortDsdCDF[firstBinVarLessThanVal2] < 0.1 && binVarSortDsdCDF[firstBinVarLessThanVal1] > 0.02)
m_reshapeCW.binCW[0] = 34;
*reshapeTH1 = 3.4;
*reshapeTH2 = 4.0;
m_reshapeCW.binCW[0] = 40;
*reshapeTH1 = 2.2;
*reshapeTH2 = 4.5;
m_rateAdpMode = 0;
}
}
else
{
if (maxBinVar > 3.3)
{
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.5;
*reshapeTH2 = 4.5;
double diff1 = binVarSortDsdCDF[firstBinVarLessThanVal4] - binVarSortDsdCDF[firstBinVarLessThanVal3];
double diff2 = binVarSortDsdCDF[firstBinVarLessThanVal2] - binVarSortDsdCDF[firstBinVarLessThanVal1];
if (diff1 > 0.4 || binVarSortDsdCDF[firstBinVarLessThanVal1] > 0.1)
else if (diff2 <= 0.1 && binVarSortDsdCDF[firstBinVarLessThanVal4] > 0.99 && binVarSortDsdCDF[firstBinVarLessThanVal3] > 0.642 && binVarSortDsdCDF[firstBinVarLessThanVal2] > 0.03)
m_rateAdpMode = 1;
}
else
{
m_rateAdpMode = 2;
}
}
}
else
{
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.6;
*reshapeTH2 = 4.5;
if (binVarSortDsdCDF[firstBinVarLessThanVal2] > 0.5 && maxBinVar < 4.7)
m_rateAdpMode = 2;
if (maxBinVar > 2.4)
{
if (binVarSortDsdCDF[firstBinVarLessThanVal4] > 0.88)
*reshapeTH1 = 2.5;
*reshapeTH2 = 4.0;
m_reshapeCW.binCW[0] = 36;
m_sliceReshapeInfo.enableChromaAdj = 0;
m_useAdpCW = true;
m_reshapeCW.binCW[0] = 36;
m_reshapeCW.binCW[1] = 30;
*reshapeTH1 = 2.2;
*reshapeTH2 = 4.0;
m_reshapeCW.binCW[0] = 36;
m_sliceReshapeInfo.enableChromaAdj = 0;
m_useAdpCW = true;
m_reshapeCW.binCW[0] = 38;
m_reshapeCW.binCW[1] = 28;
}
}
}
else
{
if (maxBinVar > 2.24)
{
m_useAdpCW = true;
m_reshapeCW.binCW[0] = 34;
m_reshapeCW.binCW[1] = 30;
{
int firstVarCDFLargerThanVal = 1;
for (int b = 0; b < PIC_ANALYZE_CW_BINS; b++)
{
{
firstVarCDFLargerThanVal = b;
break;
}
}
if (meanBinVar < 2.52 || binVarSortDsdCDF[firstBinVarLessThanVal2] > 0.5)
*reshapeTH1 = 2.2;
*reshapeTH2 = (binVarSortDsd[firstVarCDFLargerThanVal] + binVarSortDsd[firstVarCDFLargerThanVal - 1]) / 2.0;
else if (binVarSortDsdCDF[firstBinVarLessThanVal2] < 0.1 && binVarSortDsdCDF[firstBinVarLessThanVal1] > 0.02)
}
}
else
{
if (maxBinVar > 3.3)
{
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.5;
*reshapeTH2 = 4.5;
if (binVarSortDsdCDF[firstBinVarLessThanVal2] < 0.33 && m_reshapeCW.rspFps>40)
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 3.0;
*reshapeTH2 = 4.0;
m_rateAdpMode = 2;
if (maxBinVar < 2.4)
{
m_tcase = 3;
}
else if (maxBinVar > 3.0)
{
if (minBinVar > 1)
{
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.8;
*reshapeTH2 = 3.5;
m_sliceReshapeInfo.enableChromaAdj = 0;
m_chromaWeight = 1.05;
m_rateAdpMode = 0;
}
else
{
m_reshapeCW.binCW[0] = 36;
*reshapeTH1 = 2.2;
*reshapeTH2 = 3.5;
m_sliceReshapeInfo.enableChromaAdj = 0;
m_chromaWeight = 0.95;
}
}
else
{
m_rateAdpMode = 0;
m_tcase = 9;
}
else
{
else if (binVarSortDsdCDF[firstBinVarLessThanVal2] < 0.1 && binVarSortDsdCDF[firstBinVarLessThanVal1] > 0.02)
*reshapeTH1 = 2.4;
*reshapeTH2 = 4.5;
m_reshapeCW.binCW[0] = 40;
}
}
else
{
if (maxBinVar > 3.3)
{
*reshapeTH1 = 3.0;
*reshapeTH2 = 4.0;
m_reshapeCW.binCW[1] = 30;
m_reshapeCW.binCW[1] = 30;
*reshapeTH1 = 2.5;
*reshapeTH2 = 4.5;
*intraAdp = true;
m_rateAdpMode = 1;
if (minBinVar > 2.6)
{
m_rateAdpMode = 0;
m_tcase = 9;
}
else {
double diff1 = binVarSortDsdCDF[firstBinVarLessThanVal4] - binVarSortDsdCDF[firstBinVarLessThanVal3];
double diff2 = binVarSortDsdCDF[firstBinVarLessThanVal2] - binVarSortDsdCDF[firstBinVarLessThanVal1];
if (diff1 > 0.4 || binVarSortDsdCDF[firstBinVarLessThanVal1] > 0.1)
*reshapeTH1 = 2.9;
if (binVarSortDsdCDF[firstBinVarLessThanVal4] > 0.99 && binVarSortDsdCDF[firstBinVarLessThanVal3] > 0.642 && binVarSortDsdCDF[firstBinVarLessThanVal2] > 0.03)
{
m_rateAdpMode = 0;
m_tcase = 9;
}
}
}
}
}
else
{