From: Geert Uytterhoeven <geert@linux-m68k.org> To: Javier Martinez Canillas <javierm@redhat.com> Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>, "Linux Fbdev development list" <linux-fbdev@vger.kernel.org>, "Maxime Ripard" <maxime@cerno.tech>, "Daniel Vetter" <daniel.vetter@ffwll.ch>, "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>, "DRI Development" <dri-devel@lists.freedesktop.org>, "Noralf Trønnes" <noralf@tronnes.org>, "Daniel Vetter" <daniel@ffwll.ch>, "David Airlie" <airlied@linux.ie>, "Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>, "Maxime Ripard" <mripard@kernel.org>, "Thomas Zimmermann" <tzimmermann@suse.de> Subject: Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed() Date: Mon, 14 Mar 2022 14:40:02 +0100 [thread overview] Message-ID: <CAMuHMdWPQrErbMZ4wJPgROY7XOnKGvimNFg8JpiyuWqz2a3Gzw@mail.gmail.com> (raw) In-Reply-To: <20220131201225.2324984-3-javierm@redhat.com> Hi Javier, On Mon, Jan 31, 2022 at 9:12 PM Javier Martinez Canillas <javierm@redhat.com> wrote: > Add support to convert 8-bit grayscale to reversed monochrome for drivers > that control monochromatic displays, that only have 1 bit per pixel depth. > > This helper function was based on repaper_gray8_to_mono_reversed() from > the drivers/gpu/drm/tiny/repaper.c driver. > > Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for > return -EINVAL; > } > EXPORT_SYMBOL(drm_fb_blit_toio); > + > +/** > + * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome > + * @dst: reversed monochrome destination buffer What's the meaning of "reversed"? During the last few days, I've been balancing between (a) "reverse video" and (b) "reverse bit order", but none of them seems to be true. (a) The code maps 0-127 to 0 and 8-255 to 1, which just reduces from 256 to 2 grayscale levels, without inversion. The result is also white-on-black on my ssd130x OLED. (b) On little-endian, the CFB drawops use little-endian bit order, which is what ends up in "byte" in the code below. > + * @src: 8-bit grayscale source buffer > + * @clip: Clip rectangle area to copy > + * > + * DRM doesn't have native monochrome or grayscale support. > + * Such drivers can announce the commonly supported XR24 format to userspace > + * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this > + * helper function to convert to the native format. > + */ > +void drm_fb_gray8_to_mono_reversed(void *dst, void *src, const struct drm_rect *clip) > +{ > + size_t width = drm_rect_width(clip); > + size_t height = drm_rect_width(clip); > + > + u8 *mono = dst, *gray8 = src; > + unsigned int y, xb, i; > + > + for (y = 0; y < height; y++) > + for (xb = 0; xb < width / 8; xb++) { > + u8 byte = 0x00; > + > + for (i = 0; i < 8; i++) { > + int x = xb * 8 + i; > + > + byte >>= 1; > + if (gray8[y * width + x] >> 7) > + byte |= BIT(7); > + } > + *mono++ = byte; > + } > +} Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
WARNING: multiple messages have this Message-ID (diff)
From: Geert Uytterhoeven <geert@linux-m68k.org> To: Javier Martinez Canillas <javierm@redhat.com> Cc: "Linux Fbdev development list" <linux-fbdev@vger.kernel.org>, "Thomas Zimmermann" <tzimmermann@suse.de>, "David Airlie" <airlied@linux.ie>, "Daniel Vetter" <daniel.vetter@ffwll.ch>, "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>, "DRI Development" <dri-devel@lists.freedesktop.org>, "Noralf Trønnes" <noralf@tronnes.org>, "Maxime Ripard" <maxime@cerno.tech>, "Andy Shevchenko" <andriy.shevchenko@linux.intel.com> Subject: Re: [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed() Date: Mon, 14 Mar 2022 14:40:02 +0100 [thread overview] Message-ID: <CAMuHMdWPQrErbMZ4wJPgROY7XOnKGvimNFg8JpiyuWqz2a3Gzw@mail.gmail.com> (raw) In-Reply-To: <20220131201225.2324984-3-javierm@redhat.com> Hi Javier, On Mon, Jan 31, 2022 at 9:12 PM Javier Martinez Canillas <javierm@redhat.com> wrote: > Add support to convert 8-bit grayscale to reversed monochrome for drivers > that control monochromatic displays, that only have 1 bit per pixel depth. > > This helper function was based on repaper_gray8_to_mono_reversed() from > the drivers/gpu/drm/tiny/repaper.c driver. > > Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> > --- a/drivers/gpu/drm/drm_format_helper.c > +++ b/drivers/gpu/drm/drm_format_helper.c > @@ -584,3 +584,38 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_for > return -EINVAL; > } > EXPORT_SYMBOL(drm_fb_blit_toio); > + > +/** > + * drm_fb_gray8_to_mono_reversed - Convert grayscale to reversed monochrome > + * @dst: reversed monochrome destination buffer What's the meaning of "reversed"? During the last few days, I've been balancing between (a) "reverse video" and (b) "reverse bit order", but none of them seems to be true. (a) The code maps 0-127 to 0 and 8-255 to 1, which just reduces from 256 to 2 grayscale levels, without inversion. The result is also white-on-black on my ssd130x OLED. (b) On little-endian, the CFB drawops use little-endian bit order, which is what ends up in "byte" in the code below. > + * @src: 8-bit grayscale source buffer > + * @clip: Clip rectangle area to copy > + * > + * DRM doesn't have native monochrome or grayscale support. > + * Such drivers can announce the commonly supported XR24 format to userspace > + * and use drm_fb_xrgb8888_to_gray8() to convert to grayscale and then this > + * helper function to convert to the native format. > + */ > +void drm_fb_gray8_to_mono_reversed(void *dst, void *src, const struct drm_rect *clip) > +{ > + size_t width = drm_rect_width(clip); > + size_t height = drm_rect_width(clip); > + > + u8 *mono = dst, *gray8 = src; > + unsigned int y, xb, i; > + > + for (y = 0; y < height; y++) > + for (xb = 0; xb < width / 8; xb++) { > + u8 byte = 0x00; > + > + for (i = 0; i < 8; i++) { > + int x = xb * 8 + i; > + > + byte >>= 1; > + if (gray8[y * width + x] >> 7) > + byte |= BIT(7); > + } > + *mono++ = byte; > + } > +} Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
next prev parent reply other threads:[~2022-03-14 13:40 UTC|newest] Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-31 20:12 [PATCH 0/4] drm/tiny: Add driver for Solomon SSD1307 OLED displays Javier Martinez Canillas 2022-01-31 20:12 ` Javier Martinez Canillas 2022-01-31 20:12 ` [PATCH 1/4] drm: Add I2C connector type Javier Martinez Canillas 2022-01-31 20:12 ` Javier Martinez Canillas 2022-01-31 20:52 ` Sam Ravnborg 2022-01-31 23:26 ` Javier Martinez Canillas 2022-01-31 23:26 ` Javier Martinez Canillas 2022-02-01 12:58 ` Noralf Trønnes 2022-02-01 12:58 ` Noralf Trønnes 2022-02-01 13:06 ` Javier Martinez Canillas 2022-02-01 13:20 ` Noralf Trønnes 2022-02-01 13:55 ` Javier Martinez Canillas 2022-02-01 13:38 ` Simon Ser 2022-02-01 13:38 ` Simon Ser 2022-02-01 14:20 ` Noralf Trønnes 2022-02-01 14:20 ` Noralf Trønnes 2022-02-01 20:57 ` Sam Ravnborg 2022-02-01 22:29 ` Simon Ser 2022-02-01 22:29 ` Simon Ser 2022-02-02 8:46 ` Javier Martinez Canillas 2022-02-02 8:46 ` Javier Martinez Canillas 2022-02-02 9:14 ` Thomas Zimmermann 2022-02-02 9:14 ` Thomas Zimmermann 2022-02-02 9:45 ` Noralf Trønnes 2022-02-02 9:45 ` Noralf Trønnes 2022-02-02 15:04 ` Pekka Paalanen 2022-02-02 15:04 ` Pekka Paalanen 2022-02-02 16:00 ` Noralf Trønnes 2022-02-02 16:00 ` Noralf Trønnes 2022-01-31 20:12 ` [PATCH 2/4] drm/format-helper: Add drm_fb_gray8_to_mono_reversed() Javier Martinez Canillas 2022-01-31 20:12 ` Javier Martinez Canillas 2022-02-01 9:59 ` Thomas Zimmermann 2022-02-01 9:59 ` Thomas Zimmermann 2022-02-01 11:13 ` Pekka Paalanen 2022-02-01 11:13 ` Pekka Paalanen 2022-02-01 11:48 ` Javier Martinez Canillas 2022-02-01 11:48 ` Javier Martinez Canillas 2022-03-14 13:40 ` Geert Uytterhoeven [this message] 2022-03-14 13:40 ` Geert Uytterhoeven 2022-03-14 14:07 ` Javier Martinez Canillas 2022-03-14 14:07 ` Javier Martinez Canillas 2022-01-31 20:36 ` [PATCH 0/4] drm/tiny: Add driver for Solomon SSD1307 OLED displays Simon Ser 2022-01-31 20:36 ` Simon Ser 2022-01-31 20:39 ` Simon Ser 2022-01-31 20:39 ` Simon Ser 2022-01-31 23:21 ` Javier Martinez Canillas 2022-01-31 23:21 ` Javier Martinez Canillas 2022-02-01 8:26 ` Geert Uytterhoeven 2022-02-01 8:26 ` Geert Uytterhoeven 2022-02-01 8:34 ` Simon Ser 2022-02-01 8:34 ` Simon Ser 2022-02-01 8:36 ` Geert Uytterhoeven 2022-02-01 8:36 ` Geert Uytterhoeven 2022-02-01 10:08 ` Thomas Zimmermann 2022-02-01 10:08 ` Thomas Zimmermann 2022-02-01 10:11 ` Simon Ser 2022-02-01 10:11 ` Simon Ser 2022-02-01 10:17 ` Thomas Zimmermann 2022-02-01 10:17 ` Thomas Zimmermann 2022-02-01 8:38 ` Daniel Vetter 2022-02-01 8:38 ` Daniel Vetter 2022-02-01 9:49 ` Javier Martinez Canillas 2022-02-01 9:49 ` Javier Martinez Canillas 2022-02-01 10:42 ` Pekka Paalanen 2022-02-01 10:42 ` Pekka Paalanen 2022-02-01 11:07 ` Geert Uytterhoeven 2022-02-01 11:07 ` Geert Uytterhoeven 2022-02-02 9:19 ` Pekka Paalanen 2022-02-02 9:19 ` Pekka Paalanen 2022-02-02 10:55 ` Geert Uytterhoeven 2022-02-02 10:55 ` Geert Uytterhoeven 2022-01-31 20:56 ` Sam Ravnborg 2022-01-31 23:37 ` Javier Martinez Canillas 2022-01-31 23:37 ` Javier Martinez Canillas 2022-02-01 9:37 ` Andy Shevchenko 2022-02-01 9:37 ` Andy Shevchenko 2022-02-01 11:31 ` Javier Martinez Canillas 2022-02-01 11:31 ` Javier Martinez Canillas 2022-02-01 11:38 ` Geert Uytterhoeven 2022-02-01 11:38 ` Geert Uytterhoeven 2022-02-01 13:09 ` Javier Martinez Canillas 2022-02-01 13:09 ` Javier Martinez Canillas 2022-02-01 14:14 ` Geert Uytterhoeven 2022-02-01 14:14 ` Geert Uytterhoeven 2022-02-01 15:03 ` Javier Martinez Canillas 2022-02-01 15:03 ` Javier Martinez Canillas 2022-02-01 20:40 ` Sam Ravnborg 2022-02-01 20:40 ` Sam Ravnborg 2022-02-02 8:38 ` Javier Martinez Canillas 2022-02-02 8:38 ` Javier Martinez Canillas 2022-02-02 11:06 ` Andy Shevchenko 2022-02-02 11:06 ` Andy Shevchenko 2022-02-02 11:39 ` Javier Martinez Canillas 2022-02-02 11:39 ` Javier Martinez Canillas 2022-02-02 11:50 ` Andy Shevchenko 2022-02-02 11:50 ` Andy Shevchenko 2022-02-02 11:54 ` Javier Martinez Canillas 2022-02-02 11:54 ` Javier Martinez Canillas 2022-02-02 12:21 ` Andy Shevchenko 2022-02-02 12:21 ` Andy Shevchenko 2022-02-01 8:43 ` Geert Uytterhoeven 2022-02-01 8:43 ` Geert Uytterhoeven 2022-02-01 9:27 ` Simon Ser 2022-02-01 9:27 ` Simon Ser 2022-02-01 10:36 ` Javier Martinez Canillas 2022-02-01 10:36 ` Javier Martinez Canillas
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=CAMuHMdWPQrErbMZ4wJPgROY7XOnKGvimNFg8JpiyuWqz2a3Gzw@mail.gmail.com \ --to=geert@linux-m68k.org \ --cc=airlied@linux.ie \ --cc=andriy.shevchenko@linux.intel.com \ --cc=daniel.vetter@ffwll.ch \ --cc=daniel@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=javierm@redhat.com \ --cc=linux-fbdev@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=maarten.lankhorst@linux.intel.com \ --cc=maxime@cerno.tech \ --cc=mripard@kernel.org \ --cc=noralf@tronnes.org \ --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: linkBe 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.