From: Louis Chauvet <louis.chauvet@bootlin.com>
To: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>,
Haneen Mohammed <hamohammed.sa@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Melissa Wen <melissa.srw@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion
Date: Wed, 18 Nov 2026 14:25:11 +0100 [thread overview]
Message-ID: <c8161754-f2a0-4efd-a7cc-72cd6a4696ce@bootlin.com> (raw)
In-Reply-To: <20260928005301.367977-4-matheus.aalmeida@inf.ufrgs.br>
On 9/28/26 02:52, Matheus Alves de Almeida wrote:
> Other pixel formats have similar conversions to the one implemented in
> the RGB565 helper.
>
> Add a channels_to_argb_u16() helper to convert individual channels into
> the internal representation, and use it in argb_u16_from_BGR565() and
> argb_u16_from_RGB565().
>
> Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
> drivers/gpu/drm/vkms/vkms_formats.c | 50 +++++++++++++++++------------
> 1 file changed, 29 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> index b44900761..6e4f58207 100644
> --- a/drivers/gpu/drm/vkms/vkms_formats.c
> +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> @@ -229,24 +229,42 @@ static struct pixel_argb_u16 argb_u16_from_le16161616(__le16 a, __le16 r, __le16
> le16_to_cpu(b));
> }
>
> -static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
> +static u16 channel_to_u16(unsigned int size, u16 in)
> +{
> + s64 fp_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp((1 << size) - 1));
> +
> + s64 fp_channel = drm_int2fixp(in);
> +
> + return drm_fixp2int_round(drm_fixp_mul(fp_channel, fp_ratio));
> +}
> +
> +static struct pixel_argb_u16 channels_to_argb_u16(u16 in_r, u16 in_g, u16 in_b, u16 in_a,
> + unsigned int size_r, unsigned int size_g,
> + unsigned int size_b, unsigned int size_a)
> {
> struct pixel_argb_u16 out_pixel;
>
> - s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
> - s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
> + out_pixel.r = size_r ? channel_to_u16(size_r, in_r) : in_r;
> + out_pixel.g = size_g ? channel_to_u16(size_g, in_g) : in_g;
> + out_pixel.b = size_b ? channel_to_u16(size_b, in_b) : in_b;
> + out_pixel.a = size_a ? channel_to_u16(size_a, in_a) : in_a;
>
> + return out_pixel;
> +}
> +
> +static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
> +{
> u16 rgb_565 = le16_to_cpu(*pixel);
> - s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
> - s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
> - s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
>
> - out_pixel.a = (u16)0xffff;
> - out_pixel.r = drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio));
> - out_pixel.g = drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio));
> - out_pixel.b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio));
> + return channels_to_argb_u16((rgb_565 >> 11) & 0x1f, (rgb_565 >> 5) & 0x3f,
> + rgb_565 & 0x1f, 0xffff, 5, 6, 5, 0);
> +}
>
> - return out_pixel;
> +static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
> +{
> + u16 bgr_565 = le16_to_cpu(*pixel);
> +
> + return channels_to_argb_u16(bgr_565 & 0x1f, (bgr_565 >> 5) & 0x3f,
> + (bgr_565 >> 11) & 0x1f, 0xffff, 5, 6, 5, 0);
> }
>
> static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
> @@ -259,16 +277,6 @@ static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray)
> return argb_u16_from_u16161616(0xFFFF, gray, gray, gray);
> }
>
> -static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
> -{
> - struct pixel_argb_u16 out_pixel;
> -
> - out_pixel = argb_u16_from_RGB565(pixel);
> - swap(out_pixel.r, out_pixel.b);
> -
> - return out_pixel;
> -}
> -
> VISIBLE_IF_KUNIT
> struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix,
> u16 y, u16 channel_1, u16 channel_2)
next prev parent reply other threads:[~2026-11-18 13:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
2026-09-28 0:52 ` [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values Matheus Alves de Almeida
2026-11-08 3:12 ` Sidharth Saha
2026-11-18 13:27 ` Louis Chauvet
2026-09-28 0:52 ` [PATCH 2/5] drm/vkms: support BGR565 writeback Matheus Alves de Almeida
2026-11-18 13:29 ` Louis Chauvet
2026-09-28 0:52 ` [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion Matheus Alves de Almeida
2026-11-18 13:25 ` Louis Chauvet [this message]
2026-09-28 0:53 ` [PATCH 4/5] drm/vkms: add support for RGB332 Matheus Alves de Almeida
2026-11-17 16:11 ` Louis Chauvet
2026-09-28 0:53 ` [PATCH 5/5] drm/vkms: add support for BGR233 Matheus Alves de Almeida
2026-11-18 13:30 ` Louis Chauvet
2026-10-12 19:18 ` [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
2026-11-08 3:08 ` Sidharth Saha
2026-11-13 0:18 ` Sidharth Saha
2026-11-13 1:51 ` Matheus Alves de Almeida
2026-11-14 18:51 ` Sidharth Saha
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=c8161754-f2a0-4efd-a7cc-72cd6a4696ce@bootlin.com \
--to=louis.chauvet@bootlin.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matheus.aalmeida@inf.ufrgs.br \
--cc=melissa.srw@gmail.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®