All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: dri-devel@lists.freedesktop.org
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH libdrm 3/3] util: Add SMPTE pattern support for C4 format
Date: Mon,  7 Mar 2022 21:53:18 +0100	[thread overview]
Message-ID: <cc84f1fcd0901ba58a2e4fd34c43846c622fd157.1646683737.git.geert@linux-m68k.org> (raw)
In-Reply-To: <cover.1646683737.git.geert@linux-m68k.org>

Add support for drawing the SMPTE pattern in a buffer using the C4
indexed format.

Note that this still uses 256 instead of 16 as the CLUT size, as
DRM_IOCTL_MODE_SETGAMMA enforces that the size matches against the
(fixed) gamma size, while the CLUT size depends on the format.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
The linuxdoc comments say userspace can query the gamma size:

 * drm_mode_gamma_set_ioctl - set the gamma table
 *
 * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
 * inquire the required gamma table size through drm_mode_gamma_get_ioctl.

 * drm_mode_gamma_get_ioctl - get the gamma table
 *
 * Copy the current gamma table into the storage provided. This also provides
 * the gamma table size the driver expects, which can be used to size the
 * allocated storage.

but the code doesn't seem to support that in an easy way (like setting
red/green/blue to NULL on input, retrieving gamma_size on output), only
by providing big enough buffers for red/green/blue, and looping over
gamma_size until -EINVAL is no longer returned.
---
 tests/modetest/modetest.c | 11 +++++++---
 tests/util/pattern.c      | 42 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c
index e369044fb7a484c1..205b7093b0045e01 100644
--- a/tests/modetest/modetest.c
+++ b/tests/modetest/modetest.c
@@ -1122,16 +1122,21 @@ static void set_gamma(struct device *dev, unsigned crtc_id, unsigned fourcc)
 	struct drm_color_lut gamma_lut[256];
 	int i, ret;
 
-	if (fourcc == DRM_FORMAT_C8) {
-		/* TODO: Add C8 support for more patterns */
+	switch (fourcc) {
+	case DRM_FORMAT_C4:
+	case DRM_FORMAT_C8:
+		/* TODO: Add index support for more patterns */
 		util_smpte_index_gamma(256, gamma_lut);
 		drmModeCreatePropertyBlob(dev->fd, gamma_lut, sizeof(gamma_lut), &blob_id);
-	} else {
+		break;
+
+	default:
 		for (i = 0; i < 256; i++) {
 			gamma_lut[i].red =
 			gamma_lut[i].green =
 			gamma_lut[i].blue = i << 8;
 		}
+		break;
 	}
 
 	add_property_optional(dev, crtc_id, "DEGAMMA_LUT", 0);
diff --git a/tests/util/pattern.c b/tests/util/pattern.c
index 953bf95492ee150c..42d75d700700dc3d 100644
--- a/tests/util/pattern.c
+++ b/tests/util/pattern.c
@@ -608,6 +608,46 @@ static void fill_smpte_rgb16fp(const struct util_rgb_info *rgb, void *mem,
 static unsigned int smpte_middle[7] = { 6, 7, 4, 7, 2, 7, 0 };
 static unsigned int smpte_bottom[8] = { 8, 9, 10, 7, 11, 7, 12, 7 };
 
+static void write_pixel_4(uint8_t *mem, unsigned int x, unsigned int pixel)
+{
+	if (x & 1)
+		mem[x / 2] = (mem[x / 2] & 0xf0) | (pixel & 0x0f);
+	else
+		mem[x / 2] = (mem[x / 2] & 0x0f) | (pixel << 4);
+}
+
+static void fill_smpte_c4(void *mem, unsigned int width, unsigned int height,
+			  unsigned int stride)
+{
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			write_pixel_4(mem, x, x * 7 / width);
+		mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			write_pixel_4(mem, x, smpte_middle[x * 7 / width]);
+		mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			write_pixel_4(mem, x,
+				      smpte_bottom[x * 4 / (width * 5 / 7)]);
+		for (; x < width * 6 / 7; ++x)
+			write_pixel_4(mem, x,
+				      smpte_bottom[(x - width * 5 / 7) * 3 /
+						   (width / 7) + 4]);
+		for (; x < width; ++x)
+			write_pixel_4(mem, x, smpte_bottom[7]);
+		mem += stride;
+	}
+}
+
 static void fill_smpte_c8(void *mem, unsigned int width, unsigned int height,
 			  unsigned int stride)
 {
@@ -688,6 +728,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
 	unsigned char *u, *v;
 
 	switch (info->format) {
+	case DRM_FORMAT_C4:
+		return fill_smpte_c4(planes[0], width, height, stride);
 	case DRM_FORMAT_C8:
 		return fill_smpte_c8(planes[0], width, height, stride);
 	case DRM_FORMAT_UYVY:
-- 
2.25.1


  parent reply	other threads:[~2022-03-07 20:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-07 20:53 [PATCH libdrm 0/3] Add support for low-color frame buffer formats Geert Uytterhoeven
2022-03-07 20:53 ` [PATCH libdrm 1/3] util: Optimize C8 SMPTE color LUT Geert Uytterhoeven
2022-03-07 20:53 ` [PATCH libdrm 2/3] drm_fourcc: Add DRM_FORMAT_C[124] Geert Uytterhoeven
2022-03-08  9:24   ` Pekka Paalanen
2022-03-07 20:53 ` Geert Uytterhoeven [this message]
2022-03-07 21:23   ` [PATCH libdrm 3/3] util: Add SMPTE pattern support for C4 format Ilia Mirkin
2022-03-08  7:57     ` Geert Uytterhoeven
2022-03-14 13:06       ` Geert Uytterhoeven
2022-03-14 13:43         ` Ilia Mirkin
2022-03-14 14:06           ` Geert Uytterhoeven
2022-03-14 14:39             ` Ilia Mirkin
2022-03-14 14:48               ` Geert Uytterhoeven

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=cc84f1fcd0901ba58a2e4fd34c43846c622fd157.1646683737.git.geert@linux-m68k.org \
    --to=geert@linux-m68k.org \
    --cc=dri-devel@lists.freedesktop.org \
    /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.