mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: spu@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] fbconsole: support fonts wider than 16 pixels
Date: Sat, 24 Aug 2024 22:04:05 +0200	[thread overview]
Message-ID: <20240824200406.2160679-1-a.fatoum@pengutronix.de> (raw)

We have a nested loop that iterates over all pixels in a font, but it
only looks at the first 8 bits. This worked so far, because our biggest
font was VGA8x16. In the follow-up commit, a 16x32 font will be added,
so we need to prepare the code to consider the whole width of a font.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/video/fbconsole.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 6c85e8e06a8c..cec1afec56cb 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -117,7 +117,7 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 	int bpp = priv->fb->bits_per_pixel >> 3;
 	void *adr;
 	int i;
-	const char *inbuf;
+	const uint8_t *inbuf;
 	int line_length;
 	u32 color, bgcolor;
 	struct rgb *rgb;
@@ -142,21 +142,30 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 	bgcolor = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
 
 	for (i = 0; i < priv->font->height; i++) {
-		uint8_t t = inbuf[i];
+		uint8_t mask = 0x80;
 		int j;
 
 		adr = buf + line_length * (priv->margin.top + y * priv->font->height + i) +
 		      (priv->margin.left + x * priv->font->width) * bpp;
 
 		for (j = 0; j < priv->font->width; j++) {
-			if (t & 0x80)
+			if (!mask) {
+				inbuf++;
+				mask = 0x80;
+			}
+
+			if (*inbuf & mask)
 				gu_set_pixel(priv->fb, adr, color);
 			else
 				gu_set_pixel(priv->fb, adr, bgcolor);
 
 			adr += priv->fb->bits_per_pixel >> 3;
-			t <<= 1;
+			mask >>= 1;
+
 		}
+
+		inbuf++;
+		mask = 0x80;
 	}
 }
 
-- 
2.39.2




             reply	other threads:[~2024-08-24 20:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-24 20:04 Ahmad Fatoum [this message]
2024-08-24 20:04 ` [PATCH 2/2] fonts: add TER16x32 font Ahmad Fatoum
2024-08-26 11:13 ` [PATCH 1/2] fbconsole: support fonts wider than 16 pixels Sascha Hauer

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=20240824200406.2160679-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=spu@pengutronix.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