From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A496C678D4 for ; Tue, 7 Mar 2023 10:22:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6DAD085C02; Tue, 7 Mar 2023 11:22:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WRJ23raA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E922C85B2D; Tue, 7 Mar 2023 11:21:53 +0100 (CET) Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6841E85B6A for ; Tue, 7 Mar 2023 11:21:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=dsankouski@gmail.com Received: by mail-wm1-x335.google.com with SMTP id r19-20020a05600c459300b003eb3e2a5e7bso6880282wmo.0 for ; Tue, 07 Mar 2023 02:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678184503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hndsGVKz8OLN9QqIjiqvGhf2utCbF6rDqw134H4cY6I=; b=WRJ23raAPyvyrsA/IhBjdlE7Q3WT/kkC0k5/6PGmqYo2LWtJsrga8tikbzEZfnLpbs Nk+WUFyhukYWfqLT9g/fsXf/PBGZFQZXO5RaPwyXSCtlI4uNWBv0yYqiU68LbqnO0cRS 1C8B5wOxiWwimetFozMK3i4BQOYgxnLqluAnuS6rm6TJJ3U2JzJ9R6UWapd8bo2h3i3q RZ0RG/C5b0po2pmP0HEpIFFb1R99+F0sfnFFO8WZNXJKdhT9vBsMFqr1+D8W6SSh22cR cfU6OAg4y85SCPDcXUseym2hBIM6IlkIHsfjJMkkC+WTfjJB5ZGLrOCpYP1t/+3aONKA twZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678184503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hndsGVKz8OLN9QqIjiqvGhf2utCbF6rDqw134H4cY6I=; b=UtJxrSv3YYvKEC8pyviKTuiil/SfDnLViNqUW664Qj2JBzVqA2A6oMhU6QpNMv+vl0 jLhXN9tZC0nYT7H8HOEGI6bQB0u+gBxzcOTbG31JjbRWlEBTAqan6FS+O8jyD0223FkD g1tgGqIWaQN1VjmejXwqz4A2d4YWDwZmHKDr4oKGgqXfA75Hk/1bcbrc84kCUxxgyR8Q ExAMzjmQXTYXgOV/CMhkboOp1Gtn8cPnWGGuc0NLQQTjUaFDFF/EUbN+gfCV0NouDH64 SsFI/Zo1I06An91txFqzLGFVIMpxw1gYOmDoV1UeaFBxyKFQUtPlEITj/GJhR1GDOfkv /M5w== X-Gm-Message-State: AO0yUKX8Ub8CMQAJBvnRShmuKZGw+pVAqbHRSQ1wqP5pBLp2t4uDSwaG bjSFHhtg+OV3g+gLc4gQ8IBqZEXOzR0= X-Google-Smtp-Source: AK7set/u6YkN8jw5tekgw+yktIeOOwUVVrXtsMVmMwKrMmkHB+DNZYjlDKa387qtjE1FodhXwPkhBg== X-Received: by 2002:a05:600c:1c1f:b0:3eb:3b7e:7b89 with SMTP id j31-20020a05600c1c1f00b003eb3b7e7b89mr12610723wms.3.1678184503670; Tue, 07 Mar 2023 02:21:43 -0800 (PST) Received: from debian.localdomain ([37.45.231.77]) by smtp.googlemail.com with ESMTPSA id d42-20020a05600c4c2a00b003e6efc0f91csm12306258wmp.42.2023.03.07.02.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 02:21:43 -0800 (PST) From: Dzmitry Sankouski To: U-Boot Mailing List Cc: Dzmitry Sankouski , Simon Glass , Anatolij Gustschin Subject: [PATCH v8 02/10] video console: add support for fonts wider than 1 byte Date: Tue, 7 Mar 2023 13:21:12 +0300 Message-Id: <20230307102121.1925581-3-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230307102121.1925581-1-dsankouski@gmail.com> References: <20230307102121.1925581-1-dsankouski@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Simon Glass --- 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 /* 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