All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikita Lipski <mikita.lipski@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Harry.Wentland@amd.com>, <Sunpeng.Li@amd.com>,
	<Bhawanpreet.Lakha@amd.com>, <Rodrigo.Siqueira@amd.com>,
	<Aurabindo.Pillai@amd.com>, <Qingqing.Zhuo@amd.com>,
	<mikita.lipski@amd.com>,  <Anson.Jacob@amd.com>,
	Jaehyun Chung <jaehyun.chung@amd.com>,
	Krunoslav Kovac <Krunoslav.Kovac@amd.com>
Subject: [PATCH 19/19] drm/amd/display: Add regamma/degamma coefficients and set sRGB when TF is BT709
Date: Fri, 27 Aug 2021 16:29:10 -0400	[thread overview]
Message-ID: <20210827202910.20864-20-mikita.lipski@amd.com> (raw)
In-Reply-To: <20210827202910.20864-1-mikita.lipski@amd.com>

From: Jaehyun Chung <jaehyun.chung@amd.com>

[Why]
In YUV case, need to set the input TF to sRGB instead of BT709,
even though the input TF type is distributed. SRGB was not
being used because pixel format was not being set in the
surface update sequence.
Also, we were using the same coefficients for degamma and
regamma formula, causing the cutoff point of the linear
section of the curve to be incorrect.

[How]
Set pixel format in the surface update sequence. Add separate
coefficient arrays for regamma and degamma.

Reviewed-by: Krunoslav Kovac <Krunoslav.Kovac@amd.com>
Acked-by: Mikita Lipski <mikita.lipski@amd.com>
Signed-off-by: Jaehyun Chung <jaehyun.chung@amd.com>
---
 .../amd/display/modules/color/color_gamma.c   | 60 ++++++++++++-------
 1 file changed, 40 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
index ef742d95ef05..275f11f8bea3 100644
--- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
+++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
@@ -54,12 +54,18 @@ static struct hw_x_point coordinates_x[MAX_HW_POINTS + 2];
  * just multiply with 2^gamma which can be computed once, and save the result so we
  * recursively compute all the values.
  */
-										/*sRGB	 709 2.2 2.4 P3*/
-static const int32_t gamma_numerator01[] = { 31308,	180000,	0,	0,	0};
-static const int32_t gamma_numerator02[] = { 12920,	4500,	0,	0,	0};
-static const int32_t gamma_numerator03[] = { 55,	99,		0,	0,	0};
-static const int32_t gamma_numerator04[] = { 55,	99,		0,	0,	0};
-static const int32_t gamma_numerator05[] = { 2400,	2200,	2200, 2400, 2600};
+											 /*sRGB     709     2.2 2.4 P3*/
+static const int32_t regamma_numerator01[] = { 31308,   180000, 0,  0,  0};
+static const int32_t regamma_numerator02[] = { 12920,   4500,   0,  0,  0};
+static const int32_t regamma_numerator03[] = { 55,      99,     0,  0,  0};
+static const int32_t regamma_numerator04[] = { 55,      99,     0,  0,  0};
+static const int32_t regamma_numerator05[] = { 2400,    2200,   2200, 2400, 2600};
+
+static const int32_t degamma_numerator01[] = { 40450,   810000, 0,  0,  0};
+static const int32_t degamma_numerator02[] = { 12920,   4500,   0,  0,  0};
+static const int32_t degamma_numerator03[] = { 55,      99,     0,  0,  0};
+static const int32_t degamma_numerator04[] = { 55,      99,     0,  0,  0};
+static const int32_t degamma_numerator05[] = { 2400,    2200,   2200, 2400, 2600};
 
 /* one-time setup of X points */
 void setup_x_points_distribution(void)
@@ -288,7 +294,8 @@ struct dividers {
 };
 
 
-static bool build_coefficients(struct gamma_coefficients *coefficients, enum dc_transfer_func_predefined type)
+static bool build_coefficients(struct gamma_coefficients *coefficients,
+		enum dc_transfer_func_predefined type, bool isRegamma)
 {
 
 	uint32_t i = 0;
@@ -311,16 +318,29 @@ static bool build_coefficients(struct gamma_coefficients *coefficients, enum dc_
 	}
 
 	do {
-		coefficients->a0[i] = dc_fixpt_from_fraction(
-			gamma_numerator01[index], 10000000);
-		coefficients->a1[i] = dc_fixpt_from_fraction(
-			gamma_numerator02[index], 1000);
-		coefficients->a2[i] = dc_fixpt_from_fraction(
-			gamma_numerator03[index], 1000);
-		coefficients->a3[i] = dc_fixpt_from_fraction(
-			gamma_numerator04[index], 1000);
-		coefficients->user_gamma[i] = dc_fixpt_from_fraction(
-			gamma_numerator05[index], 1000);
+		if (isRegamma) {
+			coefficients->a0[i] = dc_fixpt_from_fraction(
+				regamma_numerator01[index], 10000000);
+			coefficients->a1[i] = dc_fixpt_from_fraction(
+				regamma_numerator02[index], 1000);
+			coefficients->a2[i] = dc_fixpt_from_fraction(
+				regamma_numerator03[index], 1000);
+			coefficients->a3[i] = dc_fixpt_from_fraction(
+				regamma_numerator04[index], 1000);
+			coefficients->user_gamma[i] = dc_fixpt_from_fraction(
+				regamma_numerator05[index], 1000);
+		} else {
+			coefficients->a0[i] = dc_fixpt_from_fraction(
+				degamma_numerator01[index], 10000000);
+			coefficients->a1[i] = dc_fixpt_from_fraction(
+				degamma_numerator02[index], 1000);
+			coefficients->a2[i] = dc_fixpt_from_fraction(
+				degamma_numerator03[index], 1000);
+			coefficients->a3[i] = dc_fixpt_from_fraction(
+				degamma_numerator04[index], 1000);
+			coefficients->user_gamma[i] = dc_fixpt_from_fraction(
+				degamma_numerator05[index], 1000);
+		}
 
 		++i;
 	} while (i != ARRAY_SIZE(coefficients->a0));
@@ -833,7 +853,7 @@ static bool build_regamma(struct pwl_float_data_ex *rgb_regamma,
 	if (!coeff)
 		goto release;
 
-	if (!build_coefficients(coeff, type))
+	if (!build_coefficients(coeff, type, true))
 		goto release;
 
 	memset(cal_buffer->buffer, 0, NUM_PTS_IN_REGION * sizeof(struct fixed31_32));
@@ -1082,7 +1102,7 @@ static bool build_degamma(struct pwl_float_data_ex *curve,
 	uint32_t begin_index, end_index;
 	bool ret = false;
 
-	if (!build_coefficients(&coeff, type))
+	if (!build_coefficients(&coeff, type, false))
 		goto release;
 
 	i = 0;
@@ -1685,7 +1705,7 @@ static void apply_degamma_for_user_regamma(struct pwl_float_data_ex *rgb_regamma
 	struct pwl_float_data_ex *rgb = rgb_regamma;
 	const struct hw_x_point *coord_x = coordinates_x;
 
-	build_coefficients(&coeff, TRANSFER_FUNCTION_SRGB);
+	build_coefficients(&coeff, TRANSFER_FUNCTION_SRGB, true);
 
 	i = 0;
 	while (i != hw_points_num + 1) {
-- 
2.25.1


  parent reply	other threads:[~2021-08-27 20:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 20:28 [PATCH 00/19] DC Patches August 23, 2021 Mikita Lipski
2021-08-27 20:28 ` [PATCH 01/19] drm/amd/display: cleanup idents after a revert Mikita Lipski
2021-08-27 20:28 ` [PATCH 02/19] drm/amd/display: Initialize lt_settings on instantiation Mikita Lipski
2021-08-27 20:28 ` [PATCH 03/19] drm/amd/display: Add DPCD writes at key points Mikita Lipski
2021-08-27 20:28 ` [PATCH 04/19] drm/amd/display: Fix system hang at boot Mikita Lipski
2021-08-27 20:28 ` [PATCH 05/19] drm/amd/display: Drop unused privacy_mask setters and getters Mikita Lipski
2021-08-27 20:28 ` [PATCH 06/19] drm/amd/display: expose dsc overhead bw in dc dsc header Mikita Lipski
2021-08-27 20:28 ` [PATCH 07/19] drm/amd/display: move bpp range decision in decide dsc bw range function Mikita Lipski
2021-08-27 20:28 ` [PATCH 08/19] drm/amd/display: Add option to defer works of hpd_rx_irq Mikita Lipski
2021-08-27 20:29 ` [PATCH 09/19] drm/amd/display: Fork thread to offload work " Mikita Lipski
2021-08-27 20:29 ` [PATCH 10/19] drm/amd/display: unblock abm when odm is enabled only on configs that support it Mikita Lipski
2021-08-27 20:29 ` [PATCH 11/19] drm/amd/display: Add flag to detect dpms force off during HPD Mikita Lipski
2021-08-27 20:29 ` [PATCH 12/19] drm/amd/display: Fix false BAD_FREE warning from Coverity Mikita Lipski
2021-08-27 20:29 ` [PATCH 13/19] drm/amd/display: Fix for null pointer access for ddc pin and aux engine Mikita Lipski
2021-08-27 20:29 ` [PATCH 14/19] drm/amd/display: [FW Promotion] Release 0.0.81 Mikita Lipski
2021-08-27 20:29 ` [PATCH 15/19] drm/amd/display: 3.2.151 Mikita Lipski
2021-08-27 20:29 ` [PATCH 16/19] drm/amd/display: Fix multiple memory leaks reported by coverity Mikita Lipski
2021-08-27 20:29 ` [PATCH 17/19] drm/amd/display: Get backlight from PWM if DMCU is not initialized Mikita Lipski
2021-08-27 20:29   ` Mikita Lipski
2021-08-27 20:29 ` [PATCH 18/19] drm/amd/display: Revert "Directly retrain link from debugfs" Mikita Lipski
2021-08-27 20:29 ` Mikita Lipski [this message]
2021-08-30 14:12 ` [PATCH 00/19] DC Patches August 23, 2021 Wheeler, Daniel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210827202910.20864-20-mikita.lipski@amd.com \
    --to=mikita.lipski@amd.com \
    --cc=Anson.Jacob@amd.com \
    --cc=Aurabindo.Pillai@amd.com \
    --cc=Bhawanpreet.Lakha@amd.com \
    --cc=Harry.Wentland@amd.com \
    --cc=Krunoslav.Kovac@amd.com \
    --cc=Qingqing.Zhuo@amd.com \
    --cc=Rodrigo.Siqueira@amd.com \
    --cc=Sunpeng.Li@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=jaehyun.chung@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.