From patchwork Mon Dec 26 19:49:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dzmitry Sankouski X-Patchwork-Id: 1719528 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qobadFQX; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NgpKr4H1Yz23dc for ; Tue, 27 Dec 2022 06:50:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 86C3285519; Mon, 26 Dec 2022 20:49:50 +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="qobadFQX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D46E4854F1; Mon, 26 Dec 2022 20:49:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (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 C180E854F1 for ; Mon, 26 Dec 2022 20:49:38 +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-ej1-x62c.google.com with SMTP id m18so27670026eji.5 for ; Mon, 26 Dec 2022 11:49:38 -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=nPkUrsF49xXoGDAjUmZiR1DNJlZcV424r0ynKurxmt8=; b=qobadFQX9vJUwmoF8XZH3NJcB4s4kG+jtwVfFedNEnIWI1FUCer3ve9KTefkYQb02e C4GsslqxpXkcLjjQaPDAeF/O6C7lJawDLLmG5h4Aa4t4SFkQzeIBr+pFhbHVf7dSHAED kW7bLrGxXBdsXxdqIutctzCBQ4JuAvPUataT1gXMSBxlnXFq9LUh7dAD8kxrvf2PKTwB EO82XXP8cc1PZeHVhcSvvHGg/cJd2mXpLp/58XYCV/13w0vf7H80rNrslKH7yGlnAjv0 NykPaQ/jeR2bqDooghfCixwGbX+90ookHSvaJbU+Fe2pGzue97eAQk9gsfL7wDHlXZFK 2dpQ== 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=nPkUrsF49xXoGDAjUmZiR1DNJlZcV424r0ynKurxmt8=; b=OK3OtrBlWlAtiNRmql7cJj1nWeGlZkR1cV5O2s7UYT3m6/ykmoGAlS3vm7zKgPx2Wj Sb6H5k1d18gzqfM0mN2FKcn0c5aG4RahSdLt/d63Beiz3qaHvIgAwrwfzDhtOASjkFh2 1G475bTHnv8WJtS05SOWNz1Cm0FrAzu0k900kZ+Nv+UIYB0YDG8s9ZPM8rhwTD6CsuGp wfpQ8kc/j18YTBWv3KeLWUXzaJrekDOKwf8Nqvr+diiUS04Y0JRt6x4ugPijTWZNFX2e We41kCay7p+6yjngUBy5NRtxFUNGakXLwCHh5Gwcuh6a/N5Tbt3SV1lwscjVz3l/WwXG HzaQ== X-Gm-Message-State: AFqh2kr2stzQN1/U9R1uSb1xiVPFUAx3B02dc7Gir+CPeHOYLpLi5Gpt bAO2LO/WKAHBuK9WEm9sLyY5FU75XR0= X-Google-Smtp-Source: AMrXdXvhoKziyBrJmYMmkZ5kQc8KXPMuVD+SBbi2zYpnJCUd+n3MB+C13gzDbmsMJeoFBSK3ZFfnaA== X-Received: by 2002:a17:907:7e83:b0:7c0:e6d8:7770 with SMTP id qb3-20020a1709077e8300b007c0e6d87770mr18527347ejc.74.1672084178266; Mon, 26 Dec 2022 11:49:38 -0800 (PST) Received: from localhost.localdomain ([46.216.42.4]) by smtp.googlemail.com with ESMTPSA id kx18-20020a170907775200b007c14ae38a80sm5065666ejc.122.2022.12.26.11.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Dec 2022 11:49:37 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Anatolij Gustschin Subject: [PATCH 3/5] video console: add support for fonts wider than 1 byte Date: Mon, 26 Dec 2022 22:49:27 +0300 Message-Id: <20221226194929.166369-4-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221226194929.166369-1-dsankouski@gmail.com> References: <20221226194929.166369-1-dsankouski@gmail.com> MIME-Version: 1.0 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 --- 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] = {