[x265] [PATCH] sao: only load/save entropy state of sao when applying sao
Ximing Cheng
chengximing1989 at foxmail.com
Sat Nov 18 13:55:34 CET 2017
# HG changeset patch
# User Ximing Cheng <ximingcheng at tencent.com>
# Date 1511009612 -28800
# Sat Nov 18 20:53:32 2017 +0800
# Node ID a5b805430a4b0cb797604ab7f0176538d93e8d9d
# Parent 06979c0423504a324ea05ca3de59769c6d0fba0d
sao: only load/save entropy state of sao when applying sao
diff -r 06979c042350 -r a5b805430a4b source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp Thu Nov 16 20:23:14 2017 +0530
+++ b/source/encoder/entropy.cpp Sat Nov 18 20:53:32 2017 +0800
@@ -1506,6 +1506,19 @@
markValid();
}
+void Entropy::copyFromSAO(const Entropy& src)
+{
+ X265_CHECK(src.m_valid, "invalid copy source context\n");
+
+ copyState(src);
+
+ // only copy OFF_SAO_MERGE_FLAG_CTX and OFF_SAO_TYPE_IDX_CTX, two bytes
+ uint16_t* srcEntropy = (uint16_t*)(src.m_contextState + OFF_SAO_MERGE_FLAG_CTX);
+ uint16_t* dstEntropy = (uint16_t*)(m_contextState + OFF_SAO_MERGE_FLAG_CTX);
+ *dstEntropy = *srcEntropy;
+ markValid();
+}
+
void Entropy::codePartSize(const CUData& cu, uint32_t absPartIdx, uint32_t depth)
{
PartSize partSize = (PartSize)cu.m_partSize[absPartIdx];
diff -r 06979c042350 -r a5b805430a4b source/encoder/entropy.h
--- a/source/encoder/entropy.h Thu Nov 16 20:23:14 2017 +0530
+++ b/source/encoder/entropy.h Sat Nov 18 20:53:32 2017 +0800
@@ -136,7 +136,9 @@
// SBAC RD
void load(const Entropy& src) { copyFrom(src); }
+ void loadSAO(const Entropy& src) { copyFromSAO(src); }
void store(Entropy& dest) const { dest.copyFrom(*this); }
+ void storeSAO(Entropy& dest) const { dest.copyFromSAO(*this); }
void loadContexts(const Entropy& src) { copyContextsFrom(src); }
void loadIntraDirModeLuma(const Entropy& src);
void copyState(const Entropy& other);
@@ -254,6 +256,7 @@
bool& bCodeDQP, const uint32_t depthRange[2]);
void copyFrom(const Entropy& src);
+ void copyFromSAO(const Entropy& src);
void copyContextsFrom(const Entropy& src);
};
}
diff -r 06979c042350 -r a5b805430a4b source/encoder/sao.cpp
--- a/source/encoder/sao.cpp Thu Nov 16 20:23:14 2017 +0530
+++ b/source/encoder/sao.cpp Sat Nov 18 20:53:32 2017 +0800
@@ -242,9 +242,9 @@
break;
}
- m_entropyCoder.load(initState);
- m_rdContexts.next.load(initState);
- m_rdContexts.cur.load(initState);
+ m_entropyCoder.loadSAO(initState);
+ m_rdContexts.next.loadSAO(initState);
+ m_rdContexts.cur.loadSAO(initState);
SAOParam* saoParam = frame->m_encData->m_saoParam;
if (!saoParam)
@@ -1262,13 +1262,13 @@
for (int i = 0; i < planes; i++)
saoParam->ctuParam[i][addr].reset();
// SAO distortion calculation
- m_entropyCoder.load(m_rdContexts.cur);
+ m_entropyCoder.loadSAO(m_rdContexts.cur);
m_entropyCoder.resetBits();
if (allowMerge[0])
m_entropyCoder.codeSaoMerge(0);
if (allowMerge[1])
m_entropyCoder.codeSaoMerge(0);
- m_entropyCoder.store(m_rdContexts.temp);
+ m_entropyCoder.storeSAO(m_rdContexts.temp);
memset(m_offset, 0, sizeof(m_offset));
int64_t bestCost = 0;
int64_t rateDist = 0;
@@ -1333,7 +1333,7 @@
mergeDist += (estDist << 8) / lambda[!!plane];
}
- m_entropyCoder.load(m_rdContexts.cur);
+ m_entropyCoder.loadSAO(m_rdContexts.cur);
m_entropyCoder.resetBits();
if (allowMerge[0])
m_entropyCoder.codeSaoMerge(1 - mergeIdx);
@@ -1346,7 +1346,7 @@
{
SaoMergeMode mergeMode = mergeIdx ? SAO_MERGE_UP : SAO_MERGE_LEFT;
bestCost = mergeCost;
- m_entropyCoder.store(m_rdContexts.temp);
+ m_entropyCoder.storeSAO(m_rdContexts.temp);
for (int plane = 0; plane < planes; plane++)
{
if (saoParam->bSaoFlag[plane > 0])
@@ -1368,8 +1368,8 @@
m_numNoSao[0]++;
if (chroma && saoParam->ctuParam[1][addr].typeIdx < 0)
m_numNoSao[1]++;
- m_entropyCoder.load(m_rdContexts.temp);
- m_entropyCoder.store(m_rdContexts.cur);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
+ m_entropyCoder.storeSAO(m_rdContexts.cur);
}
}
@@ -1488,7 +1488,7 @@
int64_t costClasses[MAX_NUM_SAO_CLASS];
// RDO SAO_NA
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
m_entropyCoder.codeSaoType(0);
int64_t costPartBest = calcSaoRdoCost(0, m_entropyCoder.getNumberOfWrittenBits(), lambda[0]);
@@ -1518,7 +1518,7 @@
estDist += distClasses[classIdx];
}
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
m_entropyCoder.codeSaoOffsetEO(m_offset[0][typeIdx] + 1, typeIdx, 0);
@@ -1576,7 +1576,7 @@
for (int classIdx = bestClassBO; classIdx < bestClassBO + SAO_NUM_OFFSET; classIdx++)
estDist += distClasses[classIdx];
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
m_entropyCoder.codeSaoOffsetBO(m_offset[0][SAO_BO] + bestClassBO, bestClassBO, 0);
@@ -1595,9 +1595,9 @@
}
rateDist = (bestDist << 8) / lambda[0];
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.codeSaoOffset(*lclCtuParam, 0);
- m_entropyCoder.store(m_rdContexts.temp);
+ m_entropyCoder.storeSAO(m_rdContexts.temp);
if (m_param->internalCsp == X265_CSP_I400)
{
@@ -1616,7 +1616,7 @@
int32_t distClasses[MAX_NUM_SAO_CLASS];
int32_t bestClassBO[2] = { 0, 0 };
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
m_entropyCoder.codeSaoType(0);
@@ -1651,7 +1651,7 @@
}
}
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
for (int compIdx = 0; compIdx < 2; compIdx++)
@@ -1715,7 +1715,7 @@
estDist[compIdx - 1] += distClasses[classIdx];
}
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
m_entropyCoder.resetBits();
for (int compIdx = 0; compIdx < 2; compIdx++)
@@ -1740,13 +1740,13 @@
}
rateDist += (bestDist << 8) / lambda[1];
- m_entropyCoder.load(m_rdContexts.temp);
+ m_entropyCoder.loadSAO(m_rdContexts.temp);
if (saoParam->bSaoFlag[1])
{
m_entropyCoder.codeSaoOffset(*lclCtuParam[0], 1);
m_entropyCoder.codeSaoOffset(*lclCtuParam[1], 2);
- m_entropyCoder.store(m_rdContexts.temp);
+ m_entropyCoder.storeSAO(m_rdContexts.temp);
uint32_t rate = m_entropyCoder.getNumberOfWrittenBits();
bestCost = rateDist + rate;
More information about the x265-devel
mailing list