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 4E050C64ED8 for ; Mon, 27 Feb 2023 17:37:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9C7D585AB1; Mon, 27 Feb 2023 18:37:31 +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="GnzqR8CW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 10EA185A6E; Mon, 27 Feb 2023 18:37:23 +0100 (CET) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 07F0985AAA for ; Mon, 27 Feb 2023 18:37:19 +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-ed1-x533.google.com with SMTP id ec43so28982845edb.8 for ; Mon, 27 Feb 2023 09:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=sUua5nUFRm/E5ychrTwd5kvpJ0BhQPIjrcybPUcnJ3Q=; b=GnzqR8CWmP1ko0NOVE1/DwRxuhZQEHp0IqlwfYpnObzn0uLsyLgrhtkefJNUheS8KV 0emLr9pb11qfUHxt2ELeixeGm9UZ0WVmAAvLQW/mqMWL/aR3Xnu4DHHq5fiiER13tRsk LkfPd5n+0TiKJfBY0uUc/Sj79URYnrTTOFw5up9ohVtwwdDj+4pbtbsp3HpJ6AC5xqet /WKgr5youJKEM9BZ1wx1iI+AMicaqU90sd86ReaHHIFLy3Iff34sjvDNpUaxUG4wvEYE OzLorSOwuMiLMnjSTsZ7m0CLg1pTc7/BTbc0BeD0CtMvsMQYDeYkWfD4gQDKKJwnGS0z 6zkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sUua5nUFRm/E5ychrTwd5kvpJ0BhQPIjrcybPUcnJ3Q=; b=HWFonJL6gAiLZUvaB098xsPCYu+dMoKMNZoZ93RquqqXulO97sZ5Rc8J6i+iuzdAVw FABm7/K2CpXVCM7cIlIrdpAOesKbnTHaww2wEpupDxY/gqbgVOS+PyRHrjZ0XFDDYhRh WIVcv0KxVltYVRv1yERwbjnVBR6neng/8j6I7xHzpk4v9iwbhbo347eN1xna1PcdZSBz zAXzhMv+JQumX1s6NRftQ1VX+PIfvtassgIlHNsGGUxtjQDuPcx9Zi0R23oKOPk4MhjX O1OoPWlT2C049LbPEhEX06zQPmf7OxglZNk6LJyPuC381DWGjPOySuI5vaPc8rW1BdhL dTJQ== X-Gm-Message-State: AO0yUKWznFcYSALoSombTH9NQZxS69jXBJZZymYw7FRaPu1RkwqtL36C J29/HXVF4Ndq/AiC+620ksuMzu1L0Vg= X-Google-Smtp-Source: AK7set/yvbcX1rBm8YqR+5hu0sW9L9YJVUrabQ3dsMuSA1Cf/VKWAIzAPwgZONvtvwT5eYwhVMm0IA== X-Received: by 2002:a05:6402:2a07:b0:4af:7bdc:1891 with SMTP id ey7-20020a0564022a0700b004af7bdc1891mr305274edb.11.1677519438240; Mon, 27 Feb 2023 09:37:18 -0800 (PST) Received: from debian.localdomain ([37.45.144.86]) by smtp.googlemail.com with ESMTPSA id c89-20020a509fe2000000b004aeeb476c5bsm3349912edf.24.2023.02.27.09.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 09:37:17 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Anatolij Gustschin , Simon Glass Subject: [PATCH v7 02/10] video console: add support for fonts wider than 1 byte Date: Mon, 27 Feb 2023 20:37:02 +0300 Message-Id: <20230227173710.1688611-3-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230227173710.1688611-1-dsankouski@gmail.com> References: <20230227173710.1688611-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.6 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 --- Charges for v2: - replace TAIL_BIT_COUNT macro with c code - rename refactoring Charges for v3: none Charges for v4: N/A Charges for v5: N/A Charges for v6: rebase only Charges for v7: none 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