mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javierm@redhat.com>
To: "Geert Uytterhoeven" <geert@linux-m68k.org>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Noralf Trønnes" <noralf@tronnes.org>,
	"Pekka Paalanen" <pekka.paalanen@collabora.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] drm/format-helper: Fix XRGB888 to monochrome conversion
Date: Tue, 15 Mar 2022 13:18:00 +0100	[thread overview]
Message-ID: <27e1c911-798a-c14b-e5a0-622a7c5d8755@redhat.com> (raw)
In-Reply-To: <20220315110707.628166-3-geert@linux-m68k.org>

On 3/15/22 12:07, Geert Uytterhoeven wrote:
> The conversion functions drm_fb_xrgb8888_to_mono() and
> drm_fb_gray8_to_mono_line() do not behave correctly when the
> horizontal boundaries of the clip rectangle are not multiples of 8:
>   a. When x1 % 8 != 0, the calculated pitch is not correct,
>   b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
>

Thanks a lot for tracking down and fixing these issues.

> Simplify the code and fix (a) by:
>   1. Removing start_offset, and always storing the first pixel in the
>      first bit of the monochrome destination buffer.
>      Drivers that require the first pixel in a byte to be located at an
>      x-coordinate that is a multiple of 8 can always align the clip
>      rectangle before calling drm_fb_xrgb8888_to_mono().
>      Note that:
>        - The ssd130x driver does not need the alignment, as the
> 	 monochrome buffer is a temporary format,
>        - The repaper driver always updates the full screen, so the clip
> 	 rectangle is always aligned.
>   2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
>      instead of the number of bytes, and the number of pixels in the
>      last byte.
> 
> Fix (b) by explicitly setting the target bit, instead of always setting
> bit 7 and shifting the value in each loop iteration.
> 
> Remove the bogus pitch check, which operates on bytes instead of pixels,
> and triggers when e.g. flashing the cursor on a text console with a font
> that is 8 pixels wide.
> 
> Drop the confusing comment about scanlines, as a pitch in bytes always
> contains a multiple of 8 pixels.
> 
> While at it, use the drm_rect_height() helper instead of open-coding the
> same operation.
> 
> Update the comments accordingly.
> 
> Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---

Acked-by: Javier Martinez Canillas <javierm@redhat.com>

I just have a small comment below.

[snip]

> +static void drm_fb_gray8_to_mono_line(u8 *dst, const u8 *src, unsigned int pixels)
> +{
> +	while (pixels) {
> +		unsigned int i, bits = min(pixels, 8U);
> +		u8 byte = 0;
>  
> -			byte >>= 1;
> -			if (src[x] >> 7)
> -				byte |= BIT(7);
> +		for (i = 0; i < bits; i++, pixels--) {

I think is worth to add a comment here explaining that the pixel is set to
1 for brightness > 127 and to 0 for brightness < 128. Or as kernel-doc for
this helper function.

> +			if (*src++ & BIT(7))

Pekka also mentioned that if (*src++ > 127) would make this easier to read.

> +				byte |= BIT(i);
>  		}
>  		*dst++ = byte;
>  	}

-- 
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat


  reply	other threads:[~2022-03-15 12:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 11:07 [PATCH 0/5] drm: Fix monochrome conversion for sdd130x Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 1/5] drm/format-helper: Rename drm_fb_xrgb8888_to_mono_reversed() Geert Uytterhoeven
2022-03-15 11:59   ` Javier Martinez Canillas
2022-03-15 13:32   ` Andy Shevchenko
2022-03-15 13:37     ` Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 2/5] drm/format-helper: Fix XRGB888 to monochrome conversion Geert Uytterhoeven
2022-03-15 12:18   ` Javier Martinez Canillas [this message]
2022-03-15 12:48     ` Geert Uytterhoeven
2022-03-15 13:39     ` Andy Shevchenko
2022-03-15 13:38   ` Andy Shevchenko
2022-03-15 11:07 ` [PATCH 3/5] drm: ssd130x: Fix rectangle updates Geert Uytterhoeven
2022-03-15 12:28   ` Javier Martinez Canillas
2022-03-15 11:07 ` [PATCH 4/5] drm: ssd130x: Reduce temporary buffer sizes Geert Uytterhoeven
2022-03-15 12:32   ` Javier Martinez Canillas
2022-03-15 12:57     ` Geert Uytterhoeven
2022-03-15 13:50   ` Andy Shevchenko
2022-03-15 14:01     ` Geert Uytterhoeven
2022-03-15 11:07 ` [PATCH 5/5] drm/repaper: Reduce temporary buffer size in repaper_fb_dirty() Geert Uytterhoeven
2022-03-15 12:36   ` Javier Martinez Canillas
2022-03-15 13:56   ` Andy Shevchenko

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=27e1c911-798a-c14b-e5a0-622a7c5d8755@redhat.com \
    --to=javierm@redhat.com \
    --cc=airlied@linux.ie \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=noralf@tronnes.org \
    --cc=pekka.paalanen@collabora.com \
    --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®