Skip to content

Commit 6da802d

Browse files
peiyigu-intelintel-mediadev
authored andcommitted
[VP] Fix L0 FC CSC Bias Normalization
fix l0 fc csc bias normalization wrong. switch bewtween 1023 and 255 denpends on convert type
1 parent ce9892c commit 6da802d

File tree

3 files changed

+68
-27
lines changed

3 files changed

+68
-27
lines changed

media_softlet/agnostic/common/vp/hal/features/vp_l0_fc_filter.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,31 +1439,31 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP
14391439

14401440
if (IS_COLOR_SPACE_RGB(dstColorSpace) && !IS_COLOR_SPACE_RGB(srcColorSpace))
14411441
{
1442-
KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, backCscMatrix);
1442+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, backCscMatrix));
14431443
bBackCscEnabled = true; // YUV -> RGB
14441444
}
14451445
else if (IS_COLOR_SPACE_RGB(srcColorSpace) && !IS_COLOR_SPACE_RGB(dstColorSpace))
14461446
{
1447-
KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix);
1447+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix));
14481448
bPreCscEnabled = true; // RGB -> YUV
14491449
}
14501450
else if (IS_COLOR_SPACE_BT709_RGB(srcColorSpace) && IS_COLOR_SPACE_BT709_RGB(dstColorSpace))
14511451
{
1452-
KernelDll_GetCSCMatrix(srcColorSpace, CSpace_BT709, preCscMatrix);
1453-
KernelDll_GetCSCMatrix(CSpace_BT709, dstColorSpace, backCscMatrix);
1452+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, CSpace_BT709, preCscMatrix));
1453+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(CSpace_BT709, dstColorSpace, backCscMatrix));
14541454
bPreCscEnabled = bBackCscEnabled = true; // 8bit RGB -> RGB
14551455
}
14561456
else if (IS_COLOR_SPACE_BT2020_RGB(srcColorSpace) && IS_COLOR_SPACE_BT2020_RGB(dstColorSpace))
14571457
{
1458-
KernelDll_GetCSCMatrix(srcColorSpace, CSpace_BT2020, preCscMatrix);
1459-
KernelDll_GetCSCMatrix(CSpace_BT2020, dstColorSpace, backCscMatrix);
1458+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, CSpace_BT2020, preCscMatrix));
1459+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(CSpace_BT2020, dstColorSpace, backCscMatrix));
14601460
bPreCscEnabled = bBackCscEnabled = true; // 10bit RGB -> RGB
14611461
}
14621462
else
14631463
{
14641464
if (srcColorSpace != dstColorSpace)
14651465
{
1466-
KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix);
1466+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, preCscMatrix));
14671467
bPreCscEnabled = true; // YUV -> YUV
14681468
VP_PUBLIC_NORMALMESSAGE("YUV to YUV colorspace. Need pre csc matrix.");
14691469
}
@@ -1474,8 +1474,6 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP
14741474
}
14751475

14761476
// Calculate procamp parameters
1477-
// BT2020 is [0, 1023], BT709 is [0, 255], BT2020 need * 4.
1478-
int coefficient = IS_COLOR_SPACE_BT2020(dstColorSpace) ? 4 : 1;
14791477
float brightness, contrast, hue, saturation;
14801478
brightness = procampParams.fBrightness;
14811479
contrast = procampParams.fContrast;
@@ -1493,15 +1491,15 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP
14931491
procampMatrix[0] = contrast;
14941492
procampMatrix[1] = 0.0f;
14951493
procampMatrix[2] = 0.0f;
1496-
procampMatrix[3] = 16.0f * coefficient - 16.0f * coefficient * contrast + brightness;
1494+
procampMatrix[3] = (16.0f - 16.0f * contrast + brightness) / 255.f;
14971495
procampMatrix[4] = 0.0f;
14981496
procampMatrix[5] = (float)cos(hue) * contrast * saturation;
14991497
procampMatrix[6] = (float)sin(hue) * contrast * saturation;
1500-
procampMatrix[7] = 128.0f * coefficient * (1.0f - procampMatrix[5] - procampMatrix[6]);
1498+
procampMatrix[7] = (128.0f * (1.0f - procampMatrix[5] - procampMatrix[6])) / 255.f;
15011499
procampMatrix[8] = 0.0f;
15021500
procampMatrix[9] = -procampMatrix[6];
15031501
procampMatrix[10] = procampMatrix[5];
1504-
procampMatrix[11] = 128.0f * coefficient * (1.0f - procampMatrix[5] + procampMatrix[6]);
1502+
procampMatrix[11] = (128.0f * (1.0f - procampMatrix[5] + procampMatrix[6])) / 255.f;
15051503

15061504
// Calculate final CSC matrix [backcsc] * [pa] * [precsc]
15071505
if (bPreCscEnabled)
@@ -1516,7 +1514,7 @@ MOS_STATUS VpL0FcFilter::GenerateProcampCscMatrix(VPHAL_CSPACE srcColorSpace, VP
15161514
}
15171515

15181516
// Use the output matrix copy into csc matrix to generate kernel CSC parameters
1519-
MOS_SecureMemcpy(cscMatrix, sizeof(float) * 12, (void *)procampMatrix, sizeof(float)*12);
1517+
MOS_SecureMemcpy(cscMatrix, sizeof(float) * 12, (void *)procampMatrix, sizeof(float) * 12);
15201518
return MOS_STATUS_SUCCESS;
15211519
}
15221520

@@ -1537,26 +1535,17 @@ MOS_STATUS VpL0FcFilter::ConvertProcampAndCscToKrnParam(VPHAL_CSPACE srcColorSpa
15371535
return MOS_STATUS_SUCCESS;
15381536
}
15391537

1540-
KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, cscMatrix);
1538+
VP_PUBLIC_CHK_STATUS_RETURN(VpUtils::GetNormalizedCSCMatrix(srcColorSpace, dstColorSpace, cscMatrix));
15411539
}
15421540

15431541
// Save finalMatrix into csc
15441542
VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s0123, sizeof(csc.s0123), &cscMatrix[0], sizeof(float) * 3));
15451543
VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s4567, sizeof(csc.s4567), &cscMatrix[4], sizeof(float) * 3));
15461544
VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s89AB, sizeof(csc.s89AB), &cscMatrix[8], sizeof(float) * 3));
1545+
csc.sCDEF[0] = cscMatrix[3];
1546+
csc.sCDEF[1] = cscMatrix[7];
1547+
csc.sCDEF[2] = cscMatrix[11];
15471548

1548-
if (IS_COLOR_SPACE_BT2020(dstColorSpace))
1549-
{
1550-
csc.sCDEF[0] = cscMatrix[3] / 1023;
1551-
csc.sCDEF[1] = cscMatrix[7] / 1023;
1552-
csc.sCDEF[2] = cscMatrix[11] / 1023;
1553-
}
1554-
else
1555-
{
1556-
csc.sCDEF[0] = cscMatrix[3] / 255;
1557-
csc.sCDEF[1] = cscMatrix[7] / 255;
1558-
csc.sCDEF[2] = cscMatrix[11] / 255;
1559-
}
15601549
return MOS_STATUS_SUCCESS;
15611550
}
15621551

media_softlet/agnostic/common/vp/hal/utils/vp_utils.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ MOS_STATUS VpUtils::GetPixelWithCSCForColorFill(
423423
else if (IS_COLOR_SPACE_BT2020(dstCspace))
424424
{
425425
// Target is BT2020, which is not supported by legacy convert
426-
VP_PUBLIC_NORMALMESSAGE("Will do special convert to BT2020. Source Cspace %d. Target Cspace %d", srcCspace, dstColor);
426+
VP_PUBLIC_NORMALMESSAGE("Will do special convert to BT2020. Source Cspace %d. Target Cspace %d", srcCspace, dstCspace);
427427
float pCscMatrix[12] = {};
428428
auto SDRDegamma_sRGB_x1 = [](float c) -> float {
429429
if (c <= VPHAL_HDR_EOTF_COEFF1_TRADITIONNAL_GAMMA_SRGB)
@@ -534,5 +534,40 @@ MOS_STATUS VpUtils::GetPixelWithCSCForColorFill(
534534
}
535535
}
536536

537+
return MOS_STATUS_SUCCESS;
538+
}
539+
540+
MOS_STATUS VpUtils::GetNormalizedCSCMatrix(
541+
MEDIA_CSPACE src,
542+
MEDIA_CSPACE dst,
543+
float cscMatrix[12])
544+
{
545+
VP_PUBLIC_CHK_NULL_RETURN(cscMatrix);
546+
547+
if ((IS_COLOR_SPACE_BT2020(src) && !IS_COLOR_SPACE_BT2020(dst)) ||
548+
(!IS_COLOR_SPACE_BT2020(src) && IS_COLOR_SPACE_BT2020(dst)))
549+
{
550+
VP_PUBLIC_ASSERTMESSAGE("Not support hdr to sdr or sdr to hdr csc convert. Src CSpace %d, Dst CSpace %d", src, dst);
551+
}
552+
553+
KernelDll_GetCSCMatrix(src, dst, cscMatrix);
554+
555+
//for BT2020RGB convert to BT2020RGB, KernelDll_GetCSCMatrix use 1023 as max bias
556+
//for other cases, such as sRGB/BT709/BT601 and BT2020YUV convert BT2020RGB, KernelDll_GetCSCMatrix use 255 as max bias
557+
//so need to normalize w/ different value
558+
if ((src == CSpace_BT2020_stRGB && dst == CSpace_BT2020_RGB) ||
559+
(src == CSpace_BT2020_RGB && dst == CSpace_BT2020_stRGB))
560+
{
561+
cscMatrix[3] /= 1023.f;
562+
cscMatrix[7] /= 1023.f;
563+
cscMatrix[11] /= 1023.f;
564+
}
565+
else
566+
{
567+
cscMatrix[3] /= 255.f;
568+
cscMatrix[7] /= 255.f;
569+
cscMatrix[11] /= 255.f;
570+
}
571+
537572
return MOS_STATUS_SUCCESS;
538573
}

media_softlet/agnostic/common/vp/hal/utils/vp_utils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,23 @@ class VpUtils
468468
VPHAL_CSPACE srcCspace,
469469
VPHAL_CSPACE dstCspace);
470470

471+
//!
472+
//! \brief Get Color Space Convert Normalized Matrix
473+
//! \details Get Color Space Convert Normalized Matrix
474+
//! \param [out] pCSC_Matrix
475+
//! Pointer to float
476+
//! \param [in] src
477+
//! Source Color Space
478+
//! \param [in] dst
479+
//! Target Color Space
480+
//! \return MOS_STATUS
481+
//! Return MOS_STATUS_SUCCESS if successful
482+
//!
483+
static MOS_STATUS GetNormalizedCSCMatrix(
484+
MEDIA_CSPACE src,
485+
MEDIA_CSPACE dst,
486+
float cscMatrix[12]);
487+
471488
private:
472489
//!
473490
//! \brief Performs Color Space Convert for Sample 8 bit Using Specified Coeff Matrix

0 commit comments

Comments
 (0)