[x265] [PATCH 2 of 3] Add distortion offset
aruna at multicorewareinc.com
aruna at multicorewareinc.com
Tue Dec 27 13:44:04 CET 2016
# HG changeset patch
# User Aruna Matheswaran
# Date 1482815269 -19800
# Tue Dec 27 10:37:49 2016 +0530
# Node ID 372a31cfab8d39dba074d6095ae41839be45a49d
# Parent 14837a0999d7addfeb63daa5463716595d913c74
Add distortion offset
diff -r 14837a0999d7 -r 372a31cfab8d source/common/framedata.h
--- a/source/common/framedata.h Wed Dec 07 19:44:52 2016 +0530
+++ b/source/common/framedata.h Tue Dec 27 10:37:49 2016 +0530
@@ -194,6 +194,10 @@
double* scaledDistortion;
double averageDistortion;
double sdDistortion;
+ uint32_t highDistortionCtuCount;
+ uint32_t lowDistortionCtuCount;
+ double* offset;
+ double* threshold;
};
}
diff -r 14837a0999d7 -r 372a31cfab8d source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Dec 07 19:44:52 2016 +0530
+++ b/source/encoder/encoder.cpp Tue Dec 27 10:37:49 2016 +0530
@@ -2307,6 +2307,8 @@
{
CHECKED_MALLOC_ZERO(analysisFrameData->ctuDistortion, sse_t, numCUsInFrame);
CHECKED_MALLOC(analysisFrameData->scaledDistortion, double, numCUsInFrame);
+ CHECKED_MALLOC(analysisFrameData->offset, double, numCUsInFrame);
+ CHECKED_MALLOC(analysisFrameData->threshold, double, numCUsInFrame);
}
if (!IS_X265_TYPE_I(sliceType))
{
@@ -2338,6 +2340,8 @@
{
X265_FREE(((analysis2PassFrameData*)analysis->analysisFramedata)->ctuDistortion);
X265_FREE(((analysis2PassFrameData*)analysis->analysisFramedata)->scaledDistortion);
+ X265_FREE(((analysis2PassFrameData*)analysis->analysisFramedata)->offset);
+ X265_FREE(((analysis2PassFrameData*)analysis->analysisFramedata)->threshold);
}
if (!IS_X265_TYPE_I(sliceType))
{
@@ -2547,6 +2551,16 @@
double avg = sum / numCUsInFrame;
analysisFrameData->sdDistortion = pow(((sqrSum / numCUsInFrame) - (avg * avg)), 0.5);
analysisFrameData->averageDistortion = avg;
+ analysisFrameData->highDistortionCtuCount = analysisFrameData->lowDistortionCtuCount = 0;
+ for (uint32_t i = 0; i < numCUsInFrame; ++i)
+ {
+ analysisFrameData->threshold[i] = analysisFrameData->scaledDistortion[i] / analysisFrameData->averageDistortion;
+ analysisFrameData->offset[i] = (analysisFrameData->averageDistortion - analysisFrameData->scaledDistortion[i]) / analysisFrameData->sdDistortion;
+ if (analysisFrameData->threshold[i] < 0.9 && analysisFrameData->offset[i] >= 1)
+ analysisFrameData->lowDistortionCtuCount++;
+ else if (analysisFrameData->threshold[i] > 1.1 && analysisFrameData->offset[i] <= -1)
+ analysisFrameData->highDistortionCtuCount++;
+ }
if (!IS_X265_TYPE_I(sliceType))
{
MV *tempMVBuf[2], *MVBuf[2];
diff -r 14837a0999d7 -r 372a31cfab8d source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Wed Dec 07 19:44:52 2016 +0530
+++ b/source/encoder/frameencoder.cpp Tue Dec 27 10:37:49 2016 +0530
@@ -1311,6 +1311,10 @@
rowCoder.copyState(m_initSliceContext);
rowCoder.loadContexts(m_rows[row - 1].bufferedEntropy);
}
+ analysis2PassFrameData* analysisFrameData = (analysis2PassFrameData*)(m_frame->m_analysis2Pass).analysisFramedata;
+ if (analysisFrameData && m_param->rc.bStatRead && m_param->analysisMultiPassDistortion && (analysisFrameData->threshold[cuAddr] < 0.9 || analysisFrameData->threshold[cuAddr] > 1.1)
+ && analysisFrameData->highDistortionCtuCount && analysisFrameData->lowDistortionCtuCount)
+ curEncData.m_cuStat[cuAddr].baseQp += analysisFrameData->offset[cuAddr];
// Does all the CU analysis, returns best top level mode decision
Mode& best = tld.analysis.compressCTU(*ctu, *m_frame, m_cuGeoms[m_ctuGeomMap[cuAddr]], rowCoder);
More information about the x265-devel
mailing list