public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dzmitry Sankouski <dsankouski@gmail.com>
To: u-boot@lists.denx.de
Cc: Dzmitry Sankouski <dsankouski@gmail.com>,
	Anatolij Gustschin <agust@denx.de>
Subject: [PATCH 3/5] video console: add support for fonts wider than 1 byte
Date: Mon, 26 Dec 2022 22:49:27 +0300	[thread overview]
Message-ID: <20221226194929.166369-4-dsankouski@gmail.com> (raw)
In-Reply-To: <20221226194929.166369-1-dsankouski@gmail.com>

Devices with high ppi may benefit from wider fonts.

Current width implementation is limited by 1 byte, i.e. 8 bits.
New version iterates VIDEO_FONT_BYTE_WIDTH times, to process all
width bytes, thus allowing fonts wider than 1 byte.

Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
---
 drivers/video/console_simple.c | 79 ++++++++++++++++++----------------
 include/video_font_4x6.h       |  2 +
 include/video_font_data.h      |  2 +
 3 files changed, 47 insertions(+), 36 deletions(-)

diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index 20087a30af..3ae1fbdc89 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -61,30 +61,32 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
 {
 	int ret;
 	void *dst;
-	u8 mask = 0x80;
-
+	u8 mask;
 	ret = check_bpix_support(vid_priv->bpix);
 	if (ret)
 		return ret;
 
-	for (int col = 0; col < VIDEO_FONT_WIDTH; col++) {
-		dst = *line;
-		for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
-			u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH + col] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-
-			ret = fill_pixel_and_goto_next(&dst,
-						       value,
-						       VNBYTES(vid_priv->bpix),
-						       direction
-			);
+	for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+		mask = 0x80;
+		for (int bit = 0; bit < 8; bit++) {
+			dst = *line;
+			for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+				u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH + col] & mask) ?
+							vid_priv->colour_fg :
+							vid_priv->colour_bg;
+
+				ret = fill_pixel_and_goto_next(&dst,
+							       value,
+							       VNBYTES(vid_priv->bpix),
+							       direction
+				);
+			}
+			if (direction)
+				*line += vid_priv->line_length;
+			else
+				*line -= vid_priv->line_length;
+			mask >>= 1;
 		}
-		if (direction)
-			*line += vid_priv->line_length;
-		else
-			*line -= vid_priv->line_length;
-		mask >>= 1;
 	}
 	return ret;
 }
@@ -101,24 +103,29 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
 		return ret;
 	for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
 		dst = *line;
-		uchar bits = pfont[row];
-
-		for (int i = 0; i < VIDEO_FONT_WIDTH; i++) {
-			u32 value = (bits & 0x80) ?
-				vid_priv->colour_fg :
-				vid_priv->colour_bg;
-
-			ret = fill_pixel_and_goto_next(&dst,
-						       value,
-						       VNBYTES(vid_priv->bpix),
-						       direction
-			);
-			bits <<= 1;
+		uchar bits;
+
+		for (int i = 0; i < VIDEO_FONT_BYTE_WIDTH; i++) {
+			bits = pfont[i];
+			for (int bit = 0; bit < 8; bit++) {
+				u32 value = (bits & 0x80) ?
+					vid_priv->colour_fg :
+					vid_priv->colour_bg;
+
+				ret = fill_pixel_and_goto_next(&dst,
+							       value,
+							       VNBYTES(vid_priv->bpix),
+							       direction
+				);
+				bits <<= 1;
+			}
 		}
 		if (direction)
 			*line -= vid_priv->line_length;
 		else
 			*line += vid_priv->line_length;
+
+		pfont += VIDEO_FONT_BYTE_WIDTH;
 	}
 	return ret;
 }
@@ -177,7 +184,7 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int x, linenum, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_DATA_SIZE;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -286,7 +293,7 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int x, linenum, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_DATA_SIZE;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -357,7 +364,7 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int linenum, x, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_DATA_SIZE;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -432,7 +439,7 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
 	int pbytes = VNBYTES(vid_priv->bpix);
 	int linenum, x, ret;
 	void *start, *line;
-	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_HEIGHT;
+	uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_DATA_SIZE;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
diff --git a/include/video_font_4x6.h b/include/video_font_4x6.h
index c7e6351b64..f1eb2af861 100644
--- a/include/video_font_4x6.h
+++ b/include/video_font_4x6.h
@@ -43,7 +43,9 @@ __END__;
 
 #define VIDEO_FONT_CHARS	256
 #define VIDEO_FONT_WIDTH	4
+#define VIDEO_FONT_BYTE_WIDTH	VIDEO_FONT_WIDTH / 8 + (VIDEO_FONT_WIDTH % 8 > 0)
 #define VIDEO_FONT_HEIGHT	6
+#define VIDEO_FONT_CHAR_PIXEL_DATA_SIZE	VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH
 #define VIDEO_FONT_SIZE		(VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT)
 
 static unsigned char video_fontdata[VIDEO_FONT_SIZE] = {
diff --git a/include/video_font_data.h b/include/video_font_data.h
index 6e64198d1a..6a575e6d15 100644
--- a/include/video_font_data.h
+++ b/include/video_font_data.h
@@ -11,7 +11,9 @@
 
 #define VIDEO_FONT_CHARS	256
 #define VIDEO_FONT_WIDTH	8
+#define VIDEO_FONT_BYTE_WIDTH	VIDEO_FONT_WIDTH / 8 + (VIDEO_FONT_WIDTH % 8 > 0)
 #define VIDEO_FONT_HEIGHT	16
+#define VIDEO_FONT_CHAR_PIXEL_DATA_SIZE	VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH
 #define VIDEO_FONT_SIZE		(VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT)
 
 static unsigned char __maybe_unused video_fontdata[VIDEO_FONT_SIZE] = {
-- 
2.30.2


  parent reply	other threads:[~2022-12-26 19:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-26 19:49 [PATCH 0/5] vidconsole: refactoring and support for wider fonts Dzmitry Sankouski
2022-12-26 19:49 ` [PATCH 1/5] video console: unite normal and rotated files Dzmitry Sankouski
2022-12-29 22:38   ` Simon Glass
2023-01-11 17:08     ` Dzmitry Sankouski
2022-12-26 19:49 ` [PATCH 2/5] video console: refactoring and optimization Dzmitry Sankouski
2022-12-29 22:39   ` Simon Glass
2023-01-04 11:17     ` Dzmitry Sankouski
2023-01-04 20:01       ` Simon Glass
2023-02-13 17:02         ` Dzmitry Sankouski
2022-12-26 19:49 ` Dzmitry Sankouski [this message]
2022-12-29 22:38   ` [PATCH 3/5] video console: add support for fonts wider than 1 byte Simon Glass
2023-02-10  1:19   ` Andre Przywara
2022-12-26 19:49 ` [PATCH 4/5] video console: add 16x32 ter font from linux Dzmitry Sankouski
2022-12-29 22:39   ` Simon Glass
2023-01-11 16:59     ` Dzmitry Sankouski
2023-01-11 21:08       ` Simon Glass
2022-12-26 19:49 ` [PATCH 5/5] video console: remove unused 4x6 font Dzmitry Sankouski
2022-12-29 22:38   ` Simon Glass
2023-01-11 17:05     ` Dzmitry Sankouski
2023-02-10  1:38       ` Andre Przywara
2022-12-29 23:02 ` [PATCH 0/5] vidconsole: refactoring and support for wider fonts Mark Kettenis
2022-12-30 17:51   ` Simon Glass
2023-01-11 12:25   ` Dzmitry Sankouski

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=20221226194929.166369-4-dsankouski@gmail.com \
    --to=dsankouski@gmail.com \
    --cc=agust@denx.de \
    --cc=u-boot@lists.denx.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