diff --git a/source/Lib/CommonLib/DepQuant.cpp b/source/Lib/CommonLib/DepQuant.cpp index 5373fe7ceb7e60811f9f5b14c43cc5a9a9b9239a..29794986be8be56f00e4cfa77112c363d0641fe7 100644 --- a/source/Lib/CommonLib/DepQuant.cpp +++ b/source/Lib/CommonLib/DepQuant.cpp @@ -666,8 +666,13 @@ namespace DQIntern m_QShift = QUANT_SHIFT - 1 + qpPer + transformShift; m_QAdd = -( ( 3 << m_QShift ) >> 1 ); #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + Intermediate_Int invShift = IQUANT_SHIFT + 1 - qpPer - transformShift + ( TU::needsBlockSizeTrafoScale( tu, compID ) ? ADJ_DEQUANT_SHIFT : 0 ); + m_QScale = ( TU::needsSqrt2Scale( tu, compID ) ? ( g_quantScales[ qpRem ] * 181 ) >> 7 : g_quantScales[ qpRem ] ); +#else Intermediate_Int invShift = IQUANT_SHIFT + 1 - qpPer - transformShift + ( TU::needsBlockSizeTrafoScale( area ) ? ADJ_DEQUANT_SHIFT : 0 ); m_QScale = ( TU::needsSqrt2Scale( area ) ? ( g_quantScales[ qpRem ] * 181 ) >> 7 : g_quantScales[ qpRem ] ); +#endif #else Intermediate_Int invShift = IQUANT_SHIFT + 1 - qpPer - transformShift; m_QScale = g_quantScales [ qpRem ]; @@ -750,8 +755,13 @@ namespace DQIntern #endif const int transformShift = ( clipTransformShift ? std::max<int>( 0, nomTransformShift ) : nomTransformShift ); #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + Intermediate_Int shift = IQUANT_SHIFT + 1 - qpPer - transformShift + ( TU::needsBlockSizeTrafoScale( tu, compID ) ? ADJ_DEQUANT_SHIFT : 0 ); + Intermediate_Int invQScale = g_invQuantScales[ qpRem ] * ( TU::needsSqrt2Scale( tu, compID ) ? 181 : 1 ); +#else Intermediate_Int shift = IQUANT_SHIFT + 1 - qpPer - transformShift + ( TU::needsBlockSizeTrafoScale( area ) ? ADJ_DEQUANT_SHIFT : 0 ); Intermediate_Int invQScale = g_invQuantScales[ qpRem ] * ( TU::needsSqrt2Scale( area ) ? 181 : 1 ); +#endif #else Intermediate_Int shift = IQUANT_SHIFT + 1 - qpPer - transformShift; Intermediate_Int invQScale = g_invQuantScales[ qpRem ]; diff --git a/source/Lib/CommonLib/Quant.cpp b/source/Lib/CommonLib/Quant.cpp index ca477139b28c97e7342b3cae0b7c14d1494355ac..5829874da0427ff5d161ab7062b18d7b193aeabb 100644 --- a/source/Lib/CommonLib/Quant.cpp +++ b/source/Lib/CommonLib/Quant.cpp @@ -313,8 +313,13 @@ void Quant::dequant(const TransformUnit &tu, const int QP_rem = cQP.rem; #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + const bool needsScalingCorrection = TU::needsBlockSizeTrafoScale( tu, compID ); + const int NEScale = TU::needsSqrt2Scale( tu, compID ) ? 181 : 1; +#else const bool needsScalingCorrection = TU::needsBlockSizeTrafoScale( tu.block( compID ) ); const int NEScale = TU::needsSqrt2Scale( tu.blocks[compID] ) ? 181 : 1; +#endif #if HEVC_USE_SCALING_LISTS const int rightShift = (needsScalingCorrection ? 8 : 0 ) + (IQUANT_SHIFT - (iTransformShift + QP_per)) + (enableScalingLists ? LOG2_SCALING_LIST_NEUTRAL_VALUE : 0); #else @@ -767,7 +772,11 @@ void Quant::quant(TransformUnit &tu, const ComponentID &compID, const CCoeffBuf int iWHScale = 1; #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + if( TU::needsBlockSizeTrafoScale( tu, compID ) ) +#else if( TU::needsBlockSizeTrafoScale( rect ) ) +#endif { iTransformShift += ADJ_QUANT_SHIFT; iWHScale = 181; @@ -863,7 +872,11 @@ bool Quant::xNeedRDOQ(TransformUnit &tu, const ComponentID &compID, const CCoeff int iWHScale = 1; #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + if( TU::needsBlockSizeTrafoScale( tu, compID ) ) +#else if( TU::needsBlockSizeTrafoScale( rect ) ) +#endif { iTransformShift += ADJ_QUANT_SHIFT; iWHScale = 181; diff --git a/source/Lib/CommonLib/QuantRDOQ.cpp b/source/Lib/CommonLib/QuantRDOQ.cpp index fa0e835589ff0e64904fe768e117d1b94cbc0243..36866aaf8577fc05d0c0ec2e880aff576220ba6c 100644 --- a/source/Lib/CommonLib/QuantRDOQ.cpp +++ b/source/Lib/CommonLib/QuantRDOQ.cpp @@ -408,15 +408,25 @@ void QuantRDOQ::setScalingList(ScalingList *scalingList, const int maxLog2TrDyna #endif #else +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT +double QuantRDOQ::xGetErrScaleCoeff( const bool needsSqrt2, SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth ) +#else double QuantRDOQ::xGetErrScaleCoeff( SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth ) +#endif { const int iTransformShift = getTransformShift(channelBitDepth, Size(width, height), maxLog2TrDynamicRange); #if HM_QTBT_AS_IN_JEM_QUANT double dErrScale = (double)( 1 << SCALE_BITS ); // Compensate for scaling of bitcount in Lagrange cost function +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + double dTransShift = (double)iTransformShift + ( needsSqrt2 ? -0.5 : 0.0 ); + dErrScale = dErrScale*pow( 2.0, ( -2.0*dTransShift ) ); // Compensate for scaling through forward transform + int QStep = ( needsSqrt2 ? ( ( g_quantScales[qp] * 181 ) >> 7 ) : g_quantScales[qp] ); +#else bool needsSrqt2 = TU::needsBlockSizeTrafoScale( Size(width, height) );// ( ( (sizeX+sizeY) & 1 ) !=0 ); double dTransShift = (double)iTransformShift + ( needsSrqt2 ? -0.5 : 0.0 ); dErrScale = dErrScale*pow( 2.0, ( -2.0*dTransShift ) ); // Compensate for scaling through forward transform int QStep = ( needsSrqt2 ? ( ( g_quantScales[qp] * 181 ) >> 7 ) : g_quantScales[qp] ); +#endif double finalErrScale = dErrScale / QStep / QStep / (1 << (DISTORTION_PRECISION_ADJUSTMENT(channelBitDepth) << 1)); #else int errShift = SCALE_BITS - ((iTransformShift + DISTORTION_PRECISION_ADJUSTMENT(channelBitDepth)) << 1); @@ -682,8 +692,13 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID, const bool enableScalingLists = getUseScalingList(uiWidth, uiHeight, tu.transformSkip[compID]); #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + const int defaultQuantisationCoefficient = ( TU::needsSqrt2Scale( rect, tu.transformSkip[compID] ) ? ( g_quantScales[cQP.rem] * 181 ) >> 7 : g_quantScales[cQP.rem] ); + const double defaultErrorScale = xGetErrScaleCoeffNoScalingList(scalingListType, (uiLog2BlockWidth-1), (uiLog2BlockHeight-1), cQP.rem); +#else const int defaultQuantisationCoefficient = ( TU::needsSqrt2Scale( rect ) ? ( g_quantScales[cQP.rem] * 181 ) >> 7 : g_quantScales[cQP.rem] ); const double defaultErrorScale = xGetErrScaleCoeffNoScalingList(scalingListType, (uiLog2BlockWidth-1), (uiLog2BlockHeight-1), cQP.rem); +#endif #else const double blkErrScale = ( TU::needsQP3Offset( tu, compID ) ? 2.0 : 1.0 ); const int defaultQuantisationCoefficient = g_quantScales[cQP.rem]; @@ -691,8 +706,13 @@ void QuantRDOQ::xRateDistOptQuant(TransformUnit &tu, const ComponentID &compID, #endif #else //HEVC_USE_SCALING_LISTS #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + const int quantisationCoefficient = ( TU::needsSqrt2Scale( tu, compID ) ? ( g_quantScales[cQP.rem] * 181 ) >> 7 : g_quantScales[cQP.rem] ); + const double errorScale = xGetErrScaleCoeff( TU::needsSqrt2Scale( tu, compID ), uiWidth, uiHeight, cQP.rem, maxLog2TrDynamicRange, channelBitDepth ); +#else const int quantisationCoefficient = ( TU::needsSqrt2Scale( rect ) ? ( g_quantScales[cQP.rem] * 181 ) >> 7 : g_quantScales[cQP.rem] ); const double errorScale = xGetErrScaleCoeff( uiWidth, uiHeight, cQP.rem, maxLog2TrDynamicRange, channelBitDepth ); +#endif #else const double blkErrScale = ( TU::needsQP3Offset( tu, compID ) ? 2.0 : 1.0 ); const int quantisationCoefficient = g_quantScales[cQP.rem]; diff --git a/source/Lib/CommonLib/QuantRDOQ.h b/source/Lib/CommonLib/QuantRDOQ.h index c29ab0eca4792cd0bd3c13723977a52eb201a6b1..037fab4d7d5ec44646ebca62be1b018f5bef5bb0 100644 --- a/source/Lib/CommonLib/QuantRDOQ.h +++ b/source/Lib/CommonLib/QuantRDOQ.h @@ -75,8 +75,12 @@ private: void xInitScalingList ( const QuantRDOQ* other ); void xDestroyScalingList (); void xSetErrScaleCoeff ( uint32_t list, uint32_t sizeX, uint32_t sizeY, int qp, const int maxLog2TrDynamicRange[MAX_NUM_CHANNEL_TYPE], const BitDepths &bitDepths ); +#else +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + double xGetErrScaleCoeff ( const bool needsSqrt2, SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth); #else double xGetErrScaleCoeff ( SizeType width, SizeType height, int qp, const int maxLog2TrDynamicRange, const int channelBitDepth); +#endif #endif // RDOQ functions diff --git a/source/Lib/CommonLib/TrQuant.cpp b/source/Lib/CommonLib/TrQuant.cpp index 6396fe5c3b8c378fed8af9451dcaa382e05b1394..f6192a5a1f6aef203b2a83cb8abaf81af726d27b 100644 --- a/source/Lib/CommonLib/TrQuant.cpp +++ b/source/Lib/CommonLib/TrQuant.cpp @@ -435,7 +435,7 @@ void TrQuant::xITransformSkip(const CCoeffBuf &pCoeff, } int iWHScale = 1; -#if HM_QTBT_AS_IN_JEM_QUANT +#if HM_QTBT_AS_IN_JEM_QUANT && !JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT if( TU::needsBlockSizeTrafoScale( area ) ) { iTransformShift += ADJ_QUANT_SHIFT; @@ -762,7 +762,7 @@ void TrQuant::xTransformSkip(const TransformUnit &tu, const ComponentID &compID, } int iWHScale = 1; -#if HM_QTBT_AS_IN_JEM_QUANT +#if HM_QTBT_AS_IN_JEM_QUANT && !JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT if( TU::needsBlockSizeTrafoScale( rect ) ) { iTransformShift -= ADJ_DEQUANT_SHIFT; diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index cb1dc56721259efdd479c56284673317f95b2bfc..dbad2e95bc4c59b8e4ad81c3d5c1062981a5b572 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -228,6 +228,8 @@ typedef std::pair<int, int> TrCost; #define HM_JEM_CLIP_PEL 1 // *** #define HM_JEM_MERGE_CANDS 0 // *** +#define JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT 1 + #endif//JEM_COMP // ==================================================================================================================== diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index f22199dbe8b3b7d34d04db19f50ad2d01f4a0c31..5b0fb93816988a6d3a882b8c7887b41d8472822e 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -4811,17 +4811,37 @@ uint32_t TU::getNumNonZeroCoeffsNonTS( const TransformUnit& tu, const bool bLuma return count; } +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT +bool TU::needsSqrt2Scale( const TransformUnit &tu, const ComponentID &compID ) +{ + const Size &size=tu.blocks[compID]; +#if JVET_M0464_UNI_MTS + const bool bTransformSkip = tu.mtsIdx==1; +#else + const bool bTransformSkip = tu.transformSkip[compID]; +#endif + return (!bTransformSkip) && (((g_aucLog2[size.width] + g_aucLog2[size.height]) & 1) == 1); +} +#else bool TU::needsSqrt2Scale( const Size& size ) { return (((g_aucLog2[size.width] + g_aucLog2[size.height]) & 1) == 1); } +#endif #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT +bool TU::needsBlockSizeTrafoScale( const TransformUnit &tu, const ComponentID &compID ) +{ + return needsSqrt2Scale( tu, compID ) || isNonLog2BlockSize( tu.blocks[compID] ); +} +#else bool TU::needsBlockSizeTrafoScale( const Size& size ) { return needsSqrt2Scale( size ) || isNonLog2BlockSize( size ); } +#endif #else bool TU::needsQP3Offset(const TransformUnit &tu, const ComponentID &compID) { diff --git a/source/Lib/CommonLib/UnitTools.h b/source/Lib/CommonLib/UnitTools.h index 5bbf165cae5329d9d182bc57c23661fff01f1ff7..a225e52997ce432461a14de0526fe1e23176e528 100644 --- a/source/Lib/CommonLib/UnitTools.h +++ b/source/Lib/CommonLib/UnitTools.h @@ -200,9 +200,18 @@ namespace TU #endif bool hasCrossCompPredInfo (const TransformUnit &tu, const ComponentID &compID); + +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + bool needsSqrt2Scale ( const TransformUnit &tu, const ComponentID &compID ); +#else bool needsSqrt2Scale ( const Size& size ); +#endif #if HM_QTBT_AS_IN_JEM_QUANT +#if JVET_M0119_NO_TRANSFORM_SKIP_QUANTISATION_ADJUSTMENT + bool needsBlockSizeTrafoScale ( const TransformUnit &tu, const ComponentID &compID ); +#else bool needsBlockSizeTrafoScale ( const Size& size ); +#endif #else bool needsQP3Offset (const TransformUnit &tu, const ComponentID &compID); #endif