mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values
Date: Wed, 18 Nov 2026 14:27:10 +0100	[thread overview]
Message-ID: <bd611fa8-2df2-49ba-9e2d-ce897d42d18e@bootlin.com> (raw)
In-Reply-To: <20260928005301.367977-2-matheus.aalmeida@inf.ufrgs.br>



On 9/28/26 02:52, Matheus Alves de Almeida wrote:
> Currently, argb_u16_to_RGB565() truncates the resulting channel values.
> Use drm_fixp2int_round() to round them to the nearest representable
> RGB565 values.
> 
> Restore the rounding behavior from commit
> ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion") while adding a
> separate helper for channel conversion.
> 
> Fixes: cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions")
> 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 | 35 ++++++++++++++++++++---------
>   1 file changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> index dfb8e13cb..6d7853e87 100644
> --- a/drivers/gpu/drm/vkms/vkms_formats.c
> +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> @@ -639,20 +639,35 @@ static void argb_u16_to_XRGB16161616(u8 *out_pixel, const struct pixel_argb_u16
>   	pixel[0] = cpu_to_le16(in_pixel->b);
>   }
>   
> -static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
> +static u16 u16_to_channel(int size, u16 in)
>   {
> -	__le16 *pixel = (__le16 *)out_pixel;
> +	s64 fp_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp((1 << size) - 1));
> +	s64 fp_channel = drm_int2fixp(in);
>   
> -	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));
> +	return drm_fixp2int_round(drm_fixp_div(fp_channel, fp_ratio));
> +}
> +
> +static void argb_u16_to_channels(u16 *out_r, u16 *out_g, u16 *out_b, u16 *out_a,
> +				 unsigned int r_size, unsigned int g_size,
> +				 unsigned int b_size, unsigned int a_size,
> +				 const struct pixel_argb_u16 *in_pixel)
> +{
> +	if (r_size)
> +		*out_r = u16_to_channel(r_size, in_pixel->r);
> +	if (g_size)
> +		*out_g = u16_to_channel(g_size, in_pixel->g);
> +	if (b_size)
> +		*out_b = u16_to_channel(b_size, in_pixel->b);
> +	if (a_size)
> +		*out_a = u16_to_channel(a_size, in_pixel->a);
> +}
>   
> -	s64 fp_r = drm_int2fixp(in_pixel->r);
> -	s64 fp_g = drm_int2fixp(in_pixel->g);
> -	s64 fp_b = drm_int2fixp(in_pixel->b);
> +static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
> +{
> +	__le16 *pixel = (__le16 *)out_pixel;
> +	u16 r, g, b;
>   
> -	u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio));
> -	u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
> -	u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
> +	argb_u16_to_channels(&r, &g, &b, NULL, 5, 6, 5, 0, in_pixel);
>   
>   	*pixel = cpu_to_le16(r << 11 | g << 5 | b);
>   }


  parent reply	other threads:[~2026-11-18 13:27 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 [this message]
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
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=bd611fa8-2df2-49ba-9e2d-ce897d42d18e@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®