From 2d08a681f7122807e19b38669c44974085c3fd22 Mon Sep 17 00:00:00 2001 From: Frank Bossen <fbossen@gmail.com> Date: Wed, 7 Sep 2022 12:25:08 -0400 Subject: [PATCH] Use proper data type for RPR scaling --- source/Lib/CommonLib/CommonDef.h | 4 +- source/Lib/CommonLib/InterPrediction.cpp | 50 +++++++++-------- source/Lib/CommonLib/InterPrediction.h | 8 +-- source/Lib/CommonLib/Picture.cpp | 70 +++++++++++++----------- source/Lib/CommonLib/Picture.h | 28 +++++----- source/Lib/CommonLib/Slice.cpp | 14 ++--- source/Lib/CommonLib/Slice.h | 9 ++- source/Lib/CommonLib/TypeDef.h | 11 ++++ source/Lib/CommonLib/UnitTools.cpp | 8 ++- source/Lib/CommonLib/UnitTools.h | 2 +- source/Lib/DecoderLib/DecLib.cpp | 10 ++-- source/Lib/EncoderLib/EncGOP.cpp | 17 +++--- source/Lib/EncoderLib/EncLib.cpp | 15 ++--- source/Lib/EncoderLib/InterSearch.cpp | 4 +- source/Lib/Utilities/VideoIOYuv.cpp | 13 +++-- 15 files changed, 144 insertions(+), 119 deletions(-) diff --git a/source/Lib/CommonLib/CommonDef.h b/source/Lib/CommonLib/CommonDef.h index f3834cca1..4381f2cc0 100644 --- a/source/Lib/CommonLib/CommonDef.h +++ b/source/Lib/CommonLib/CommonDef.h @@ -547,9 +547,9 @@ static constexpr int ENC_PPS_ID_RPR = 3; static constexpr int ENC_PPS_ID_RPR2 = 5; static constexpr int ENC_PPS_ID_RPR3 = 7; #endif -static constexpr int SCALE_RATIO_BITS = 14; static constexpr int MAX_SCALING_RATIO = 2; // max downsampling ratio for RPR -static const std::pair<int, int> SCALE_1X = std::pair<int, int>( 1 << SCALE_RATIO_BITS, 1 << SCALE_RATIO_BITS ); // scale ratio 1x +static constexpr ScalingRatio SCALE_1X = { 1 << ScalingRatio::BITS, 1 << ScalingRatio::BITS }; // scale ratio 1x + static constexpr int DELTA_QP_ACT[4] = { -5, 1, 3, 1 }; static constexpr int MAX_TSRC_RICE = 8; ///<Maximum supported TSRC Rice parameter static constexpr int MIN_TSRC_RICE = 1; ///<Minimum supported TSRC Rice parameter diff --git a/source/Lib/CommonLib/InterPrediction.cpp b/source/Lib/CommonLib/InterPrediction.cpp index 8fdab6e1a..9fec46413 100644 --- a/source/Lib/CommonLib/InterPrediction.cpp +++ b/source/Lib/CommonLib/InterPrediction.cpp @@ -659,7 +659,7 @@ void InterPrediction::xPredInterBi(PredictionUnit &pu, PelUnitBuf &pcYuvPred, co void InterPrediction::xPredInterBlk(const ComponentID compID, const PredictionUnit &pu, const Picture *refPic, const Mv &_mv, PelUnitBuf &dstPic, const bool bi, const ClpRng &clpRng, - const bool bioApplied, bool isIBC, const std::pair<int, int> scalingRatio, + const bool bioApplied, bool isIBC, const ScalingRatio scalingRatio, bool bilinearMC, Pel *srcPadBuf, ptrdiff_t srcPadStride, Pel *bdofDstBuf) { JVET_J0090_SET_REF_PICTURE( refPic, compID ); @@ -846,11 +846,11 @@ bool InterPrediction::isSubblockVectorSpreadOverLimit( int a, int b, int c, int #if GDR_ENABLED bool InterPrediction::xPredAffineBlk(const ComponentID &compID, const PredictionUnit &pu, const Picture *refPic, const Mv *_mv, PelUnitBuf &dstPic, const bool bi, const ClpRng &clpRng, - bool genChromaMv, const std::pair<int, int> scalingRatio) + bool genChromaMv, const ScalingRatio scalingRatio) #else void InterPrediction::xPredAffineBlk(const ComponentID &compID, const PredictionUnit &pu, const Picture *refPic, const Mv *_mv, PelUnitBuf &dstPic, const bool bi, const ClpRng &clpRng, - bool genChromaMv, const std::pair<int, int> scalingRatio) + bool genChromaMv, const ScalingRatio scalingRatio) #endif { JVET_J0090_SET_REF_PICTURE(refPic, compID); @@ -2072,7 +2072,7 @@ bool InterPrediction::isLumaBvValid(const int ctuSize, const int xCb, const int return true; } -bool InterPrediction::xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, const PPS &pps, const CompArea &blk, +bool InterPrediction::xPredInterBlkRPR(const ScalingRatio scalingRatio, const PPS &pps, const CompArea &blk, const Picture *refPic, const Mv &mv, Pel *dst, const ptrdiff_t dstStride, const bool bi, const bool wrapRef, const ClpRng &clpRng, const InterpolationFilter::Filter filterIndex, const bool useAltHpelIf) @@ -2098,44 +2098,46 @@ bool InterPrediction::xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, InterpolationFilter::Filter xFilter = filterIndex; InterpolationFilter::Filter yFilter = filterIndex; - const int rprThreshold1 = ( 1 << SCALE_RATIO_BITS ) * 5 / 4; - const int rprThreshold2 = ( 1 << SCALE_RATIO_BITS ) * 7 / 4; + + const int rprThreshold1 = (1 << ScalingRatio::BITS) * 5 / 4; + const int rprThreshold2 = (1 << ScalingRatio::BITS) * 7 / 4; + if (filterIndex == InterpolationFilter::Filter::DEFAULT || !isLuma(compID)) { - if( scalingRatio.first > rprThreshold2 ) + if (scalingRatio.x > rprThreshold2) { xFilter = InterpolationFilter::Filter::RPR2; } - else if( scalingRatio.first > rprThreshold1 ) + else if (scalingRatio.x > rprThreshold1) { xFilter = InterpolationFilter::Filter::RPR1; } - if( scalingRatio.second > rprThreshold2 ) + if (scalingRatio.y > rprThreshold2) { yFilter = InterpolationFilter::Filter::RPR2; } - else if( scalingRatio.second > rprThreshold1 ) + else if (scalingRatio.y > rprThreshold1) { yFilter = InterpolationFilter::Filter::RPR1; } } else if (filterIndex == InterpolationFilter::Filter::AFFINE) { - if (scalingRatio.first > rprThreshold2) + if (scalingRatio.x > rprThreshold2) { xFilter = InterpolationFilter::Filter::AFFINE_RPR2; } - else if (scalingRatio.first > rprThreshold1) + else if (scalingRatio.x > rprThreshold1) { xFilter = InterpolationFilter::Filter::AFFINE_RPR1; } - if (scalingRatio.second > rprThreshold2) + if (scalingRatio.y > rprThreshold2) { yFilter = InterpolationFilter::Filter::AFFINE_RPR2; } - else if (scalingRatio.second > rprThreshold1) + else if (scalingRatio.y > rprThreshold1) { yFilter = InterpolationFilter::Filter::AFFINE_RPR1; } @@ -2143,19 +2145,19 @@ bool InterPrediction::xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, if (useAltHpelIf) { - if (xFilter == InterpolationFilter::Filter::DEFAULT && scalingRatio.first == 1 << SCALE_RATIO_BITS) + if (xFilter == InterpolationFilter::Filter::DEFAULT && scalingRatio.x == SCALE_1X.x) { xFilter = InterpolationFilter::Filter::HALFPEL_ALT; } - if (yFilter == InterpolationFilter::Filter::DEFAULT && scalingRatio.second == 1 << SCALE_RATIO_BITS) + if (yFilter == InterpolationFilter::Filter::DEFAULT && scalingRatio.y == SCALE_1X.y) { yFilter = InterpolationFilter::Filter::HALFPEL_ALT; } } - const int posShift = SCALE_RATIO_BITS - 4; + const int posShift = ScalingRatio::BITS - 4; - const int stepX = (scalingRatio.first + 8) >> 4; - const int stepY = (scalingRatio.second + 8) >> 4; + const int stepX = (scalingRatio.x + 8) >> 4; + const int stepY = (scalingRatio.y + 8) >> 4; const int offX = 1 << (posShift - shiftHor - 1); const int offY = 1 << (posShift - shiftVer - 1); @@ -2168,8 +2170,10 @@ bool InterPrediction::xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, const int64_t posY = ((blk.pos().y << scaleY) - (pps.getScalingWindow().getWindowTopOffset() * SPS::getWinUnitY(chFmt))) >> scaleY; - int addX = isLuma( compID ) ? 0 : int( 1 - refPic->cs->sps->getHorCollocatedChromaFlag() ) * 8 * ( scalingRatio.first - SCALE_1X.first ); - int addY = isLuma( compID ) ? 0 : int( 1 - refPic->cs->sps->getVerCollocatedChromaFlag() ) * 8 * ( scalingRatio.second - SCALE_1X.second ); + int addX = + isLuma(compID) ? 0 : int(1 - refPic->cs->sps->getHorCollocatedChromaFlag()) * 8 * (scalingRatio.x - SCALE_1X.x); + int addY = + isLuma(compID) ? 0 : int(1 - refPic->cs->sps->getVerCollocatedChromaFlag()) * 8 * (scalingRatio.y - SCALE_1X.y); int boundLeft = 0; int boundRight = refPicWidth >> scaleX; @@ -2190,11 +2194,11 @@ bool InterPrediction::xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, int64_t x0Int; int64_t y0Int; - x0Int = ((posX << (4 + scaleX)) + mv.getHor()) * (int64_t) scalingRatio.first + addX; + x0Int = ((posX << (4 + scaleX)) + mv.getHor()) * (int64_t) scalingRatio.x + addX; x0Int = sgn2(x0Int) * ((abs(x0Int) + (1ull << (7 + scaleX))) >> (8 + scaleX)) + ((refPic->getScalingWindow().getWindowLeftOffset() * SPS::getWinUnitX(chFmt)) << ((posShift - scaleX))); - y0Int = ((posY << (4 + scaleY)) + mv.getVer()) * (int64_t) scalingRatio.second + addY; + y0Int = ((posY << (4 + scaleY)) + mv.getVer()) * (int64_t) scalingRatio.y + addY; y0Int = sgn2(y0Int) * ((abs(y0Int) + (1ull << (7 + scaleY))) >> (8 + scaleY)) + ((refPic->getScalingWindow().getWindowTopOffset() * SPS::getWinUnitY(chFmt)) << ((posShift - scaleY))); diff --git a/source/Lib/CommonLib/InterPrediction.h b/source/Lib/CommonLib/InterPrediction.h index 329e7edaa..71a18b4ca 100644 --- a/source/Lib/CommonLib/InterPrediction.h +++ b/source/Lib/CommonLib/InterPrediction.h @@ -126,7 +126,7 @@ protected: void xPredInterBlk(const ComponentID compID, const PredictionUnit &pu, const Picture *refPic, const Mv &_mv, PelUnitBuf &dstPic, bool bi, const ClpRng &clpRng, bool bioApplied, bool isIBC, - const std::pair<int, int> scalingRatio, bool bilinearMC, Pel *srcPadBuf, ptrdiff_t srcPadStride, + const ScalingRatio scalingRatio, bool bilinearMC, Pel *srcPadBuf, ptrdiff_t srcPadStride, Pel *bdofDstBuf); void xPredInterBlk(const ComponentID compID, const PredictionUnit &pu, const Picture *refPic, const Mv &_mv, PelUnitBuf &dstPic, bool bi, const ClpRng &clpRng, bool bioApplied, bool isIBC, RefPicList l) @@ -149,11 +149,11 @@ protected: #if GDR_ENABLED bool xPredAffineBlk(const ComponentID &compID, const PredictionUnit &pu, const Picture *refPic, const Mv *_mv, PelUnitBuf &dstPic, const bool bi, const ClpRng &clpRng, const bool genChromaMv = false, - const std::pair<int, int> scalingRatio = SCALE_1X); + const ScalingRatio = SCALE_1X); #else void xPredAffineBlk(const ComponentID &compID, const PredictionUnit &pu, const Picture *refPic, const Mv *_mv, PelUnitBuf &dstPic, const bool bi, const ClpRng &clpRng, const bool genChromaMv = false, - const std::pair<int, int> scalingRatio = SCALE_1X); + const ScalingRatio = SCALE_1X); #endif static bool xCheckIdenticalMotion( const PredictionUnit& pu ); @@ -215,7 +215,7 @@ public: void resetVPDUforIBC(const ChromaFormat chromaFormatIDC, const int ctuSize, const int vSize, const int xPos, const int yPos); bool isLumaBvValid(const int ctuSize, const int xCb, const int yCb, const int width, const int height, const int xBv, const int yBv); - bool xPredInterBlkRPR(const std::pair<int, int> &scalingRatio, const PPS &pps, const CompArea &blk, + bool xPredInterBlkRPR(const ScalingRatio scalingRatio, const PPS &pps, const CompArea &blk, const Picture *refPic, const Mv &mv, Pel *dst, const ptrdiff_t dstStride, const bool bi, const bool wrapRef, const ClpRng &clpRng, const InterpolationFilter::Filter filterIndex, const bool useAltHpelIf = false); diff --git a/source/Lib/CommonLib/Picture.cpp b/source/Lib/CommonLib/Picture.cpp index f482c240a..733f49b68 100644 --- a/source/Lib/CommonLib/Picture.cpp +++ b/source/Lib/CommonLib/Picture.cpp @@ -629,12 +629,13 @@ const TFilterCoeff m_chromaFilter6[32][6] = }; #endif -void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std::pair<int, int> compScale, - const CPelBuf& beforeScale, const int beforeScaleLeftOffset, const int beforeScaleTopOffset, - const PelBuf& afterScale, const int afterScaleLeftOffset, const int afterScaleTopOffset, - const int bitDepth, const bool useLumaFilter, const bool downsampling, +void Picture::sampleRateConv(const ScalingRatio scalingRatio, const int scaleX, const int scaleY, + const CPelBuf &beforeScale, const int beforeScaleLeftOffset, + const int beforeScaleTopOffset, const PelBuf &afterScale, const int afterScaleLeftOffset, + const int afterScaleTopOffset, const int bitDepth, const bool useLumaFilter, + const bool downsampling, #if !JVET_AB0081 - const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag + const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag #else const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag, const bool rescaleForDisplay, const int upscaleFilterForDisplay @@ -678,70 +679,76 @@ void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std: #endif const int numFracPositions = useLumaFilter ? 15 : 31; const int numFracShift = useLumaFilter ? 4 : 5; - const int posShiftX = SCALE_RATIO_BITS - numFracShift + compScale.first; - const int posShiftY = SCALE_RATIO_BITS - numFracShift + compScale.second; - int addX = ( 1 << ( posShiftX - 1 ) ) + ( beforeScaleLeftOffset << SCALE_RATIO_BITS ) + ( ( int( 1 - horCollocatedPositionFlag ) * 8 * ( scalingRatio.first - SCALE_1X.first ) + ( 1 << ( 2 + compScale.first ) ) ) >> ( 3 + compScale.first ) ); - int addY = ( 1 << ( posShiftY - 1 ) ) + ( beforeScaleTopOffset << SCALE_RATIO_BITS ) + ( ( int( 1 - verCollocatedPositionFlag ) * 8 * ( scalingRatio.second - SCALE_1X.second ) + ( 1 << ( 2 + compScale.second ) ) ) >> ( 3 + compScale.second ) ); + + const int posShiftX = ScalingRatio::BITS - numFracShift + scaleX; + const int posShiftY = ScalingRatio::BITS - numFracShift + scaleY; + + const int addX = + (1 << (posShiftX - 1)) + (beforeScaleLeftOffset << ScalingRatio::BITS) + + ((int(1 - horCollocatedPositionFlag) * 8 * (scalingRatio.x - SCALE_1X.x) + (1 << (2 + scaleX))) >> (3 + scaleX)); + const int addY = + (1 << (posShiftY - 1)) + (beforeScaleTopOffset << ScalingRatio::BITS) + + ((int(1 - verCollocatedPositionFlag) * 8 * (scalingRatio.y - SCALE_1X.y) + (1 << (2 + scaleY))) >> (3 + scaleY)); if( downsampling ) { int verFilter = 0; int horFilter = 0; - if (scalingRatio.first > (15 << SCALE_RATIO_BITS) / 4) + if (scalingRatio.x > (15 << ScalingRatio::BITS) / 4) { horFilter = 7; } - else if (scalingRatio.first > (20 << SCALE_RATIO_BITS) / 7) + else if (scalingRatio.x > (20 << ScalingRatio::BITS) / 7) { horFilter = 6; } - else if (scalingRatio.first > (5 << SCALE_RATIO_BITS) / 2) + else if (scalingRatio.x > (5 << ScalingRatio::BITS) / 2) { horFilter = 5; } - else if (scalingRatio.first > (2 << SCALE_RATIO_BITS)) + else if (scalingRatio.x > (2 << ScalingRatio::BITS)) { horFilter = 4; } - else if (scalingRatio.first > (5 << SCALE_RATIO_BITS) / 3) + else if (scalingRatio.x > (5 << ScalingRatio::BITS) / 3) { horFilter = 3; } - else if (scalingRatio.first > (5 << SCALE_RATIO_BITS) / 4) + else if (scalingRatio.x > (5 << ScalingRatio::BITS) / 4) { horFilter = 2; } - else if (scalingRatio.first > (20 << SCALE_RATIO_BITS) / 19) + else if (scalingRatio.x > (20 << ScalingRatio::BITS) / 19) { horFilter = 1; } - if (scalingRatio.second > (15 << SCALE_RATIO_BITS) / 4) + if (scalingRatio.y > (15 << ScalingRatio::BITS) / 4) { verFilter = 7; } - else if (scalingRatio.second > (20 << SCALE_RATIO_BITS) / 7) + else if (scalingRatio.y > (20 << ScalingRatio::BITS) / 7) { verFilter = 6; } - else if (scalingRatio.second > (5 << SCALE_RATIO_BITS) / 2) + else if (scalingRatio.y > (5 << ScalingRatio::BITS) / 2) { verFilter = 5; } - else if (scalingRatio.second > (2 << SCALE_RATIO_BITS)) + else if (scalingRatio.y > (2 << ScalingRatio::BITS)) { verFilter = 4; } - else if (scalingRatio.second > (5 << SCALE_RATIO_BITS) / 3) + else if (scalingRatio.y > (5 << ScalingRatio::BITS) / 3) { verFilter = 3; } - else if (scalingRatio.second > (5 << SCALE_RATIO_BITS) / 4) + else if (scalingRatio.y > (5 << ScalingRatio::BITS) / 4) { verFilter = 2; } - else if (scalingRatio.second > (20 << SCALE_RATIO_BITS) / 19) + else if (scalingRatio.y > (20 << ScalingRatio::BITS) / 19) { verFilter = 1; } @@ -768,7 +775,8 @@ void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std: for( int i = 0; i < scaledWidth; i++ ) { const Pel* org = orgSrc; - int refPos = ( ( ( i << compScale.first ) - afterScaleLeftOffset ) * scalingRatio.first + addX ) >> posShiftX; + + int refPos = (((i << scaleX) - afterScaleLeftOffset) * scalingRatio.x + addX) >> posShiftX; int integer = refPos >> numFracShift; int frac = refPos & numFracPositions; int* tmp = buf + i; @@ -795,7 +803,7 @@ void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std: for( int j = 0; j < scaledHeight; j++ ) { - int refPos = ( ( ( j << compScale.second ) - afterScaleTopOffset ) * scalingRatio.second + addY ) >> posShiftY; + int refPos = (((j << scaleY) - afterScaleTopOffset) * scalingRatio.y + addY) >> posShiftY; int integer = refPos >> numFracShift; int frac = refPos & numFracPositions; @@ -820,12 +828,12 @@ void Picture::sampleRateConv( const std::pair<int, int> scalingRatio, const std: delete[] buf; } -void Picture::rescalePicture( const std::pair<int, int> scalingRatio, - const CPelUnitBuf& beforeScaling, const Window& scalingWindowBefore, - const PelUnitBuf& afterScaling, const Window& scalingWindowAfter, - const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling, +void Picture::rescalePicture(const ScalingRatio scalingRatio, const CPelUnitBuf &beforeScaling, + const Window &scalingWindowBefore, const PelUnitBuf &afterScaling, + const Window &scalingWindowAfter, const ChromaFormat chromaFormatIDC, + const BitDepths &bitDepths, const bool useLumaFilter, const bool downsampling, #if !JVET_AB0081 - const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag + const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag #else const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag, bool rescaleForDisplay, int upscaleFilterForDisplay @@ -840,7 +848,7 @@ void Picture::rescalePicture( const std::pair<int, int> scalingRatio, sampleRateConv( scalingRatio, - std::pair<int, int>(::getComponentScaleX(compID, chromaFormatIDC), ::getComponentScaleY(compID, chromaFormatIDC)), + ::getComponentScaleX(compID, chromaFormatIDC), ::getComponentScaleY(compID, chromaFormatIDC), beforeScale, scalingWindowBefore.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIDC), scalingWindowBefore.getWindowTopOffset() * SPS::getWinUnitY(chromaFormatIDC), afterScale, scalingWindowAfter.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIDC), diff --git a/source/Lib/CommonLib/Picture.h b/source/Lib/CommonLib/Picture.h index 9b9b2e784..1985b628f 100644 --- a/source/Lib/CommonLib/Picture.h +++ b/source/Lib/CommonLib/Picture.h @@ -171,27 +171,27 @@ struct Picture : public UnitArea void setSpliceIdx(uint32_t idx, int poc) { m_spliceIdx[idx] = poc; } void createSpliceIdx(int nums); bool getSpliceFull(); - static void sampleRateConv( const std::pair<int, int> scalingRatio, const std::pair<int, int> compScale, - const CPelBuf& beforeScale, const int beforeScaleLeftOffset, const int beforeScaleTopOffset, - const PelBuf& afterScale, const int afterScaleLeftOffset, const int afterScaleTopOffset, - const int bitDepth, const bool useLumaFilter, const bool downsampling, + static void sampleRateConv(const ScalingRatio scalingRatio, int scaleX, int scaleY, const CPelBuf &beforeScale, + const int beforeScaleLeftOffset, const int beforeScaleTopOffset, const PelBuf &afterScale, + const int afterScaleLeftOffset, const int afterScaleTopOffset, const int bitDepth, + const bool useLumaFilter, const bool downsampling, #if !JVET_AB0081 - const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag + const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag #else - const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag, - const bool rescaleForDisplay, const int upscaleFilterForDisplay + const bool horCollocatedPositionFlag, const bool verCollocatedPositionFlag, + const bool rescaleForDisplay, const int upscaleFilterForDisplay #endif ); - static void rescalePicture( const std::pair<int, int> scalingRatio, - const CPelUnitBuf& beforeScaling, const Window& scalingWindowBefore, - const PelUnitBuf& afterScaling, const Window& scalingWindowAfter, - const ChromaFormat chromaFormatIDC, const BitDepths& bitDepths, const bool useLumaFilter, const bool downsampling, + static void rescalePicture(const ScalingRatio scalingRatio, const CPelUnitBuf &beforeScaling, + const Window &scalingWindowBefore, const PelUnitBuf &afterScaling, + const Window &scalingWindowAfter, const ChromaFormat chromaFormatIDC, + const BitDepths &bitDepths, const bool useLumaFilter, const bool downsampling, #if !JVET_AB0081 - const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag + const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag #else - const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag, - bool rescaleForDisplay = false, int upscaleFilterForDisplay = 0 + const bool horCollocatedChromaFlag, const bool verCollocatedChromaFlag, + bool rescaleForDisplay = false, int upscaleFilterForDisplay = 0 #endif ); diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp index 09de95686..7f3b463d4 100644 --- a/source/Lib/CommonLib/Slice.cpp +++ b/source/Lib/CommonLib/Slice.cpp @@ -4453,9 +4453,7 @@ void Slice::scaleRefPicList( Picture *scaledRefPic[ ], PicHeader *picHeader, APS // if rescaling is needed, otherwise just reuse the original picture pointer; it is needed for motion field, otherwise motion field requires a copy as well // reference resampling for the whole picture is not applied at decoder - int xScale, yScale; - CU::getRprScaling( sps, pps, m_apcRefPicList[refList][rIdx], xScale, yScale ); - m_scalingRatio[refList][rIdx] = std::pair<int, int>( xScale, yScale ); + CU::getRprScaling(sps, pps, m_apcRefPicList[refList][rIdx], m_scalingRatio[refList][rIdx]); CHECK( m_apcRefPicList[refList][rIdx]->unscaledPic == nullptr, "unscaledPic is not properly set" ); @@ -4525,11 +4523,11 @@ void Slice::scaleRefPicList( Picture *scaledRefPic[ ], PicHeader *picHeader, APS // rescale the reference picture const bool downsampling = m_apcRefPicList[refList][rIdx]->getRecoBuf().Y().width >= scaledRefPic[j]->getRecoBuf().Y().width && m_apcRefPicList[refList][rIdx]->getRecoBuf().Y().height >= scaledRefPic[j]->getRecoBuf().Y().height; - Picture::rescalePicture( m_scalingRatio[refList][rIdx], - m_apcRefPicList[refList][rIdx]->getRecoBuf(), m_apcRefPicList[refList][rIdx]->slices[0]->getPPS()->getScalingWindow(), - scaledRefPic[j]->getRecoBuf(), pps->getScalingWindow(), - sps->getChromaFormatIdc(), sps->getBitDepths(), true, downsampling, - sps->getHorCollocatedChromaFlag(), sps->getVerCollocatedChromaFlag() ); + Picture::rescalePicture(m_scalingRatio[refList][rIdx], m_apcRefPicList[refList][rIdx]->getRecoBuf(), + m_apcRefPicList[refList][rIdx]->slices[0]->getPPS()->getScalingWindow(), + scaledRefPic[j]->getRecoBuf(), pps->getScalingWindow(), sps->getChromaFormatIdc(), + sps->getBitDepths(), true, downsampling, sps->getHorCollocatedChromaFlag(), + sps->getVerCollocatedChromaFlag()); scaledRefPic[j]->unscaledPic = m_apcRefPicList[refList][rIdx]; scaledRefPic[j]->extendPicBorder( getPPS() ); diff --git a/source/Lib/CommonLib/Slice.h b/source/Lib/CommonLib/Slice.h index 4d1b46840..d99be4939 100644 --- a/source/Lib/CommonLib/Slice.h +++ b/source/Lib/CommonLib/Slice.h @@ -2782,8 +2782,7 @@ private: int m_hierPredLayerIdx; // hierarchical prediction layer index Picture* m_scaledRefPicList[NUM_REF_PIC_LIST_01][MAX_NUM_REF + 1]; Picture* m_savedRefPicList[NUM_REF_PIC_LIST_01][MAX_NUM_REF + 1]; - std::pair<int, int> m_scalingRatio[NUM_REF_PIC_LIST_01][MAX_NUM_REF_PICS]; - + ScalingRatio m_scalingRatio[NUM_REF_PIC_LIST_01][MAX_NUM_REF_PICS]; // access channel const VPS* m_pcVPS; @@ -3177,7 +3176,11 @@ public: void scaleRefPicList( Picture *scaledRefPic[ ], PicHeader *picHeader, APS** apss, APS* lmcsAps, APS* scalingListAps, const bool isDecoder ); void freeScaledRefPicList( Picture *scaledRefPic[] ); bool checkRPR(); - const std::pair<int, int>& getScalingRatio( const RefPicList refPicList, const int refIdx ) const { CHECK( refIdx < 0, "Invalid reference index" ); return m_scalingRatio[refPicList][refIdx]; } + const ScalingRatio &getScalingRatio(const RefPicList refPicList, const int refIdx) const + { + CHECK(refIdx < 0, "Invalid reference index"); + return m_scalingRatio[refPicList][refIdx]; + } void setNumSubstream( const SPS *sps, const PPS *pps ); void setNumEntryPoints( const SPS *sps, const PPS *pps ); uint32_t getNumEntryPoints( ) const { return m_numEntryPoints; } diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 7fc1b0f39..e2ed177fa 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -1003,6 +1003,17 @@ private: using BitDepths = EnumArray<int, ChannelType>; +struct ScalingRatio +{ + static constexpr int BITS = 14; + + int x; + int y; + + bool operator==(const ScalingRatio &s) const { return x == s.x && y == s.y; } + bool operator!=(const ScalingRatio &s) const { return x != s.x || y != s.y; } +}; + enum PLTRunMode { PLT_RUN_INDEX = 0, diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index 21b3850eb..85327bdd6 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -97,7 +97,7 @@ void CS::setRefinedMotionField(CodingStructure &cs) } // CU tools -bool CU::getRprScaling( const SPS* sps, const PPS* curPPS, Picture* refPic, int& xScale, int& yScale ) +bool CU::getRprScaling(const SPS *sps, const PPS *curPPS, Picture *refPic, ScalingRatio &scalingRatio) { const int subWidthC = SPS::getWinUnitX(sps->getChromaFormatIdc()); const int subHeightC = SPS::getWinUnitY(sps->getChromaFormatIdc()); @@ -132,8 +132,10 @@ bool CU::getRprScaling( const SPS* sps, const PPS* curPPS, Picture* refPic, int& CHECK(curPicScalWinHeight > refPicScalWinHeight * 8, "curPicScalWinHeight shall be less than or equal to refPicScalWinHeight * 8"); - xScale = (int) (((refPicScalWinWidth << SCALE_RATIO_BITS) + (curPicScalWinWidth >> 1)) / curPicScalWinWidth); - yScale = (int) (((refPicScalWinHeight << SCALE_RATIO_BITS) + (curPicScalWinHeight >> 1)) / curPicScalWinHeight); + scalingRatio.x = + (int) (((refPicScalWinWidth << ScalingRatio::BITS) + (curPicScalWinWidth >> 1)) / curPicScalWinWidth); + scalingRatio.y = + (int) (((refPicScalWinHeight << ScalingRatio::BITS) + (curPicScalWinHeight >> 1)) / curPicScalWinHeight); const int maxPicWidth = sps->getMaxPicWidthInLumaSamples(); // sps_pic_width_max_in_luma_samples const int maxPicHeight = sps->getMaxPicHeightInLumaSamples(); // sps_pic_height_max_in_luma_samples diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h index 73137e29a..a59769fe2 100644 --- a/source/Lib/CommonLib/UnitTools.h +++ b/source/Lib/CommonLib/UnitTools.h @@ -131,7 +131,7 @@ namespace CU uint8_t numSbtModeRdo (uint8_t sbtAllowed); bool isSbtMode (const uint8_t sbtInfo); bool isSameSbtSize (const uint8_t sbtInfo1, const uint8_t sbtInfo2); - bool getRprScaling ( const SPS* sps, const PPS* curPPS, Picture* refPic, int& xScale, int& yScale ); + bool getRprScaling(const SPS *sps, const PPS *curPPS, Picture *refPic, ScalingRatio &scalingRatio); void checkConformanceILRP (Slice *slice); } // PU tools diff --git a/source/Lib/DecoderLib/DecLib.cpp b/source/Lib/DecoderLib/DecLib.cpp index 575619609..ed21e7166 100644 --- a/source/Lib/DecoderLib/DecLib.cpp +++ b/source/Lib/DecoderLib/DecLib.cpp @@ -825,15 +825,15 @@ void DecLib::finishPicture(int &poc, PicList *&rpcListPic, MsgLevel msgl, bool a msg(msgl, "[L%d", refList); for (int refIndex = 0; refIndex < pcSlice->getNumRefIdx(RefPicList(refList)); refIndex++) { - const std::pair<int, int> &scaleRatio = pcSlice->getScalingRatio(RefPicList(refList), refIndex); + const ScalingRatio &scaleRatio = pcSlice->getScalingRatio(RefPicList(refList), refIndex); if (pcSlice->getPicHeader()->getEnableTMVPFlag() && pcSlice->getColFromL0Flag() == bool(1 - refList) && pcSlice->getColRefIdx() == refIndex) { - if( scaleRatio.first != 1 << SCALE_RATIO_BITS || scaleRatio.second != 1 << SCALE_RATIO_BITS ) + if (scaleRatio != SCALE_1X) { msg(msgl, " %dc(%1.2lfx, %1.2lfx)", pcSlice->getRefPOC(RefPicList(refList), refIndex), - double(scaleRatio.first) / (1 << SCALE_RATIO_BITS), double(scaleRatio.second) / (1 << SCALE_RATIO_BITS)); + double(scaleRatio.x) / (1 << ScalingRatio::BITS), double(scaleRatio.y) / (1 << ScalingRatio::BITS)); } else { @@ -842,10 +842,10 @@ void DecLib::finishPicture(int &poc, PicList *&rpcListPic, MsgLevel msgl, bool a } else { - if( scaleRatio.first != 1 << SCALE_RATIO_BITS || scaleRatio.second != 1 << SCALE_RATIO_BITS ) + if (scaleRatio != SCALE_1X) { msg(msgl, " %d(%1.2lfx, %1.2lfx)", pcSlice->getRefPOC(RefPicList(refList), refIndex), - double(scaleRatio.first) / (1 << SCALE_RATIO_BITS), double(scaleRatio.second) / (1 << SCALE_RATIO_BITS)); + double(scaleRatio.x) / (1 << ScalingRatio::BITS), double(scaleRatio.y) / (1 << ScalingRatio::BITS)); } else { diff --git a/source/Lib/EncoderLib/EncGOP.cpp b/source/Lib/EncoderLib/EncGOP.cpp index e94c59cd9..8616bf153 100644 --- a/source/Lib/EncoderLib/EncGOP.cpp +++ b/source/Lib/EncoderLib/EncGOP.cpp @@ -5000,11 +5000,10 @@ void EncGOP::xCalculateAddPSNR(Picture* pcPic, PelUnitBuf cPicD, const AccessUni const CPelBuf& upscaledOrg = (sps.getUseLmcs() || m_pcCfg->getGopBasedTemporalFilterEnabled()) ? pcPic->M_BUFS( 0, PIC_TRUE_ORIGINAL_INPUT).get( COMPONENT_Y ) : pcPic->M_BUFS( 0, PIC_ORIGINAL_INPUT).get( COMPONENT_Y ); upscaledRec.create( pic.chromaFormat, Area( Position(), upscaledOrg ) ); - int xScale, yScale; + ScalingRatio scalingRatio; // it is assumed that full resolution picture PPS has ppsId 0 const PPS* pps = m_pcEncLib->getPPS(0); - CU::getRprScaling( &sps, pps, pcPic, xScale, yScale ); - std::pair<int, int> scalingRatio = std::pair<int, int>( xScale, yScale ); + CU::getRprScaling(&sps, pps, pcPic, scalingRatio); #if JVET_AB0081 bool rescaleForDisplay = true; @@ -5313,16 +5312,15 @@ void EncGOP::xCalculateAddPSNR(Picture* pcPic, PelUnitBuf cPicD, const AccessUni msg(NOTICE, " [L%d", refList); for (int refIndex = 0; refIndex < pcSlice->getNumRefIdx(RefPicList(refList)); refIndex++) { - const std::pair<int, int> &scaleRatio = pcSlice->getScalingRatio(RefPicList(refList), refIndex); + const ScalingRatio &scaleRatio = pcSlice->getScalingRatio(RefPicList(refList), refIndex); if (pcPic->cs->picHeader->getEnableTMVPFlag() && pcSlice->getColFromL0Flag() == bool(1 - refList) && pcSlice->getColRefIdx() == refIndex) { - if( scaleRatio.first != 1 << SCALE_RATIO_BITS || scaleRatio.second != 1 << SCALE_RATIO_BITS ) + if (scaleRatio != SCALE_1X) { msg(NOTICE, " %dc(%1.2lfx, %1.2lfx)", pcSlice->getRefPOC(RefPicList(refList), refIndex), - double(scaleRatio.first) / (1 << SCALE_RATIO_BITS), - double(scaleRatio.second) / (1 << SCALE_RATIO_BITS)); + double(scaleRatio.x) / (1 << ScalingRatio::BITS), double(scaleRatio.y) / (1 << ScalingRatio::BITS)); } else { @@ -5331,11 +5329,10 @@ void EncGOP::xCalculateAddPSNR(Picture* pcPic, PelUnitBuf cPicD, const AccessUni } else { - if( scaleRatio.first != 1 << SCALE_RATIO_BITS || scaleRatio.second != 1 << SCALE_RATIO_BITS ) + if (scaleRatio != SCALE_1X) { msg(NOTICE, " %d(%1.2lfx, %1.2lfx)", pcSlice->getRefPOC(RefPicList(refList), refIndex), - double(scaleRatio.first) / (1 << SCALE_RATIO_BITS), - double(scaleRatio.second) / (1 << SCALE_RATIO_BITS)); + double(scaleRatio.x) / (1 << ScalingRatio::BITS), double(scaleRatio.y) / (1 << ScalingRatio::BITS)); } else { diff --git a/source/Lib/EncoderLib/EncLib.cpp b/source/Lib/EncoderLib/EncLib.cpp index 77036443c..bf2b45304 100644 --- a/source/Lib/EncoderLib/EncLib.cpp +++ b/source/Lib/EncoderLib/EncLib.cpp @@ -713,12 +713,8 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv double upscaledPSNR = 0.0; if (poc % getGOPSize() == 0) { - int xScale = 32768; - int yScale = 32768; - std::pair<int, int> downScalingRatio = std::pair<int, int>(xScale, yScale); - xScale = 8192; - yScale = 8192; - std::pair<int, int> upScalingRatio = std::pair<int, int>(xScale, yScale); + ScalingRatio downScalingRatio{ 32768, 32768 }; + ScalingRatio upScalingRatio{ 8192, 8192 }; const PPS* orgPPS = m_ppsMap.getPS(0); const SPS* orgSPS = m_spsMap.getPS(orgPPS->getSPSId()); @@ -848,9 +844,10 @@ bool EncLib::encodePrep(bool flush, PelStorage *pcPicYuvOrg, PelStorage *cPicYuv int refPicWidth = refPPS->getPicWidthInLumaSamples() - SPS::getWinUnitX( pSPS->getChromaFormatIdc() ) * ( refScalingWindow.getWindowLeftOffset() + refScalingWindow.getWindowRightOffset() ); int refPicHeight = refPPS->getPicHeightInLumaSamples() - SPS::getWinUnitY( pSPS->getChromaFormatIdc() ) * ( refScalingWindow.getWindowTopOffset() + refScalingWindow.getWindowBottomOffset() ); - int xScale = ( ( refPicWidth << SCALE_RATIO_BITS ) + ( curPicWidth >> 1 ) ) / curPicWidth; - int yScale = ( ( refPicHeight << SCALE_RATIO_BITS ) + ( curPicHeight >> 1 ) ) / curPicHeight; - std::pair<int, int> scalingRatio = std::pair<int, int>( xScale, yScale ); + const int xScale = ((refPicWidth << ScalingRatio::BITS) + (curPicWidth >> 1)) / curPicWidth; + const int yScale = ((refPicHeight << ScalingRatio::BITS) + (curPicHeight >> 1)) / curPicHeight; + + const ScalingRatio scalingRatio = { xScale, yScale }; Picture::rescalePicture(scalingRatio, *pcPicYuvOrg, refPPS->getScalingWindow(), pcPicCurr->getOrigBuf(), pPPS->getScalingWindow(), chromaFormatIDC, pSPS->getBitDepths(), true, true, diff --git a/source/Lib/EncoderLib/InterSearch.cpp b/source/Lib/EncoderLib/InterSearch.cpp index 819ce8898..268e9a49a 100644 --- a/source/Lib/EncoderLib/InterSearch.cpp +++ b/source/Lib/EncoderLib/InterSearch.cpp @@ -2082,7 +2082,7 @@ bool InterSearch::xRectHashInterEstimation(PredictionUnit& pu, RefPicList& bestR } m_numHashMVStoreds[eRefPicList][refIdx] = 0; - const std::pair<int, int>& scaleRatio = pu.cu->slice->getScalingRatio( eRefPicList, refIdx ); + const ScalingRatio &scaleRatio = pu.cu->slice->getScalingRatio(eRefPicList, refIdx); if( scaleRatio != SCALE_1X ) { continue; @@ -2384,7 +2384,7 @@ bool InterSearch::xHashInterEstimation(PredictionUnit& pu, RefPicList& bestRefPi } m_numHashMVStoreds[eRefPicList][refIdx] = 0; - const std::pair<int, int>& scaleRatio = pu.cu->slice->getScalingRatio( eRefPicList, refIdx ); + const ScalingRatio &scaleRatio = pu.cu->slice->getScalingRatio(eRefPicList, refIdx); if( scaleRatio != SCALE_1X ) { continue; diff --git a/source/Lib/Utilities/VideoIOYuv.cpp b/source/Lib/Utilities/VideoIOYuv.cpp index a79e24dab..155c1c595 100644 --- a/source/Lib/Utilities/VideoIOYuv.cpp +++ b/source/Lib/Utilities/VideoIOYuv.cpp @@ -1448,14 +1448,19 @@ bool VideoIOYuv::writeUpscaledPicture(const SPS &sps, const PPS &pps, const CPel int refPicWidth = pps.getPicWidthInLumaSamples() - SPS::getWinUnitX( sps.getChromaFormatIdc() ) * ( beforeScalingWindow.getWindowLeftOffset() + beforeScalingWindow.getWindowRightOffset() ); int refPicHeight = pps.getPicHeightInLumaSamples() - SPS::getWinUnitY( sps.getChromaFormatIdc() ) * ( beforeScalingWindow.getWindowTopOffset() + beforeScalingWindow.getWindowBottomOffset() ); - int xScale = ( ( refPicWidth << SCALE_RATIO_BITS ) + ( curPicWidth >> 1 ) ) / curPicWidth; - int yScale = ( ( refPicHeight << SCALE_RATIO_BITS ) + ( curPicHeight >> 1 ) ) / curPicHeight; + const int xScale = ((refPicWidth << ScalingRatio::BITS) + (curPicWidth >> 1)) / curPicWidth; + const int yScale = ((refPicHeight << ScalingRatio::BITS) + (curPicHeight >> 1)) / curPicHeight; #if JVET_AB0081 bool rescaleForDisplay = true; - Picture::rescalePicture(std::pair<int, int>(xScale, yScale), pic, pps.getScalingWindow(), upscaledPic, afterScaleWindowFullResolution, chromaFormatIDC, sps.getBitDepths(), false, false, sps.getHorCollocatedChromaFlag(), sps.getVerCollocatedChromaFlag(), rescaleForDisplay, upscaleFilterForDisplay); + Picture::rescalePicture({ xScale, yScale }, pic, pps.getScalingWindow(), upscaledPic, + afterScaleWindowFullResolution, chromaFormatIDC, sps.getBitDepths(), false, false, + sps.getHorCollocatedChromaFlag(), sps.getVerCollocatedChromaFlag(), rescaleForDisplay, + upscaleFilterForDisplay); #else - Picture::rescalePicture( std::pair<int, int>( xScale, yScale ), pic, pps.getScalingWindow(), upscaledPic, afterScaleWindowFullResolution, chromaFormatIDC, sps.getBitDepths(), false, false, sps.getHorCollocatedChromaFlag(), sps.getVerCollocatedChromaFlag() ); + Picture::rescalePicture({ xScale, yScale }, pic, pps.getScalingWindow(), upscaledPic, + afterScaleWindowFullResolution, chromaFormatIDC, sps.getBitDepths(), false, false, + sps.getHorCollocatedChromaFlag(), sps.getVerCollocatedChromaFlag()); #endif ret = write(sps.getMaxPicWidthInLumaSamples(), sps.getMaxPicHeightInLumaSamples(), upscaledPic, ipCSC, packedYuvOutputMode, confFullResolution.getWindowLeftOffset() * SPS::getWinUnitX(chromaFormatIDC), -- GitLab