[x265] [PATCH] search: made separate functions for encoding cbfs in xEstimateResidualQT()
ashok at multicorewareinc.com
ashok at multicorewareinc.com
Wed Nov 5 16:06:20 CET 2014
# HG changeset patch
# User Ashok Kumar Mishra<ashok at multicorewareinc.com>
# Date 1415199866 -19800
# Wed Nov 05 20:34:26 2014 +0530
# Node ID a1902139ce82796caa570405b63cbb78fc6fd442
# Parent 18344f74ded0e192bc7177a217e9112c9de31983
search: made separate functions for encoding cbfs in xEstimateResidualQT()
diff -r 18344f74ded0 -r a1902139ce82 source/encoder/search.cpp
--- a/source/encoder/search.cpp Wed Nov 05 16:23:42 2014 +0530
+++ b/source/encoder/search.cpp Wed Nov 05 20:34:26 2014 +0530
@@ -3208,10 +3208,10 @@
m_entropyCoder.load(m_rqt[depth].rqtRoot);
m_entropyCoder.resetBits();
- encodeResidualQT(cu, absPartIdx, depth, true, TEXT_LUMA, depthRange);
- encodeResidualQT(cu, absPartIdx, depth, false, TEXT_LUMA, depthRange);
- encodeResidualQT(cu, absPartIdx, depth, false, TEXT_CHROMA_U, depthRange);
- encodeResidualQT(cu, absPartIdx, depth, false, TEXT_CHROMA_V, depthRange);
+ codeInterSubdivCbfQT(cu, absPartIdx, depth, depthRange);
+ encodeResidualQT(cu, absPartIdx, depth, TEXT_LUMA, depthRange);
+ encodeResidualQT(cu, absPartIdx, depth, TEXT_CHROMA_U, depthRange);
+ encodeResidualQT(cu, absPartIdx, depth, TEXT_CHROMA_V, depthRange);
splitCost.bits = m_entropyCoder.getNumberOfWrittenBits();
@@ -3283,51 +3283,87 @@
outCosts.energy += fullCost.energy;
}
-void Search::encodeResidualQT(CUData& cu, uint32_t absPartIdx, const uint32_t depth, bool bSubdivAndCbf, TextType ttype, uint32_t depthRange[2])
+void Search::codeInterSubdivCbfQT(CUData& cu, uint32_t absPartIdx, const uint32_t depth, uint32_t depthRange[2])
{
X265_CHECK(cu.m_cuDepth[0] == cu.m_cuDepth[absPartIdx], "depth not matching\n");
- X265_CHECK(cu.isInter(absPartIdx), "encodeResidualQT() with intra block\n");
+ X265_CHECK(cu.isInter(absPartIdx), "codeInterSubdivCbfQT() with intra block\n");
const uint32_t curTuDepth = depth - cu.m_cuDepth[0];
const uint32_t tuDepth = cu.m_tuDepth[absPartIdx];
const bool bSubdiv = curTuDepth != tuDepth;
const uint32_t log2TrSize = g_maxLog2CUSize - depth;
+ if (log2TrSize <= depthRange[1] && log2TrSize > depthRange[0])
+ m_entropyCoder.codeTransformSubdivFlag(bSubdiv, 5 - log2TrSize);
+
+ const bool splitIntoSubTUs = (m_csp == X265_CSP_I422);
uint32_t log2TrSizeC = log2TrSize - m_hChromaShift;
-
- const bool splitIntoSubTUs = (m_csp == X265_CSP_I422);
-
- if (bSubdivAndCbf && log2TrSize <= depthRange[1] && log2TrSize > depthRange[0])
- m_entropyCoder.codeTransformSubdivFlag(bSubdiv, 5 - log2TrSize);
-
- bool mCodeAll = true;
uint32_t trWidthC = 1 << log2TrSizeC;
uint32_t trHeightC = splitIntoSubTUs ? (trWidthC << 1) : trWidthC;
+ bool mCodeAll = true;
const uint32_t numPels = trWidthC * trHeightC;
if (numPels < (MIN_TU_SIZE * MIN_TU_SIZE))
mCodeAll = false;
- if (bSubdivAndCbf)
+ if (mCodeAll)
{
- const bool bFirstCbfOfCU = curTuDepth == 0;
- if (bFirstCbfOfCU || mCodeAll)
+ uint32_t absPartIdxStep = NUM_CU_PARTITIONS >> ((cu.m_cuDepth[0] + curTuDepth) << 1);
+ if (!curTuDepth || cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth - 1))
+ m_entropyCoder.codeQtCbf(cu, absPartIdx, absPartIdxStep, trWidthC, trHeightC, TEXT_CHROMA_U, curTuDepth, !bSubdiv);
+ if (!curTuDepth || cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth - 1))
+ m_entropyCoder.codeQtCbf(cu, absPartIdx, absPartIdxStep, trWidthC, trHeightC, TEXT_CHROMA_V, curTuDepth, !bSubdiv);
+ }
+ else
+ {
+ X265_CHECK(cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth) == cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth - 1), "chroma CBF not matching\n");
+ X265_CHECK(cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth) == cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth - 1), "chroma CBF not matching\n");
+ }
+
+ if (!bSubdiv)
+ {
+ m_entropyCoder.codeQtCbf(cu, absPartIdx, TEXT_LUMA, tuDepth);
+ }
+ else
+ {
+ const uint32_t qpartNumSubdiv = NUM_CU_PARTITIONS >> ((depth + 1) << 1);
+ for (uint32_t i = 0; i < 4; ++i)
+ codeInterSubdivCbfQT(cu, absPartIdx + i * qpartNumSubdiv, depth + 1, depthRange);
+ }
+}
+
+void Search::encodeResidualQT(CUData& cu, uint32_t absPartIdx, const uint32_t depth, TextType ttype, uint32_t depthRange[2])
+{
+ X265_CHECK(cu.m_cuDepth[0] == cu.m_cuDepth[absPartIdx], "depth not matching\n");
+ X265_CHECK(cu.isInter(absPartIdx), "encodeResidualQT() with intra block\n");
+
+ const uint32_t curTuDepth = depth - cu.m_cuDepth[0];
+ const uint32_t tuDepth = cu.m_tuDepth[absPartIdx];
+ const bool bSubdiv = curTuDepth != tuDepth;
+
+ if (bSubdiv)
+ {
+ if (cu.getCbf(absPartIdx, ttype, curTuDepth))
{
- uint32_t absPartIdxStep = NUM_CU_PARTITIONS >> ((cu.m_cuDepth[0] + curTuDepth) << 1);
- if (bFirstCbfOfCU || cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth - 1))
- m_entropyCoder.codeQtCbf(cu, absPartIdx, absPartIdxStep, trWidthC, trHeightC, TEXT_CHROMA_U, curTuDepth, !bSubdiv);
- if (bFirstCbfOfCU || cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth - 1))
- m_entropyCoder.codeQtCbf(cu, absPartIdx, absPartIdxStep, trWidthC, trHeightC, TEXT_CHROMA_V, curTuDepth, !bSubdiv);
- }
- else
- {
- X265_CHECK(cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth) == cu.getCbf(absPartIdx, TEXT_CHROMA_U, curTuDepth - 1), "chroma CBF not matching\n");
- X265_CHECK(cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth) == cu.getCbf(absPartIdx, TEXT_CHROMA_V, curTuDepth - 1), "chroma CBF not matching\n");
+ const uint32_t qpartNumSubdiv = NUM_CU_PARTITIONS >> ((depth + 1) << 1);
+ for (uint32_t i = 0; i < 4; ++i)
+ encodeResidualQT(cu, absPartIdx + i * qpartNumSubdiv, depth + 1, ttype, depthRange);
}
}
-
- if (!bSubdiv)
+ else
{
+ const uint32_t log2TrSize = g_maxLog2CUSize - depth;
+
+ const bool splitIntoSubTUs = (m_csp == X265_CSP_I422);
+ uint32_t log2TrSizeC = log2TrSize - m_hChromaShift;
+ uint32_t trWidthC = 1 << log2TrSizeC;
+ uint32_t trHeightC = splitIntoSubTUs ? (trWidthC << 1) : trWidthC;
+
+ bool mCodeAll = true;
+ const uint32_t numPels = trWidthC * trHeightC;
+ if (numPels < (MIN_TU_SIZE * MIN_TU_SIZE))
+ mCodeAll = false;
+
// Luma
const uint32_t qtLayer = log2TrSize - 2;
uint32_t coeffOffsetY = absPartIdx << (LOG2_UNIT_SIZE * 2);
@@ -3344,57 +3380,43 @@
bCodeChroma = ((absPartIdx & (qpdiv - 1)) == 0);
}
- if (bSubdivAndCbf)
- m_entropyCoder.codeQtCbf(cu, absPartIdx, TEXT_LUMA, tuDepth);
- else
+ if (ttype == TEXT_LUMA && cu.getCbf(absPartIdx, TEXT_LUMA, tuDepth))
+ m_entropyCoder.codeCoeffNxN(cu, coeffCurY, absPartIdx, log2TrSize, TEXT_LUMA);
+
+ if (bCodeChroma)
{
- if (ttype == TEXT_LUMA && cu.getCbf(absPartIdx, TEXT_LUMA, tuDepth))
- m_entropyCoder.codeCoeffNxN(cu, coeffCurY, absPartIdx, log2TrSize, TEXT_LUMA);
-
- if (bCodeChroma)
+ uint32_t coeffOffsetC = coeffOffsetY >> (m_hChromaShift + m_vChromaShift);
+ coeff_t* coeffCurU = m_rqt[qtLayer].coeffRQT[1] + coeffOffsetC;
+ coeff_t* coeffCurV = m_rqt[qtLayer].coeffRQT[2] + coeffOffsetC;
+
+ if (!splitIntoSubTUs)
{
- uint32_t coeffOffsetC = coeffOffsetY >> (m_hChromaShift + m_vChromaShift);
- coeff_t* coeffCurU = m_rqt[qtLayer].coeffRQT[1] + coeffOffsetC;
- coeff_t* coeffCurV = m_rqt[qtLayer].coeffRQT[2] + coeffOffsetC;
-
- if (!splitIntoSubTUs)
+ if (ttype == TEXT_CHROMA_U && cu.getCbf(absPartIdx, TEXT_CHROMA_U, tuDepth))
+ m_entropyCoder.codeCoeffNxN(cu, coeffCurU, absPartIdx, log2TrSizeC, TEXT_CHROMA_U);
+ if (ttype == TEXT_CHROMA_V && cu.getCbf(absPartIdx, TEXT_CHROMA_V, tuDepth))
+ m_entropyCoder.codeCoeffNxN(cu, coeffCurV, absPartIdx, log2TrSizeC, TEXT_CHROMA_V);
+ }
+ else
+ {
+ uint32_t partIdxesPerSubTU = NUM_CU_PARTITIONS >> (((cu.m_cuDepth[absPartIdx] + tuDepthC) << 1) + 1);
+ uint32_t subTUSize = 1 << (log2TrSizeC * 2);
+ if (ttype == TEXT_CHROMA_U && cu.getCbf(absPartIdx, TEXT_CHROMA_U, tuDepth))
{
- if (ttype == TEXT_CHROMA_U && cu.getCbf(absPartIdx, TEXT_CHROMA_U, tuDepth))
+ if (cu.getCbf(absPartIdx, ttype, tuDepth + 1))
m_entropyCoder.codeCoeffNxN(cu, coeffCurU, absPartIdx, log2TrSizeC, TEXT_CHROMA_U);
- if (ttype == TEXT_CHROMA_V && cu.getCbf(absPartIdx, TEXT_CHROMA_V, tuDepth))
+ if (cu.getCbf(absPartIdx + partIdxesPerSubTU, ttype, tuDepth + 1))
+ m_entropyCoder.codeCoeffNxN(cu, coeffCurU + subTUSize, absPartIdx + partIdxesPerSubTU, log2TrSizeC, TEXT_CHROMA_U);
+ }
+ if (ttype == TEXT_CHROMA_V && cu.getCbf(absPartIdx, TEXT_CHROMA_V, tuDepth))
+ {
+ if (cu.getCbf(absPartIdx, ttype, tuDepth + 1))
m_entropyCoder.codeCoeffNxN(cu, coeffCurV, absPartIdx, log2TrSizeC, TEXT_CHROMA_V);
- }
- else
- {
- uint32_t partIdxesPerSubTU = NUM_CU_PARTITIONS >> (((cu.m_cuDepth[absPartIdx] + tuDepthC) << 1) + 1);
- uint32_t subTUSize = 1 << (log2TrSizeC * 2);
- if (ttype == TEXT_CHROMA_U && cu.getCbf(absPartIdx, TEXT_CHROMA_U, tuDepth))
- {
- if (cu.getCbf(absPartIdx, ttype, tuDepth + 1))
- m_entropyCoder.codeCoeffNxN(cu, coeffCurU, absPartIdx, log2TrSizeC, TEXT_CHROMA_U);
- if (cu.getCbf(absPartIdx + partIdxesPerSubTU, ttype, tuDepth + 1))
- m_entropyCoder.codeCoeffNxN(cu, coeffCurU + subTUSize, absPartIdx + partIdxesPerSubTU, log2TrSizeC, TEXT_CHROMA_U);
- }
- if (ttype == TEXT_CHROMA_V && cu.getCbf(absPartIdx, TEXT_CHROMA_V, tuDepth))
- {
- if (cu.getCbf(absPartIdx, ttype, tuDepth + 1))
- m_entropyCoder.codeCoeffNxN(cu, coeffCurV, absPartIdx, log2TrSizeC, TEXT_CHROMA_V);
- if (cu.getCbf(absPartIdx + partIdxesPerSubTU, ttype, tuDepth + 1))
- m_entropyCoder.codeCoeffNxN(cu, coeffCurV + subTUSize, absPartIdx + partIdxesPerSubTU, log2TrSizeC, TEXT_CHROMA_V);
- }
+ if (cu.getCbf(absPartIdx + partIdxesPerSubTU, ttype, tuDepth + 1))
+ m_entropyCoder.codeCoeffNxN(cu, coeffCurV + subTUSize, absPartIdx + partIdxesPerSubTU, log2TrSizeC, TEXT_CHROMA_V);
}
}
}
}
- else
- {
- if (bSubdivAndCbf || cu.getCbf(absPartIdx, ttype, curTuDepth))
- {
- const uint32_t qpartNumSubdiv = NUM_CU_PARTITIONS >> ((depth + 1) << 1);
- for (uint32_t i = 0; i < 4; ++i)
- encodeResidualQT(cu, absPartIdx + i * qpartNumSubdiv, depth + 1, bSubdivAndCbf, ttype, depthRange);
- }
- }
}
void Search::saveResidualQTData(CUData& cu, ShortYuv& resiYuv, uint32_t absPartIdx, uint32_t depth)
diff -r 18344f74ded0 -r a1902139ce82 source/encoder/search.h
--- a/source/encoder/search.h Wed Nov 05 16:23:42 2014 +0530
+++ b/source/encoder/search.h Wed Nov 05 20:34:26 2014 +0530
@@ -206,6 +206,7 @@
uint32_t estIntraPredChromaQT(Mode &intraMode, const CUGeom& cuGeom);
void codeSubdivCbfQTChroma(const CUData& cu, uint32_t trDepth, uint32_t absPartIdx, uint32_t absPartIdxStep, uint32_t width, uint32_t height);
+ void codeInterSubdivCbfQT(CUData& cu, uint32_t absPartIdx, const uint32_t depth, uint32_t depthRange[2]);
void codeCoeffQTChroma(const CUData& cu, uint32_t trDepth, uint32_t absPartIdx, TextType ttype);
struct Cost
@@ -221,7 +222,7 @@
void estimateResidualQT(Mode& mode, const CUGeom& cuGeom, uint32_t absPartIdx, uint32_t depth, ShortYuv& resiYuv, Cost& costs, uint32_t depthRange[2]);
// estimate bit cost of residual QT
- void encodeResidualQT(CUData& cu, uint32_t absPartIdx, uint32_t depth, bool bSubdivAndCbf, TextType ttype, uint32_t depthRange[2]);
+ void encodeResidualQT(CUData& cu, uint32_t absPartIdx, uint32_t depth, TextType ttype, uint32_t depthRange[2]);
// generate prediction, generate residual and recon. if bAllowSplit, find optimal RQT splits
void codeIntraLumaQT(Mode& mode, const CUGeom& cuGeom, uint32_t trDepth, uint32_t absPartIdx, bool bAllowSplit, Cost& costs, uint32_t depthRange[2]);
More information about the x265-devel
mailing list