[PATCH 1/2] fbconsole: support fonts wider than 16 pixels

Ahmad Fatoum a.fatoum at pengutronix.de
Sat Aug 24 13:04:05 PDT 2024


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 at 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




More information about the barebox mailing list