From: Simon Zeni <simon.zeni@collabora.com>
To: igt-dev@lists.freedesktop.org
Subject: [PATCH i-g-t 2/3] lib/igt_fb: add support for DRM_FORMAT_Y8
Date: Wed, 25 Nov 2026 14:37:09 -0500 [thread overview]
Message-ID: <20261125193826.57420-2-simon.zeni@collabora.com> (raw)
In-Reply-To: <20261125193826.57420-1-simon.zeni@collabora.com>
This adds support for the greyscale format DRM_FORMAT_Y8 along with dedicated functions to convert
pixels in this format to RGB24 and vice-versa. The function `convert_y_to_rgb24` assumes a neutral
chroma value of 128 for both the U and V components.
Signed-off-by: Simon Zeni <simon.zeni@collabora.com>
---
lib/igt_color_encoding.c | 1 +
lib/igt_fb.c | 117 +++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+)
diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
index 1d01c7eb0..479e5478c 100644
--- a/lib/igt_color_encoding.c
+++ b/lib/igt_color_encoding.c
@@ -151,6 +151,7 @@ static const struct color_encoding_format {
{ DRM_FORMAT_YVU420, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
{ DRM_FORMAT_YVU422, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
{ DRM_FORMAT_YVU444, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
+ { DRM_FORMAT_Y8, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f},
{ DRM_FORMAT_YUYV, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
{ DRM_FORMAT_YVYU, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
{ DRM_FORMAT_UYVY, 255.f, 16.f, 235.f, 16.f, 128.f, 240.f },
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 3d15f0595..370a947a1 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -347,6 +347,11 @@ static const struct format_desc_struct {
.num_planes = 1, .plane_bpp = { 64, },
.hsub = 1, .vsub = 1,
},
+ { .name = "Y8", .depth = 8, .drm_id = DRM_FORMAT_Y8,
+ .cairo_id = CAIRO_FORMAT_RGB24, .convert = true,
+ .num_planes = 1, .plane_bpp = { 8, },
+ .hsub = 1, .vsub = 1,
+ },
{ .name = "XV30", .depth = -1, .drm_id = DRM_FORMAT_XVYU2101010,
.cairo_id = CAIRO_FORMAT_RGB96F, .convert = true,
.num_planes = 1, .plane_bpp = { 32, },
@@ -1215,6 +1220,11 @@ static void clear_yuv_buffer(struct igt_fb *fb)
0x80,
plane_size[2]);
break;
+ case DRM_FORMAT_Y8:
+ memset(ptr + fb->offsets[0],
+ full_range ? 0x00 : 0x10,
+ plane_size[0]);
+ break;
}
igt_fb_unmap_buffer(fb, ptr);
@@ -3772,6 +3782,10 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
igt_assert(igt_format_is_yuv(fb->drm_format));
switch (fb->drm_format) {
+ case DRM_FORMAT_Y8:
+ params->ay_inc = 1;
+ break;
+
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV16:
case DRM_FORMAT_NV21:
@@ -3819,6 +3833,10 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
}
switch (fb->drm_format) {
+ case DRM_FORMAT_Y8:
+ params->ay_stride = fb->strides[0];
+ break;
+
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV16:
case DRM_FORMAT_NV21:
@@ -3858,6 +3876,10 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
}
switch (fb->drm_format) {
+ case DRM_FORMAT_Y8:
+ params->y_offset = fb->offsets[0];
+ break;
+
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV16:
params->y_offset = fb->offsets[0];
@@ -4099,6 +4121,94 @@ static void convert_rgb24_to_yuv(struct fb_convert *cvt)
}
}
+static void convert_y_to_rgb24(struct fb_convert *cvt)
+{
+ int i, j;
+ uint8_t bpp = 4;
+ uint8_t *y;
+ uint8_t *rgb24 = cvt->dst.ptr;
+ unsigned int rgb24_stride = cvt->dst.fb->strides[0];
+ struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(cvt->src.fb->drm_format,
+ cvt->dst.fb->drm_format,
+ cvt->src.fb->color_encoding,
+ cvt->src.fb->color_range);
+ uint8_t *buf;
+ struct yuv_parameters params = { };
+
+ igt_assert(cvt->dst.fb->drm_format == DRM_FORMAT_XRGB8888 &&
+ cvt->src.fb->drm_format == DRM_FORMAT_Y8);
+
+ buf = convert_src_get(cvt);
+ get_yuv_parameters(cvt->src.fb, ¶ms);
+ y = buf + params.y_offset;
+
+ for (i = 0; i < cvt->dst.fb->height; i++) {
+ const uint8_t *y_tmp = y;
+ uint8_t *rgb_tmp = rgb24;
+
+ for (j = 0; j < cvt->dst.fb->width; j++) {
+ struct igt_vec4 rgb, yuv;
+
+ yuv.d[0] = *y_tmp;
+ yuv.d[1] = 128.f;
+ yuv.d[2] = 128.f;
+ yuv.d[3] = 1.0f;
+
+ rgb = igt_matrix_transform(&m, &yuv);
+ write_rgb(rgb_tmp, &rgb);
+
+ rgb_tmp += bpp;
+ y_tmp += params.ay_inc;
+ }
+
+ rgb24 += rgb24_stride;
+ y += params.ay_stride;
+ }
+
+ convert_src_put(cvt, buf);
+}
+
+static void convert_rgb24_to_y(struct fb_convert *cvt)
+{
+ int i, j;
+ uint8_t *y;
+ const uint8_t *rgb24 = cvt->src.ptr;
+ uint8_t bpp = 4;
+ unsigned rgb24_stride = cvt->src.fb->strides[0];
+ struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(cvt->src.fb->drm_format,
+ cvt->dst.fb->drm_format,
+ cvt->dst.fb->color_encoding,
+ cvt->dst.fb->color_range);
+ struct yuv_parameters params = { };
+
+ igt_assert(cvt->src.fb->drm_format == DRM_FORMAT_XRGB8888 &&
+ cvt->dst.fb->drm_format == DRM_FORMAT_Y8);
+
+ get_yuv_parameters(cvt->dst.fb, ¶ms);
+ y = cvt->dst.ptr + params.y_offset;
+
+ for (i = 0; i < cvt->dst.fb->height; i++) {
+ const uint8_t *rgb_tmp = rgb24;
+ uint8_t *y_tmp = y;
+
+ for (j = 0; j < cvt->dst.fb->width; j++) {
+ struct igt_vec4 rgb;
+ struct igt_vec4 yuv;
+
+ read_rgb(&rgb, rgb_tmp);
+ yuv = igt_matrix_transform(&m, &rgb);
+
+ rgb_tmp += bpp;
+
+ *y_tmp = clamp8(yuv.d[0]);
+ y_tmp += params.ay_inc;
+ }
+
+ rgb24 += rgb24_stride;
+ y += params.ay_stride;
+ }
+}
+
static void read_rgbf(struct igt_vec4 *rgb, const float *rgb24)
{
rgb->d[0] = rgb24[0];
@@ -4637,6 +4747,9 @@ static void fb_convert(struct fb_convert *cvt)
case DRM_FORMAT_YVYU:
convert_yuv_to_rgb24(cvt);
return;
+ case DRM_FORMAT_Y8:
+ convert_y_to_rgb24(cvt);
+ return;
}
} else if (cvt->src.fb->drm_format == DRM_FORMAT_XRGB8888) {
switch (cvt->dst.fb->drm_format) {
@@ -4661,6 +4774,9 @@ static void fb_convert(struct fb_convert *cvt)
case DRM_FORMAT_YVYU:
convert_rgb24_to_yuv(cvt);
return;
+ case DRM_FORMAT_Y8:
+ convert_rgb24_to_y(cvt);
+ return;
}
} else if (cvt->dst.fb->drm_format == IGT_FORMAT_FLOAT) {
switch (cvt->src.fb->drm_format) {
@@ -5259,6 +5375,7 @@ bool igt_format_is_yuv(uint32_t drm_format)
case DRM_FORMAT_UYVY:
case DRM_FORMAT_VYUY:
case DRM_FORMAT_XYUV8888:
+ case DRM_FORMAT_Y8:
return true;
default:
return false;
--
2.53.0
next prev parent reply other threads:[~2026-11-26 8:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 19:37 [PATCH i-g-t 1/3] drm_uapi/fourcc: sync with drm-next Simon Zeni
2026-11-25 19:37 ` Simon Zeni [this message]
2026-11-25 19:37 ` [PATCH i-g-t 3/3] tests/kms_plane: compare DRM_FORMAT_Y8 plane with greyscale reference CRC Simon Zeni
2026-11-26 14:46 ` [PATCH i-g-t 1/3] drm_uapi/fourcc: sync with drm-next Kamil Konieczny
2026-11-26 19:31 ` Simon Zeni
2026-11-27 0:41 ` ✓ Xe.CI.BAT: success for series starting with [i-g-t,1/3] " Patchwork
2026-11-27 0:59 ` ✓ i915.CI.BAT: " Patchwork
2026-11-27 13:04 ` ✓ Xe.CI.FULL: " Patchwork
2026-11-28 6:19 ` ✗ i915.CI.Full: failure " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2026-12-02 16:51 [PATCH i-g-t 0/3] Add support for DRM_FORMAT_Y8 in tests/kms_plane simon.zeni
2026-12-02 16:51 ` [PATCH i-g-t 2/3] lib/igt_fb: add support for DRM_FORMAT_Y8 simon.zeni
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=20261125193826.57420-2-simon.zeni@collabora.com \
--to=simon.zeni@collabora.com \
--cc=igt-dev@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox