public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Dzmitry Sankouski <dsankouski@gmail.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dzmitry Sankouski <dsankouski@gmail.com>,
	Simon Glass <sjg@chromium.org>,
	Anatolij Gustschin <agust@denx.de>
Subject: [PATCH v8 02/10] video console: add support for fonts wider than 1 byte
Date: Tue,  7 Mar 2023 13:21:12 +0300	[thread overview]
Message-ID: <20230307102121.1925581-3-dsankouski@gmail.com> (raw)
In-Reply-To: <20230307102121.1925581-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>
Reviewed-by: Simon Glass <sjg@chromium.org>

---

Changes in v8:
none

Changes in v7:
none

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in v3:
none

Changes in v2:
- replace TAIL_BIT_COUNT macro with c code
- rename refactoring

 drivers/video/console_core.c        | 84 ++++++++++++++++++-----------
 drivers/video/console_normal.c      |  2 +-
 drivers/video/console_rotate.c      |  6 +--
 drivers/video/vidconsole_internal.h |  1 +
 4 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 9c2e4cb4ea..de004f585c 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -45,7 +45,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int ste
 int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
 			 bool direction)
 {
-	int step, line_step, pbytes, ret;
+	int step, line_step, pbytes, bitcount, width_remainder, ret;
 	void *dst;
 
 	ret = check_bpix_support(vid_priv->bpix);
@@ -61,23 +61,36 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
 		line_step = vid_priv->line_length;
 	}
 
+	width_remainder = VIDEO_FONT_WIDTH % 8;
 	for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+		uchar bits;
+
+		bitcount = 8;
 		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;
-
-			fill_pixel_and_goto_next(&dst,
-						 value,
-						 pbytes,
-						 step
-			);
-			bits <<= 1;
+		for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+			if (width_remainder) {
+				bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+
+				if (is_last_iteration)
+					bitcount = width_remainder;
+			}
+			bits = pfont[col];
+
+			for (int bit = 0; bit < bitcount; bit++) {
+				u32 value = (bits & 0x80) ?
+					vid_priv->colour_fg :
+					vid_priv->colour_bg;
+
+				fill_pixel_and_goto_next(&dst,
+							 value,
+							 pbytes,
+							 step
+				);
+				bits <<= 1;
+			}
 		}
 		*line += line_step;
+		pfont += VIDEO_FONT_BYTE_WIDTH;
 	}
 	return ret;
 }
@@ -85,9 +98,9 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
 int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv,
 			   bool direction)
 {
-	int step, line_step, pbytes, ret;
+	int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
 	void *dst;
-	u8 mask = 0x80;
+	u8 mask;
 
 	ret = check_bpix_support(vid_priv->bpix);
 	if (ret)
@@ -101,21 +114,32 @@ int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_pri
 		step = pbytes;
 		line_step = -vid_priv->line_length;
 	}
-	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] & mask) ?
-						vid_priv->colour_fg :
-						vid_priv->colour_bg;
-
-			fill_pixel_and_goto_next(&dst,
-						 value,
-						 pbytes,
-						 step
-			);
+
+	width_remainder = VIDEO_FONT_WIDTH % 8;
+	for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+		mask = 0x80;
+		if (width_remainder) {
+			bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+
+			if (is_last_iteration)
+				bitcount = width_remainder;
+		}
+		for (int bit = 0; bit < bitcount; bit++) {
+			dst = *line;
+			for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+				u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
+							vid_priv->colour_fg :
+							vid_priv->colour_bg;
+
+				fill_pixel_and_goto_next(&dst,
+							 value,
+							 pbytes,
+							 step
+				);
+			}
+			*line += line_step;
+			mask >>= 1;
 		}
-		*line += line_step;
-		mask >>= 1;
 	}
 	return ret;
 }
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 57186bedd8..e499e64852 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -67,7 +67,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_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index 70cc62d178..64e2f12c2f 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -71,7 +71,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_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -142,7 +142,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_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
@@ -217,7 +217,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_BYTES;
 
 	if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
 		return -EAGAIN;
diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h
index 0dfcd402c5..c7bc387035 100644
--- a/drivers/video/vidconsole_internal.h
+++ b/drivers/video/vidconsole_internal.h
@@ -9,6 +9,7 @@
 #include <video_font.h>		/* Get font data, width and height */
 
 #define VIDEO_FONT_BYTE_WIDTH	((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
+#define VIDEO_FONT_CHAR_PIXEL_BYTES	(VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH)
 
 #define FLIPPED_DIRECTION 1
 #define NORMAL_DIRECTION 0
-- 
2.30.2


  parent reply	other threads:[~2023-03-07 10:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 10:21 [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 01/10] video console: refactoring and optimization Dzmitry Sankouski
2023-03-07 10:21 ` Dzmitry Sankouski [this message]
2023-03-07 10:21 ` [PATCH v8 03/10] video console: move 8x16 font data in named header Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 04/10] video console: implement multiple fonts configuration Dzmitry Sankouski
2023-03-07 15:22   ` Anatolij Gustschin
2023-03-10  8:35     ` Dzmitry Sankouski
2023-03-10  9:24       ` Anatolij Gustschin
2023-03-07 10:21 ` [PATCH v8 05/10] video console: move vidconsole_get_font_size() logic to driver ops Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 06/10] video console: allow font size configuration at runtime Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 07/10] video console: add 12x22 Sun font from linux Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 08/10] video console: add 16x32 Terminus " Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 09/10] video console: sandbox: add 12x22 font defconfigs Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 10/10] video console: add 12x22 console simple font test Dzmitry Sankouski
2023-03-10  9:26 ` [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Anatolij Gustschin

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=20230307102121.1925581-3-dsankouski@gmail.com \
    --to=dsankouski@gmail.com \
    --cc=agust@denx.de \
    --cc=sjg@chromium.org \
    --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