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 35A71C636D6 for ; Thu, 23 Feb 2023 18:11:13 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7B0DD85A2F; Thu, 23 Feb 2023 19:11:11 +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="Y+HnQNpD"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E629085B19; Thu, 23 Feb 2023 19:10:44 +0100 (CET) Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (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 F25A68567B for ; Thu, 23 Feb 2023 19:10:35 +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-x532.google.com with SMTP id cq23so45054096edb.1 for ; Thu, 23 Feb 2023 10:10:35 -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=d81ANBjI2+bhUAyb5mjPUf0Fsw1eELW+wqbFMXlzsRo=; b=Y+HnQNpDVWgTITEkmkvF4N398Q149IM6z+gc2jaiMkdxgmfvQp0vbzRRID54cvZYUn oIdLYtQpOS+qeGmcIIViCM65KOAyQLPLnzWCl5019UsFv/xT2OqGB6H75ASbqPCnEoQJ ge8FYNHFMEhCfydB13TRKrz3daVvdqmxtfe2HKJ4DdEfilq9alVqacEXSexqPy+dcDYA SvVPLZTxLHQ7m9iDYKArxiQitjLx+wOJKkVw//VNTZsCUWjS5PEVbcv1cdfTJrSWdf58 /eXXhATEzFM6VGvL34N1d05tEJtD/UVU4fyDfJ9UdnFO4/53alXJlZ8fCADGCP4ENrKN ting== 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=d81ANBjI2+bhUAyb5mjPUf0Fsw1eELW+wqbFMXlzsRo=; b=tpNZcf8qSJxIvyhQgvz10i+bj0wNfxruReHf4NmQCqrZItXQHKfFTIiNhf+91AHYHu mD8ZUtf1322GAL+f3HpL2jniYDFYfo4qTMAV5sxVoQnLWNZ5wejtYKRA5101c2vtEZEu MW/+auiW5HzaXLW7XKCIAWsf3F1JK3qKq6i2ezulBoitz5wREGhWQrhubJc6rtSt/6Y/ 3rTjbN2XPpKrg1yH3lsMEKeBZQ1wjn/I2JejANsSiast0WyFNTWfM9eWBj1eFAK/Q+tj Ucj258DCWiP2SiwVoOA9nkjZNRXToJe1dgdFJHtLKYASVleN7Z3bZAkJxk9xX58pFSTQ 3lXg== X-Gm-Message-State: AO0yUKX753Ce/kxwCcg++mThfcbcCUGEyr+4q/SEMbDUnxvuygrzxaQ7 +KDig3wDqMpmRcW+q4EkVI20oip/fFM= X-Google-Smtp-Source: AK7set+CwLj3uMHcr/DfkBDMoqkPh+GaDzCCFDee/B9JISYC+x++XhVM5hKJdfkqHhzQR29GAJc1BA== X-Received: by 2002:a05:6402:12d9:b0:4af:6c25:ed9a with SMTP id k25-20020a05640212d900b004af6c25ed9amr3151770edx.29.1677175835359; Thu, 23 Feb 2023 10:10:35 -0800 (PST) Received: from debian.localdomain ([178.127.181.53]) by smtp.googlemail.com with ESMTPSA id j10-20020a50d00a000000b004af516b5010sm3822989edf.94.2023.02.23.10.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 10:10:34 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Anatolij Gustschin , Simon Glass Subject: [PATCH v6 2/9] video console: add support for fonts wider than 1 byte Date: Thu, 23 Feb 2023 21:10:22 +0300 Message-Id: <20230223181030.1596976-3-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230223181030.1596976-1-dsankouski@gmail.com> References: <20230223181030.1596976-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 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