[x265] reduce xModeBitsIntra() call
Satoshi Nakagawa
nakagawa424 at oki.com
Fri May 9 09:51:53 CEST 2014
# HG changeset patch
# User Satoshi Nakagawa <nakagawa424 at oki.com>
# Date 1399621766 -32400
# Fri May 09 16:49:26 2014 +0900
# Node ID 29afccf47900d6be2f000b07edc4b5ce52b880e2
# Parent 129bfec3144f4521c9b2d2104f8ad66107d95f7c
reduce xModeBitsIntra() call
diff -r 129bfec3144f -r 29afccf47900 source/Lib/TLibCommon/TComDataCU.cpp
--- a/source/Lib/TLibCommon/TComDataCU.cpp Thu May 08 23:49:27 2014 -0500
+++ b/source/Lib/TLibCommon/TComDataCU.cpp Fri May 09 16:49:26 2014 +0900
@@ -1196,11 +1196,11 @@
*\param mode it is set with MPM mode in case both MPM are equal. It is used to restrict RD search at encode side.
*\returns Number of MPM
*/
-int TComDataCU::getIntraDirLumaPredictor(uint32_t absPartIdx, int32_t* intraDirPred)
+int TComDataCU::getIntraDirLumaPredictor(uint32_t absPartIdx, uint32_t* intraDirPred)
{
TComDataCU* tempCU;
uint32_t tempPartIdx;
- int leftIntraDir, aboveIntraDir;
+ uint32_t leftIntraDir, aboveIntraDir;
// Get intra direction of left PU
tempCU = getPULeft(tempPartIdx, m_absIdxInLCU + absPartIdx);
diff -r 129bfec3144f -r 29afccf47900 source/Lib/TLibCommon/TComDataCU.h
--- a/source/Lib/TLibCommon/TComDataCU.h Thu May 08 23:49:27 2014 -0500
+++ b/source/Lib/TLibCommon/TComDataCU.h Fri May 09 16:49:26 2014 +0900
@@ -431,7 +431,7 @@
// -------------------------------------------------------------------------------------------------------------------
void getAllowedChromaDir(uint32_t absPartIdx, uint32_t* modeList);
- int getIntraDirLumaPredictor(uint32_t absPartIdx, int32_t* intraDirPred);
+ int getIntraDirLumaPredictor(uint32_t absPartIdx, uint32_t* intraDirPred);
// -------------------------------------------------------------------------------------------------------------------
// member functions for SBAC context
diff -r 129bfec3144f -r 29afccf47900 source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp Thu May 08 23:49:27 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp Fri May 09 16:49:26 2014 +0900
@@ -1636,7 +1636,7 @@
void TEncSbac::codeIntraDirLumaAng(TComDataCU* cu, uint32_t absPartIdx, bool isMultiple)
{
uint32_t dir[4], j;
- int preds[4][3];
+ uint32_t preds[4][3];
int predIdx[4];
PartSize mode = cu->getPartitionSize(absPartIdx);
uint32_t partNum = isMultiple ? (mode == SIZE_NxN ? 4 : 1) : 1;
diff -r 129bfec3144f -r 29afccf47900 source/Lib/TLibEncoder/TEncSearch.cpp
--- a/source/Lib/TLibEncoder/TEncSearch.cpp Thu May 08 23:49:27 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp Fri May 09 16:49:26 2014 +0900
@@ -1664,22 +1664,25 @@
modeCosts[mode] = sa8d(cmp, srcStride, &tmp[(mode - 2) * (scaleSize * scaleSize)], scaleSize) << costShift;
}
+ uint32_t preds[3];
+ int numCand = cu->getIntraDirLumaPredictor(partOffset, preds);
+
+ uint64_t mpms;
+ uint32_t rbits = xModeBitsRemIntra(cu, partOffset, depth, preds, mpms);
+
// Find N least cost modes. N = numModesForFullRD
for (uint32_t mode = 0; mode < numModesAvailable; mode++)
{
uint32_t sad = modeCosts[mode];
- uint32_t bits = xModeBitsIntra(cu, mode, partOffset, depth, initTrDepth);
+ uint32_t bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : xModeBitsIntra(cu, mode, partOffset, depth);
uint64_t cost = m_rdCost->calcRdSADCost(sad, bits);
candNum += xUpdateCandList(mode, cost, numModesForFullRD, rdModeList, candCostList);
}
- int preds[3];
- int numCand = cu->getIntraDirLumaPredictor(partOffset, preds);
-
for (int j = 0; j < numCand; j++)
{
bool mostProbableModeIncluded = false;
- int mostProbableMode = preds[j];
+ uint32_t mostProbableMode = preds[j];
for (int i = 0; i < numModesForFullRD; i++)
{
@@ -3984,12 +3987,12 @@
}
}
-uint32_t TEncSearch::xModeBitsIntra(TComDataCU* cu, uint32_t mode, uint32_t partOffset, uint32_t depth, uint32_t initTrDepth)
+uint32_t TEncSearch::xModeBitsIntra(TComDataCU* cu, uint32_t mode, uint32_t partOffset, uint32_t depth)
{
// Reload only contexts required for coding intra mode information
m_rdGoOnSbacCoder->loadIntraDirModeLuma(m_rdSbacCoders[depth][CI_CURR_BEST]);
- cu->setLumaIntraDirSubParts(mode, partOffset, depth + initTrDepth);
+ cu->getLumaIntraDir()[partOffset] = (uint8_t)mode;
m_entropyCoder->resetBits();
m_entropyCoder->encodeIntraDirModeLuma(cu, partOffset);
@@ -3997,6 +4000,23 @@
return m_entropyCoder->getNumberOfWrittenBits();
}
+uint32_t TEncSearch::xModeBitsRemIntra(TComDataCU* cu, uint32_t partOffset, uint32_t depth, uint32_t preds[3], uint64_t& mpms)
+{
+ mpms = 0;
+ for (int i = 0; i < 3; ++i)
+ {
+ mpms |= ((uint64_t)1 << preds[i]);
+ }
+
+ uint32_t mode = 34;
+ while (mpms & ((uint64_t)1 << mode))
+ {
+ --mode;
+ }
+
+ return xModeBitsIntra(cu, mode, partOffset, depth);
+}
+
uint32_t TEncSearch::xUpdateCandList(uint32_t mode, uint64_t cost, uint32_t fastCandNum, uint32_t* CandModeList, uint64_t* CandCostList)
{
uint32_t i;
diff -r 129bfec3144f -r 29afccf47900 source/Lib/TLibEncoder/TEncSearch.h
--- a/source/Lib/TLibEncoder/TEncSearch.h Thu May 08 23:49:27 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSearch.h Fri May 09 16:49:26 2014 +0900
@@ -147,7 +147,8 @@
bool init(Encoder* cfg, TComRdCost* rdCost, TComTrQuant *trQuant);
- uint32_t xModeBitsIntra(TComDataCU* cu, uint32_t mode, uint32_t partOffset, uint32_t depth, uint32_t initTrDepth);
+ uint32_t xModeBitsIntra(TComDataCU* cu, uint32_t mode, uint32_t partOffset, uint32_t depth);
+ uint32_t xModeBitsRemIntra(TComDataCU * cu, uint32_t partOffset, uint32_t depth, uint32_t preds[3], uint64_t & mpms);
uint32_t xUpdateCandList(uint32_t mode, uint64_t cost, uint32_t fastCandNum, uint32_t* CandModeList, uint64_t* CandCostList);
void estIntraPredQT(TComDataCU* cu, TComYuv* fencYuv, TComYuv* predYuv, ShortYuv* resiYuv, TComYuv* reconYuv);
diff -r 129bfec3144f -r 29afccf47900 source/encoder/compress.cpp
--- a/source/encoder/compress.cpp Thu May 08 23:49:27 2014 -0500
+++ b/source/encoder/compress.cpp Fri May 09 16:49:26 2014 +0900
@@ -139,11 +139,17 @@
int log2SizeMinus2 = g_convertToBit[scaleWidth];
pixelcmp_t sa8d = primitives.sa8d[log2SizeMinus2];
+ uint32_t preds[3];
+ cu->getIntraDirLumaPredictor(partOffset, preds);
+
+ uint64_t mpms;
+ uint32_t rbits = m_search->xModeBitsRemIntra(cu, partOffset, depth, preds, mpms);
+
// DC
primitives.intra_pred[log2SizeMinus2][DC_IDX](tmp, scaleStride, left, above, 0, (scaleWidth <= 16));
bsad = costMultiplier * sa8d(fenc, scaleStride, tmp, scaleStride);
bmode = mode = DC_IDX;
- bbits = m_search->xModeBitsIntra(cu, mode, partOffset, depth, initTrDepth);
+ bbits = !(mpms & ((uint64_t)1 << mode)) ? rbits : m_search->xModeBitsIntra(cu, mode, partOffset, depth);
bcost = m_rdCost->calcRdSADCost(bsad, bbits);
pixel *abovePlanar = above;
@@ -159,7 +165,7 @@
primitives.intra_pred[log2SizeMinus2][PLANAR_IDX](tmp, scaleStride, leftPlanar, abovePlanar, 0, 0);
sad = costMultiplier * sa8d(fenc, scaleStride, tmp, scaleStride);
mode = PLANAR_IDX;
- bits = m_search->xModeBitsIntra(cu, mode, partOffset, depth, initTrDepth);
+ bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : m_search->xModeBitsIntra(cu, mode, partOffset, depth);
cost = m_rdCost->calcRdSADCost(sad, bits);
COPY4_IF_LT(bcost, cost, bmode, mode, bsad, sad, bbits, bits);
@@ -174,7 +180,7 @@
pixel *cmp = (modeHor ? buf_trans : fenc);
intptr_t srcStride = (modeHor ? scaleWidth : scaleStride);
sad = costMultiplier * sa8d(cmp, srcStride, &tmp[(mode - 2) * (scaleWidth * scaleWidth)], scaleWidth);
- bits = m_search->xModeBitsIntra(cu, mode, partOffset, depth, initTrDepth);
+ bits = !(mpms & ((uint64_t)1 << mode)) ? rbits : m_search->xModeBitsIntra(cu, mode, partOffset, depth);
cost = m_rdCost->calcRdSADCost(sad, bits);
COPY4_IF_LT(bcost, cost, bmode, mode, bsad, sad, bbits, bits);
}
More information about the x265-devel
mailing list