[i-g-t V6 38/41] lib/igt_color: Add support for 3x3 matrices

Bhanuprakash Modem bhanuprakash.modem at intel.com
Wed Apr 24 10:26:46 UTC 2024


Add helpers to support 3x3 matrices.

v2:
 - Rebase

Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 lib/igt_color.h          | 10 ++++++++++
 tests/kms_color_helper.c | 30 ++++++++++++++++++++++++++++++
 tests/kms_color_helper.h |  5 +++++
 3 files changed, 45 insertions(+)

diff --git a/lib/igt_color.h b/lib/igt_color.h
index 2a11d1d00..a94857ee6 100644
--- a/lib/igt_color.h
+++ b/lib/igt_color.h
@@ -49,6 +49,16 @@ typedef struct igt_1dlut {
 	struct drm_color_lut lut[MAX_COLOR_LUT_ENTRIES];
 } igt_1dlut_t;
 
+typedef struct igt_matrix_3x3 {
+	/*
+	 * out   matrix       in
+	 * |R|   |0  1  2 |   | R |
+	 * |G| = |3  4  5 | x | G |
+	 * |B|   |6  7  8 |   | B |
+	 */
+	double m[9];
+} igt_matrix_3x3_t;
+
 typedef struct igt_matrix_3x4 {
 	/*
 	 * out   matrix          in
diff --git a/tests/kms_color_helper.c b/tests/kms_color_helper.c
index 31f433386..a325b04a4 100644
--- a/tests/kms_color_helper.c
+++ b/tests/kms_color_helper.c
@@ -397,6 +397,8 @@ static bool can_use_colorop(igt_display_t *display, igt_colorop_t *colorop, kms_
 		    igt_colorop_try_prop_enum(colorop, IGT_COLOROP_CURVE_1D_TYPE, kms_colorop_lut1d_tf_names[desired->enumerated_lut1d_info.tf]))
 			return true;
 		return false;
+	case KMS_COLOROP_CTM_3X3:
+		return (igt_colorop_get_prop(display, colorop, IGT_COLOROP_TYPE) == DRM_COLOROP_CTM_3X3);
 	case KMS_COLOROP_CTM_3X4:
 		return (igt_colorop_get_prop(display, colorop, IGT_COLOROP_TYPE) == DRM_COLOROP_CTM_3X4);
 	case KMS_COLOROP_CUSTOM_LUT1D:
@@ -506,6 +508,9 @@ void set_colorop(igt_display_t *display, kms_colorop_t *colorop)
 	case KMS_COLOROP_ENUMERATED_LUT1D:
 		igt_colorop_set_prop_enum(colorop->colorop, IGT_COLOROP_CURVE_1D_TYPE, kms_colorop_lut1d_tf_names[colorop->enumerated_lut1d_info.tf]);
 		break;
+	case KMS_COLOROP_CTM_3X3:
+		igt_colorop_set_ctm_3x3(display, colorop->colorop, colorop->matrix_3x3);
+		break;
 	case KMS_COLOROP_CTM_3X4:
 		igt_colorop_set_ctm_3x4(display, colorop->colorop, colorop->matrix_3x4);
 		break;
@@ -553,6 +558,31 @@ void set_color_pipeline(igt_display_t *display,
 	}
 }
 
+void igt_colorop_set_ctm_3x3(igt_display_t *display,
+			     igt_colorop_t *colorop,
+			     const struct drm_color_ctm *matrix)
+{
+	struct drm_color_ctm ctm;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(ctm.matrix); i++) {
+		if (matrix->matrix[i] < 0) {
+			ctm.matrix[i] =
+				(int64_t) (-matrix->matrix[i] *
+				((int64_t) 1L << 32));
+			ctm.matrix[i] |= 1ULL << 63;
+		} else {
+			ctm.matrix[i] =
+				(int64_t) (matrix->matrix[i] *
+				((int64_t) 1L << 32));
+		}
+		igt_debug("CTM[%d]: %llx\n", i, ctm.matrix[i]);
+	}
+
+	/* set blob property */
+	igt_colorop_replace_prop_blob(colorop, IGT_COLOROP_DATA, &ctm, sizeof(ctm));
+}
+
 void igt_colorop_set_ctm_3x4(igt_display_t *display,
 			     igt_colorop_t *colorop,
 			     const igt_matrix_3x4_t *matrix)
diff --git a/tests/kms_color_helper.h b/tests/kms_color_helper.h
index b3b1875a9..0d691af14 100644
--- a/tests/kms_color_helper.h
+++ b/tests/kms_color_helper.h
@@ -126,6 +126,7 @@ void invalid_ctm_matrix_sizes(data_t *data, enum pipe p);
 typedef enum kms_colorop_type {
 	KMS_COLOROP_ENUMERATED_LUT1D,
 	KMS_COLOROP_CUSTOM_LUT1D,
+	KMS_COLOROP_CTM_3X3,
 	KMS_COLOROP_CTM_3X4,
 	KMS_COLOROP_MULTIPLIER,
 	KMS_COLOROP_LUT3D
@@ -141,6 +142,7 @@ typedef struct kms_colorop {
 	union {
 		kms_colorop_enumerated_lut1d_info_t enumerated_lut1d_info;
 		igt_1dlut_t *lut1d;
+		const struct drm_color_ctm *matrix_3x3;
 		const igt_matrix_3x4_t *matrix_3x4;
 		double multiplier;
 	};
@@ -160,6 +162,9 @@ igt_colorop_t *get_color_pipeline(igt_display_t *display, igt_plane_t *plane,
 void set_colorop(igt_display_t *display, kms_colorop_t *colorop);
 void set_color_pipeline(igt_display_t *display, igt_plane_t *plane,
 			      kms_colorop_t *colorops[], igt_colorop_t *color_pipeline);
+void igt_colorop_set_ctm_3x3(igt_display_t *display,
+			     igt_colorop_t *colorop,
+			     const struct drm_color_ctm *matrix);
 void igt_colorop_set_ctm_3x4(igt_display_t *display,
 			     igt_colorop_t *colorop,
 			     const igt_matrix_3x4_t *matrix);
-- 
2.43.2



More information about the Intel-gfx-trybot mailing list