From 9b97e3c693ac8a2a5fbf42cf1416fbbafe57deeb Mon Sep 17 00:00:00 2001 From: yunghsua <yunghsua@qti.qualcomm.com> Date: Wed, 31 Jul 2019 23:38:48 -0700 Subject: [PATCH] Move variable doPlt from global to local, and some clean up --- source/Lib/CommonLib/Picture.cpp | 3 --- source/Lib/EncoderLib/EncLib.cpp | 37 +++++++++++++++++++++++++++ source/Lib/EncoderLib/EncLib.h | 9 +++++++ source/Lib/EncoderLib/EncModeCtrl.cpp | 7 ++--- source/Lib/EncoderLib/EncModeCtrl.h | 8 ++++++ source/Lib/EncoderLib/EncSlice.cpp | 35 +++++-------------------- 6 files changed, 63 insertions(+), 36 deletions(-) diff --git a/source/Lib/CommonLib/Picture.cpp b/source/Lib/CommonLib/Picture.cpp index d13e022a68..b3e3d9f9b5 100644 --- a/source/Lib/CommonLib/Picture.cpp +++ b/source/Lib/CommonLib/Picture.cpp @@ -932,9 +932,6 @@ void Picture::finalInit(const SPS& sps, const PPS& pps, APS** alfApss, APS& lmcs } } -#if JVET_O0119_BASE_PALETTE_444 -bool doPlt = true; -#endif void Picture::allocateNewSlice() { slices.push_back(new Slice); diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp index 0776d583ca..5de0405aa4 100644 --- a/source/Lib/EncoderLib/EncLib.cpp +++ b/source/Lib/EncoderLib/EncLib.cpp @@ -66,6 +66,9 @@ EncLib::EncLib() , m_cacheModel() #endif , m_lmcsAPS(nullptr) +#if JVET_O0119_BASE_PALETTE_444 + , m_doPlt( true ) +#endif { m_iPOCLast = -1; m_iNumPicRcvd = 0; @@ -1694,6 +1697,39 @@ bool EncLib::SPSNeedsWriting(int spsId) return bChanged; } +#if JVET_O0119_BASE_PALETTE_444 +void EncLib::checkPltStats( Picture* pic ) +{ + int totalArea = 0; + int pltArea = 0; + for (auto apu : pic->cs->pus) + { + for (int i = 0; i < MAX_NUM_TBLOCKS; ++i) + { + int puArea = apu->blocks[i].width * apu->blocks[i].height; + if (apu->blocks[i].width > 0 && apu->blocks[i].height > 0) + { + totalArea += puArea; + if (CU::isPLT(*apu->cu) || CU::isIBC(*apu->cu)) + { + pltArea += puArea; + } + break; + } + + } + } + if (pltArea * PLT_FAST_RATIO < totalArea) + { + m_doPlt = false; + } + else + { + m_doPlt = true; + } +} +#endif + #if X0038_LAMBDA_FROM_QP_CAPABILITY int EncCfg::getQPForPicture(const uint32_t gopIndex, const Slice *pSlice) const { @@ -1765,4 +1801,5 @@ int EncCfg::getQPForPicture(const uint32_t gopIndex, const Slice *pSlice) const } #endif + //! \} diff --git a/source/Lib/EncoderLib/EncLib.h b/source/Lib/EncoderLib/EncLib.h index d1ea9637df..4b50555b0d 100644 --- a/source/Lib/EncoderLib/EncLib.h +++ b/source/Lib/EncoderLib/EncLib.h @@ -144,6 +144,10 @@ private: EncHRD m_encHRD; +#if JVET_O0119_BASE_PALETTE_444 + bool m_doPlt; +#endif + public: Ctx m_entropyCodingSyncContextState; ///< leave in addition to vector for compatibility #if ENABLE_WPP_PARALLELISM @@ -237,6 +241,11 @@ public: #endif ParameterSetMap<APS>* getApsMap() { return &m_apsMap; } + +#if JVET_O0119_BASE_PALETTE_444 + bool getPltEnc() const { return m_doPlt; } + void checkPltStats( Picture* pic ); +#endif // ------------------------------------------------------------------------------------------------------------------- // encoder function // ------------------------------------------------------------------------------------------------------------------- diff --git a/source/Lib/EncoderLib/EncModeCtrl.cpp b/source/Lib/EncoderLib/EncModeCtrl.cpp index cffcc0062e..f32cf5de1e 100644 --- a/source/Lib/EncoderLib/EncModeCtrl.cpp +++ b/source/Lib/EncoderLib/EncModeCtrl.cpp @@ -1115,9 +1115,6 @@ void EncModeCtrlMTnoRQT::initCTUEncoding( const Slice &slice ) } } -#if JVET_O0119_BASE_PALETTE_444 -extern bool doPlt; -#endif void EncModeCtrlMTnoRQT::initCULevel( Partitioner &partitioner, const CodingStructure& cs ) { // Min/max depth @@ -1346,14 +1343,14 @@ void EncModeCtrlMTnoRQT::initCULevel( Partitioner &partitioner, const CodingStru // add intra modes m_ComprCUCtxList.back().testModes.push_back( { ETM_IPCM, ETO_STANDARD, qp, lossless } ); #if JVET_O0119_BASE_PALETTE_444 - if (cs.slice->getSPS()->getPLTMode() && cs.slice->isIRAP() && doPlt) + if (cs.slice->getSPS()->getPLTMode() && cs.slice->isIRAP() && getPltEnc() ) { m_ComprCUCtxList.back().testModes.push_back({ ETM_PALETTE, ETO_STANDARD, qp, lossless }); } #endif m_ComprCUCtxList.back().testModes.push_back( { ETM_INTRA, ETO_STANDARD, qp, lossless } ); #if JVET_O0119_BASE_PALETTE_444 - if (cs.slice->getSPS()->getPLTMode() && !cs.slice->isIRAP() && doPlt) + if (cs.slice->getSPS()->getPLTMode() && !cs.slice->isIRAP() && getPltEnc() ) { m_ComprCUCtxList.back().testModes.push_back({ ETM_PALETTE, ETO_STANDARD, qp, lossless }); } diff --git a/source/Lib/EncoderLib/EncModeCtrl.h b/source/Lib/EncoderLib/EncModeCtrl.h index db4c14e7ee..3360e87681 100644 --- a/source/Lib/EncoderLib/EncModeCtrl.h +++ b/source/Lib/EncoderLib/EncModeCtrl.h @@ -268,6 +268,10 @@ protected: InterSearch* m_pcInterSearch; #endif +#if JVET_O0119_BASE_PALETTE_444 + bool m_doPlt; +#endif + public: virtual ~EncModeCtrl () {} @@ -327,6 +331,10 @@ public: #if JVET_O0592_ENC_ME_IMP void setInterSearch (InterSearch* pcInterSearch) { m_pcInterSearch = pcInterSearch; } #endif +#if JVET_O0119_BASE_PALETTE_444 + void setPltEnc ( bool b ) { m_doPlt = b; } + bool getPltEnc() const { return m_doPlt; } +#endif protected: void xExtractFeatures ( const EncTestMode encTestmode, CodingStructure& cs ); diff --git a/source/Lib/EncoderLib/EncSlice.cpp b/source/Lib/EncoderLib/EncSlice.cpp index ee9a44e9e0..c49ab3ea3f 100644 --- a/source/Lib/EncoderLib/EncSlice.cpp +++ b/source/Lib/EncoderLib/EncSlice.cpp @@ -1287,9 +1287,6 @@ void EncSlice::calCostSliceI(Picture* pcPic) // TODO: this only analyses the fir /** \param pcPic picture class */ -#if JVET_O0119_BASE_PALETTE_444 -extern bool doPlt; -#endif void EncSlice::compressSlice( Picture* pcPic, const bool bCompressEntireSlice, const bool bFastDeltaQP ) { // if bCompressEntireSlice is true, then the entire slice (not slice segment) is compressed, @@ -1395,7 +1392,12 @@ void EncSlice::compressSlice( Picture* pcPic, const bool bCompressEntireSlice, c bool checkPLTRatio = m_pcCfg->getIntraPeriod() != 1 && pcSlice->isIRAP(); if (checkPLTRatio) { - doPlt = true; + m_pcCuEncoder->getModeCtrl()->setPltEnc(true); + } + else + { + bool doPlt = m_pcLib->getPltEnc(); + m_pcCuEncoder->getModeCtrl()->setPltEnc(doPlt); } #endif @@ -1434,30 +1436,7 @@ void EncSlice::compressSlice( Picture* pcPic, const bool bCompressEntireSlice, c #endif encodeCtus( pcPic, bCompressEntireSlice, bFastDeltaQP, startCtuTsAddr, boundingCtuTsAddr, m_pcLib ); #if JVET_O0119_BASE_PALETTE_444 - if (checkPLTRatio) - { - int totalArea = 0; - int pltArea = 0; - for (auto apu : pcPic->cs->pus) - { - for (int i = 0; i < MAX_NUM_TBLOCKS; ++i) - { - int puArea = apu->blocks[i].width * apu->blocks[i].height; - if (apu->blocks[i].width > 0 && apu->blocks[i].height > 0) - { - totalArea += puArea; - if (CU::isPLT(*apu->cu) || CU::isIBC(*apu->cu)) - { - pltArea += puArea; - } - break; - } - - } - } - if (pltArea * PLT_FAST_RATIO < totalArea) - doPlt = false; - } + if (checkPLTRatio) m_pcLib->checkPltStats( pcPic ); #endif } -- GitLab