]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
video console: add support for fonts wider than 1 byte
authorDzmitry Sankouski <dsankouski@gmail.com>
Tue, 7 Mar 2023 10:21:12 +0000 (13:21 +0300)
committerAnatolij Gustschin <agust@denx.de>
Tue, 7 Mar 2023 12:26:08 +0000 (13:26 +0100)
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>
drivers/video/console_core.c
drivers/video/console_normal.c
drivers/video/console_rotate.c
drivers/video/vidconsole_internal.h

index 9c2e4cb4ea526ee33146252b19dd581635f1d6eb..de004f585c41ac38a51b92f36832966bcc4d7b94 100644 (file)
@@ -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;
 }
index 57186bedd86b8fbe36fb72b0d9fbeac0ab2dec58..e499e64852b8cc7786e847d4ee290b51448869da 100644 (file)
@@ -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;
index 70cc62d1781ab58126682ee7d36c773101dc3f17..64e2f12c2fe201987c45606b0e57be640eccada3 100644 (file)
@@ -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;
index 0dfcd402c5401142c9b6b35f357fcf7cf5b1dc4c..c7bc3870352c18f494068fdf1e24d70f2f1b5642 100644 (file)
@@ -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