[x265] [PATCH 14/14] Cleanup and Fix warnings
Mahesh Pittala
mahesh at multicorewareinc.com
Fri Oct 21 09:37:03 UTC 2022
14 patches pushed to the master branch.
On Wed, Oct 19, 2022 at 1:10 PM Snehaa Giridharan <
snehaa at multicorewareinc.com> wrote:
> From 7532117d7a4161b05df3f80103ff149699688d82 Mon Sep 17 00:00:00 2001
> From: Snehaa Giridharan <snehaa at multicorewareinc.com>
> Date: Wed, 19 Oct 2022 12:40:51 +0530
> Subject: [PATCH] Cleanup and Fix warnings
>
> Also modifies cli.rst
> ---
> doc/reST/cli.rst | 5 +
> source/CMakeLists.txt | 2 +-
> source/common/temporalfilter.cpp | 228 +------------------------------
> source/common/temporalfilter.h | 11 --
> source/encoder/dpb.cpp | 2 +-
> 5 files changed, 10 insertions(+), 238 deletions(-)
>
> diff --git a/doc/reST/cli.rst b/doc/reST/cli.rst
> index be32fc6cc..9fa12fa92 100755
> --- a/doc/reST/cli.rst
> +++ b/doc/reST/cli.rst
> @@ -1328,6 +1328,11 @@ Temporal / motion search options
> Search range for HME level 0, 1 and 2.
> The Search Range for each HME level must be between 0 and
> 32768(excluding).
> Default search range is 16,32,48 for level 0,1,2 respectively.
> +
> +.. option:: --mcstf, --no-mcstf
> +
> + Enable Motion Compensated Temporal filtering.
> + Default: disabled
>
> Spatial/intra options
> =====================
> diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
> index 8a93a8bc4..04ceea0ec 100755
> --- a/source/CMakeLists.txt
> +++ b/source/CMakeLists.txt
> @@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CPU" OFF)
> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
> # X265_BUILD must be incremented each time the public API is changed
> -set(X265_BUILD 205)
> +set(X265_BUILD 206)
> configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
> "${PROJECT_BINARY_DIR}/x265.def")
> configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
> diff --git a/source/common/temporalfilter.cpp
> b/source/common/temporalfilter.cpp
> index d178c5800..01a6ddf15 100644
> --- a/source/common/temporalfilter.cpp
> +++ b/source/common/temporalfilter.cpp
> @@ -494,113 +494,6 @@ void TemporalFilter::applyMotion(MV *mvs, uint32_t
> mvsStride, PicYuv *input, Pic
> }
> }
>
> -#if 0
> -/*
> -* Old Version: bilateralFilter
> -*/
> -void TemporalFilter::bilateralFilter(Frame* frame,
> - TemporalFilterRefPicInfo* m_mcstfRefList,
> - double overallStrength)
> -{
> -
> - const int numRefs = frame->m_mcstf->m_numRef;
> -
> - for (int i = 0; i < numRefs; i++)
> - {
> - TemporalFilterRefPicInfo *ref = &m_mcstfRefList[i];
> - applyMotion(m_mcstfRefList[i].mvs, m_mcstfRefList[i].mvsStride,
> m_mcstfRefList[i].picBuffer, ref->compensatedPic);
> - }
> -
> - int refStrengthRow = 2;
> - if (numRefs == m_range * 2)
> - {
> - refStrengthRow = 0;
> - }
> - else if (numRefs == m_range)
> - {
> - refStrengthRow = 1;
> - }
> -
> - const double lumaSigmaSq = (m_QP - m_sigmaZeroPoint) * (m_QP -
> m_sigmaZeroPoint) * m_sigmaMultiplier;
> - const double chromaSigmaSq = 30 * 30;
> -
> - PicYuv* orgPic = frame->m_fencPic;
> -
> - for (int c = 0; c < m_numComponents; c++)
> - {
> - int height, width;
> - pixel *srcPelRow = NULL;
> - intptr_t srcStride, correctedPicsStride = 0;
> -
> - if (!c)
> - {
> - height = orgPic->m_picHeight;
> - width = orgPic->m_picWidth;
> - srcPelRow = orgPic->m_picOrg[c];
> - srcStride = orgPic->m_stride;
> - }
> - else
> - {
> - int csx = CHROMA_H_SHIFT(m_internalCsp);
> - int csy = CHROMA_V_SHIFT(m_internalCsp);
> -
> - height = orgPic->m_picHeight >> csy;
> - width = orgPic->m_picWidth >> csx;
> - srcPelRow = orgPic->m_picOrg[c];
> - srcStride = (int)orgPic->m_strideC;
> - }
> -
> - const double sigmaSq = (!c) ? lumaSigmaSq : chromaSigmaSq;
> - const double weightScaling = overallStrength * ((!c) ? 0.4 :
> m_chromaFactor);
> -
> - const pixel maxSampleValue = (1 << m_bitDepth) - 1;
> - const double bitDepthDiffWeighting = 1024.0 / (maxSampleValue +
> 1);
> -
> - for (int y = 0; y < height; y++, srcPelRow += srcStride)
> - {
> - pixel *srcPel = srcPelRow;
> -
> - for (int x = 0; x < width; x++, srcPel++)
> - {
> - const int orgVal = (int)*srcPel;
> - double temporalWeightSum = 1.0;
> - double newVal = (double)orgVal;
> -
> - for (int i = 0; i < numRefs; i++)
> - {
> - TemporalFilterRefPicInfo *refPicInfo =
> &m_mcstfRefList[i];
> -
> - if (!c)
> - correctedPicsStride =
> refPicInfo->compensatedPic->m_stride;
> - else
> - correctedPicsStride =
> refPicInfo->compensatedPic->m_strideC;
> -
> - const pixel *pCorrectedPelPtr =
> refPicInfo->compensatedPic->m_picOrg[c] + (y * correctedPicsStride + x);
> - const int refVal = (int)*pCorrectedPelPtr;
> - double diff = (double)(refVal - orgVal);
> - diff *= bitDepthDiffWeighting;
> - double diffSq = diff * diff;
> -
> - const int index = X265_MIN(1,
> std::abs(refPicInfo->origOffset) - 1);
> - const double weight = weightScaling *
> s_refStrengths[refStrengthRow][index] * exp(-diffSq / (2 * sigmaSq));
> -
> - newVal += weight * refVal;
> - temporalWeightSum += weight;
> - }
> - newVal /= temporalWeightSum;
> - pixel sampleVal = (pixel)round(newVal);
> - sampleVal = (sampleVal < 0 ? 0 : (sampleVal >
> maxSampleValue ? maxSampleValue : sampleVal));
> - *srcPel = sampleVal;
> - }
> - }
> - }
> -}
> -
> -#else
> -
> -/*
> -* New Version: bilateralFilter
> -*/
> void TemporalFilter::bilateralFilter(Frame* frame,
> TemporalFilterRefPicInfo* m_mcstfRefList,
> double overallStrength)
> @@ -656,7 +549,7 @@ void TemporalFilter::bilateralFilter(Frame* frame,
> const double sigmaSq = (!c) ? lumaSigmaSq : chromaSigmaSq;
> const double weightScaling = overallStrength * ( (!c) ? 0.4 :
> m_chromaFactor);
>
> - const pixel maxSampleValue = (1 << m_bitDepth) - 1;
> + const double maxSampleValue = (1 << m_bitDepth) - 1;
> const double bitDepthDiffWeighting = 1024.0 / (maxSampleValue +
> 1);
>
> const int blkSize = (!c) ? 8 : 4;
> @@ -742,128 +635,14 @@ void TemporalFilter::bilateralFilter(Frame* frame,
> temporalWeightSum += weight;
> }
> newVal /= temporalWeightSum;
> - pixel sampleVal = (pixel)round(newVal);
> + double sampleVal = round(newVal);
> sampleVal = (sampleVal < 0 ? 0 : (sampleVal >
> maxSampleValue ? maxSampleValue : sampleVal));
> - *srcPel = sampleVal;
> - }
> - }
> - }
> -}
> -#endif
> -
> -#if 0
> -/*Old Version: motionEstimationLuma*/
> -
> -void TemporalFilter::motionEstimationLuma(MV *mvs, uint32_t mvStride,
> PicYuv *orig, PicYuv *buffer, int blockSize,
> - MV *previous, uint32_t prevMvStride, int factor, bool doubleRes, int*
> minError)
> -{
> -
> - int range = 5;
> -
> -
> - const int stepSize = blockSize;
> -
> - const int origWidth = orig->m_picWidth;
> - const int origHeight = orig->m_picHeight;
> -
> -
> - for (int blockY = 0; blockY + blockSize < origHeight; blockY +=
> stepSize)
> - {
> - for (int blockX = 0; blockX + blockSize < origWidth; blockX +=
> stepSize)
> - {
> - MV best(0, 0);
> - int leastError = INT_MAX;
> -
> - if (previous == NULL)
> - {
> - range = 8;
> - }
> - else
> - {
> -
> - for (int py = -2; py <= 2; py++)
> - {
> - int testy = blockY / (2 * blockSize) + py;
> -
> - for (int px = -2; px <= 2; px++)
> - {
> -
> - int testx = blockX / (2 * blockSize) + px;
> - if ((testx >= 0) && (testx < origWidth / (2 *
> blockSize)) && (testy >= 0) && (testy < origHeight / (2 * blockSize)))
> - {
> - int mvIdx = testy * prevMvStride + testx;
> - MV old = previous[mvIdx];
> -
> - int error = motionErrorLuma(orig, buffer,
> blockX, blockY, old.x * factor, old.y * factor, blockSize, leastError);
> - if (error < leastError)
> - {
> - best.set(old.x * factor, old.y * factor);
> - leastError = error;
> - }
> - }
> - }
> - }
> -
> - }
> -
> - MV prevBest = best;
> - for (int y2 = prevBest.y / s_motionVectorFactor - range; y2
> <= prevBest.y / s_motionVectorFactor + range; y2++)
> - {
> - for (int x2 = prevBest.x / s_motionVectorFactor - range;
> x2 <= prevBest.x / s_motionVectorFactor + range; x2++)
> - {
> - int error = motionErrorLuma(orig, buffer, blockX,
> blockY, x2 * s_motionVectorFactor, y2 * s_motionVectorFactor, blockSize,
> leastError/*best.error*/);
> - if (error < leastError)
> - {
> - best.set(x2 * s_motionVectorFactor, y2 *
> s_motionVectorFactor);
> - leastError = error;
> - }
> - }
> - }
> -
> - if (doubleRes)
> - { // merge into one loop, probably with precision array (here
> [12, 3] or maybe [4, 1]) with setable number of iterations
> - prevBest = best;
> - int doubleRange = 3 * 4;
> - for (int y2 = prevBest.y - doubleRange; y2 <= prevBest.y
> + doubleRange; y2 += 4)
> - {
> - for (int x2 = prevBest.x - doubleRange; x2 <=
> prevBest.x + doubleRange; x2 += 4)
> - {
> - int error = motionErrorLuma(orig, buffer, blockX,
> blockY, x2, y2, blockSize, leastError);
> - if (error < leastError)
> - {
> - best.set(x2, y2);
> - leastError = error;
> - }
> - }
> - }
> -
> - prevBest = best;
> - doubleRange = 3;
> - for (int y2 = prevBest.y - doubleRange; y2 <= prevBest.y
> + doubleRange; y2++)
> - {
> - for (int x2 = prevBest.x - doubleRange; x2 <=
> prevBest.x + doubleRange; x2++)
> - {
> - int error = motionErrorLuma(orig, buffer, blockX,
> blockY, x2, y2, blockSize, leastError);
> - if (error < leastError)
> - {
> - best.set(x2, y2);
> - leastError = error;
> - }
> - }
> - }
> + *srcPel = (pixel)sampleVal;
> }
> -
> - int mvIdx = (blockY / stepSize) * mvStride + (blockX /
> stepSize);
> - mvs[mvIdx] = best;
> - if (doubleRes)
> - minError[mvIdx] = leastError;
> }
> }
> }
>
> -#else
> -
> -/*New Version: motionEstimationLuma*/
> void TemporalFilter::motionEstimationLuma(MV *mvs, uint32_t mvStride,
> PicYuv *orig, PicYuv *buffer, int blockSize,
> MV *previous, uint32_t prevMvStride, int factor)
> {
> @@ -1211,7 +990,6 @@ void TemporalFilter::motionEstimationLumaDoubleRes(MV
> *mvs, uint32_t mvStride, P
> }
> }
> }
> -#endif
>
> void TemporalFilter::destroyRefPicInfo(TemporalFilterRefPicInfo* curFrame)
> {
> diff --git a/source/common/temporalfilter.h
> b/source/common/temporalfilter.h
> index 55ae6736d..10f0c52b4 100644
> --- a/source/common/temporalfilter.h
> +++ b/source/common/temporalfilter.h
> @@ -35,8 +35,6 @@
>
> using namespace X265_NS;
>
> -#define BILTERAL_FILTER_NEW_VERSION 1
> -
> const int s_interpolationFilter[16][8] =
> {
> { 0, 0, 0, 64, 0, 0, 0, 0 }, //0
> @@ -57,7 +55,6 @@ const int s_interpolationFilter[16][8] =
> { 0, 0, -2, 4, 64, -3, 1, 0 } //15-->-->
> };
>
> -#if BILTERAL_FILTER_NEW_VERSION
> const double s_refStrengths[3][4] =
> { // abs(POC offset)
> // 1, 2 3 4
> @@ -65,14 +62,6 @@ const double s_refStrengths[3][4] =
> {1.13, 0.97, 0.81, 0.57}, // m_range
> {0.30, 0.30, 0.30, 0.30} // otherwise
> };
> -#else
> -const double s_refStrengths[2][2] =
> -{ // abs(POC offset)
> - // 1, 2
> - {0.85, 0.60}, // w future refs
> - {1.20, 1.00}, // w/o future refs
> -};
> -#endif
>
> class OrigPicBuffer
> {
> diff --git a/source/encoder/dpb.cpp b/source/encoder/dpb.cpp
> index 9292b6c75..79274f5dd 100644
> --- a/source/encoder/dpb.cpp
> +++ b/source/encoder/dpb.cpp
> @@ -73,7 +73,7 @@ void DPB::recycleUnreferenced()
> bool isMCSTFReferenced = false;
>
> if (curFrame->m_param->bEnableTemporalFilter)
> - isMCSTFReferenced = curFrame->m_refPicCnt[1];
> + isMCSTFReferenced =!!(curFrame->m_refPicCnt[1]);
>
> if (!curFrame->m_encData->m_bHasReferences &&
> !curFrame->m_countRefEncoders && !isMCSTFReferenced)
> {
> --
> 2.37.2.windows.2
>
>
> *Thanks and Regards,*
>
>
>
>
>
> *Snehaa.GVideo Codec Engineer,Media & AI analytics
> <https://multicorewareinc.com/>*
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20221021/368f96da/attachment-0001.html>
More information about the x265-devel
mailing list