Skip to content

Commit

Permalink
[VP] Fix L0 FC CSC Bias Normalization
Browse files Browse the repository at this point in the history
fix l0 fc csc bias normalization wrong. switch bewtween 1023 and 255 denpends on convert type
  • Loading branch information
peiyigu-intel authored and intel-mediadev committed Oct 11, 2024
1 parent ce9892c commit 6da802d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
41 changes: 15 additions & 26 deletions media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
37 changes: 36 additions & 1 deletion media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
17 changes: 17 additions & 0 deletions media_softlet/agnostic/common/vp/hal/utils/vp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6da802d

Please sign in to comment.