From 6da802d107c2b6dc9390bb669ac93129c24d1f97 Mon Sep 17 00:00:00 2001 From: Gu_Peiyi Date: Fri, 11 Oct 2024 18:56:51 +0800 Subject: [PATCH] [VP] Fix L0 FC CSC Bias Normalization fix l0 fc csc bias normalization wrong. switch bewtween 1023 and 255 denpends on convert type --- .../vp/hal/features/vp_l0_fc_filter.cpp | 41 +++++++------------ .../agnostic/common/vp/hal/utils/vp_utils.cpp | 37 ++++++++++++++++- .../agnostic/common/vp/hal/utils/vp_utils.h | 17 ++++++++ 3 files changed, 68 insertions(+), 27 deletions(-) diff --git a/media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp b/media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp index 0d628ee1f28..07359324083 100644 --- a/media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp +++ b/media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp @@ -1439,31 +1439,31 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP if (IS_COLOR_SPACE_RGB(dstColorSpace) && !IS_COLOR_SPACE_RGB(srcColorSpace)) { - KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, backCscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, backCscMatrix)); bBackCscEnabled = true; // YUV -> RGB } else if (IS_COLOR_SPACE_RGB(srcColorSpace) && !IS_COLOR_SPACE_RGB(dstColorSpace)) { - KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix)); bPreCscEnabled = true; // RGB -> YUV } else if (IS_COLOR_SPACE_BT709_RGB(srcColorSpace) && IS_COLOR_SPACE_BT709_RGB(dstColorSpace)) { - KernelDll_GetCSCMatrix(srcColorSpace, CSpace_BT709, preCscMatrix); - KernelDll_GetCSCMatrix(CSpace_BT709, dstColorSpace, backCscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, CSpace_BT709, preCscMatrix)); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(CSpace_BT709, dstColorSpace, backCscMatrix)); bPreCscEnabled = bBackCscEnabled = true; // 8bit RGB -> RGB } else if (IS_COLOR_SPACE_BT2020_RGB(srcColorSpace) && IS_COLOR_SPACE_BT2020_RGB(dstColorSpace)) { - KernelDll_GetCSCMatrix(srcColorSpace, CSpace_BT2020, preCscMatrix); - KernelDll_GetCSCMatrix(CSpace_BT2020, dstColorSpace, backCscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, CSpace_BT2020, preCscMatrix)); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(CSpace_BT2020, dstColorSpace, backCscMatrix)); bPreCscEnabled = bBackCscEnabled = true; // 10bit RGB -> RGB } else { if (srcColorSpace != dstColorSpace) { - KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix)); bPreCscEnabled = true; // YUV -> YUV VP_PUBLIC_NORMALMESSAGE("YUV to YUV colorspace. Need pre csc matrix."); } @@ -1474,8 +1474,6 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP } // Calculate procamp parameters - // BT2020 is [0, 1023], BT709 is [0, 255], BT2020 need * 4. - int coefficient = IS_COLOR_SPACE_BT2020(dstColorSpace) ? 4 : 1; float brightness, contrast, hue, saturation; brightness = procampParams.fBrightness; contrast = procampParams.fContrast; @@ -1493,15 +1491,15 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP procampMatrix[0] = contrast; procampMatrix[1] = 0.0f; procampMatrix[2] = 0.0f; - procampMatrix[3] = 16.0f * coefficient - 16.0f * coefficient * contrast + brightness; + procampMatrix[3] = (16.0f - 16.0f * contrast + brightness) / 255.f; procampMatrix[4] = 0.0f; procampMatrix[5] = (float)cos(hue) * contrast * saturation; procampMatrix[6] = (float)sin(hue) * contrast * saturation; - procampMatrix[7] = 128.0f * coefficient * (1.0f - procampMatrix[5] - procampMatrix[6]); + procampMatrix[7] = (128.0f * (1.0f - procampMatrix[5] - procampMatrix[6])) / 255.f; procampMatrix[8] = 0.0f; procampMatrix[9] = -procampMatrix[6]; procampMatrix[10] = procampMatrix[5]; - procampMatrix[11] = 128.0f * coefficient * (1.0f - procampMatrix[5] + procampMatrix[6]); + procampMatrix[11] = (128.0f * (1.0f - procampMatrix[5] + procampMatrix[6])) / 255.f; // Calculate final CSC matrix [backcsc] * [pa] * [precsc] if (bPreCscEnabled) @@ -1516,7 +1514,7 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP } // Use the output matrix copy into csc matrix to generate kernel CSC parameters - MOS_SecureMemcpy(cscMatrix, sizeof(float) * 12, (void *)procampMatrix, sizeof(float)*12); + MOS_SecureMemcpy(cscMatrix, sizeof(float) * 12, (void *)procampMatrix, sizeof(float) * 12); return MOS_STATUS_SUCCESS; } @@ -1537,26 +1535,17 @@ MOS_STATUS VpL0FcFilter::ConvertProcampAndCscToKrnParam(VPHAL_CSPACE srcColorSpa return MOS_STATUS_SUCCESS; } - KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, cscMatrix); + VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, cscMatrix)); } // Save finalMatrix into csc VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s0123, sizeof(csc.s0123), &cscMatrix[0], sizeof(float) * 3)); VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s4567, sizeof(csc.s4567), &cscMatrix[4], sizeof(float) * 3)); VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s89AB, sizeof(csc.s89AB), &cscMatrix[8], sizeof(float) * 3)); + csc.sCDEF[0] = cscMatrix[3]; + csc.sCDEF[1] = cscMatrix[7]; + csc.sCDEF[2] = cscMatrix[11]; - if (IS_COLOR_SPACE_BT2020(dstColorSpace)) - { - csc.sCDEF[0] = cscMatrix[3] / 1023; - csc.sCDEF[1] = cscMatrix[7] / 1023; - csc.sCDEF[2] = cscMatrix[11] / 1023; - } - else - { - csc.sCDEF[0] = cscMatrix[3] / 255; - csc.sCDEF[1] = cscMatrix[7] / 255; - csc.sCDEF[2] = cscMatrix[11] / 255; - } return MOS_STATUS_SUCCESS; } diff --git a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp index 392cde6d105..8669b4afaa3 100644 --- a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp +++ b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp @@ -423,7 +423,7 @@ MOS_STATUS VpUtils::GetPixelWithCSCForColorFill( else if (IS_COLOR_SPACE_BT2020(dstCspace)) { // Target is BT2020, which is not supported by legacy convert - VP_PUBLIC_NORMALMESSAGE("Will do special convert to BT2020. Source Cspace %d. Target Cspace %d", srcCspace, dstColor); + VP_PUBLIC_NORMALMESSAGE("Will do special convert to BT2020. Source Cspace %d. Target Cspace %d", srcCspace, dstCspace); float pCscMatrix[12] = {}; auto SDRDegamma_sRGB_x1 = [](float c) -> float { if (c <= VPHAL_HDR_EOTF_COEFF1_TRADITIONNAL_GAMMA_SRGB) @@ -534,5 +534,40 @@ MOS_STATUS VpUtils::GetPixelWithCSCForColorFill( } } + return MOS_STATUS_SUCCESS; +} + +MOS_STATUS VpUtils::GetNormalizedCSCMatrix( + MEDIA_CSPACE src, + MEDIA_CSPACE dst, + float cscMatrix[12]) +{ + VP_PUBLIC_CHK_NULL_RETURN(cscMatrix); + + if ((IS_COLOR_SPACE_BT2020(src) && !IS_COLOR_SPACE_BT2020(dst)) || + (!IS_COLOR_SPACE_BT2020(src) && IS_COLOR_SPACE_BT2020(dst))) + { + VP_PUBLIC_ASSERTMESSAGE("Not support hdr to sdr or sdr to hdr csc convert. Src CSpace %d, Dst CSpace %d", src, dst); + } + + KernelDll_GetCSCMatrix(src, dst, cscMatrix); + + //for BT2020RGB convert to BT2020RGB, KernelDll_GetCSCMatrix use 1023 as max bias + //for other cases, such as sRGB/BT709/BT601 and BT2020YUV convert BT2020RGB, KernelDll_GetCSCMatrix use 255 as max bias + //so need to normalize w/ different value + if ((src == CSpace_BT2020_stRGB && dst == CSpace_BT2020_RGB) || + (src == CSpace_BT2020_RGB && dst == CSpace_BT2020_stRGB)) + { + cscMatrix[3] /= 1023.f; + cscMatrix[7] /= 1023.f; + cscMatrix[11] /= 1023.f; + } + else + { + cscMatrix[3] /= 255.f; + cscMatrix[7] /= 255.f; + cscMatrix[11] /= 255.f; + } + return MOS_STATUS_SUCCESS; } \ No newline at end of file diff --git a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.h b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.h index 779b53689fb..25354cbc79f 100644 --- a/media_softlet/agnostic/common/vp/hal/utils/vp_utils.h +++ b/media_softlet/agnostic/common/vp/hal/utils/vp_utils.h @@ -468,6 +468,23 @@ class VpUtils VPHAL_CSPACE srcCspace, VPHAL_CSPACE dstCspace); + //! + //! \brief Get Color Space Convert Normalized Matrix + //! \details Get Color Space Convert Normalized Matrix + //! \param [out] pCSC_Matrix + //! Pointer to float + //! \param [in] src + //! Source Color Space + //! \param [in] dst + //! Target Color Space + //! \return MOS_STATUS + //! Return MOS_STATUS_SUCCESS if successful + //! + static MOS_STATUS GetNormalizedCSCMatrix( + MEDIA_CSPACE src, + MEDIA_CSPACE dst, + float cscMatrix[12]); + private: //! //! \brief Performs Color Space Convert for Sample 8 bit Using Specified Coeff Matrix