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 8305FC636CC for ; Mon, 13 Feb 2023 16:58:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B018C857FD; Mon, 13 Feb 2023 17:58:40 +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="jxmdGz9E"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E29980A08; Mon, 13 Feb 2023 17:57:39 +0100 (CET) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (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 BAF50856E5 for ; Mon, 13 Feb 2023 17:57:07 +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-x535.google.com with SMTP id w3so6819925edc.2 for ; Mon, 13 Feb 2023 08:57:07 -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=rkPcz2RCfK34sntV7t3jbw1wjtuUURy1FS8GfmltaGY=; b=jxmdGz9EjYyhfXCkkkwzqN8E1oKw7oDOBBPEgH1uZUZcB/2twfCjR28SaRe29bx42B HDmm7up201P0oOiGwr9Yc4C5+XASNJlnGZfMzeYqW5XKaPxHsmoNsZOZo5b+ziCA1EJq ubDex85YMHzVzih0FcPSAYi6e21CQvQkFjouATEV2KZZtt/YYtF+4k6+IlCAbhkthwyo K2OaHdW+JDeHPFhM9qKkPe7LNEvqBvxtLGBUVqS+4QpiscLHuTHHUj5gF5ZxJyKVx5ea LX2mIcD9UWNK1FLPxTx4Ld9kuROIsP2Pu7tTrhd6Cdt52ail6/y3WBV9lLSKo41O+Ne1 pDPw== 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=rkPcz2RCfK34sntV7t3jbw1wjtuUURy1FS8GfmltaGY=; b=D/0XpeS+FvUuBV+o5HnCwZOCviF/HHHFgE9jpGZvdO2Lbw8QH5IuUPZEfmlkRSeZF7 8YYIrLM0IuDeSNPgHXK7dJ7LeBinp1DhM9l9xB4T0Pn5fGP1+y7J2WzQSfsu0ACcw4tK UpYneAEfwPwMEfgwS+L+Xqbpo07KAuYyZPvmRq3V4jjr9EGYaLYD3hswmJrTciUpELNQ WqhjMGM64skrEQ9qvf5Zv25oD0iVkQUGQ/SjK8Ka2X78VBdGAownDGS2sIQTyMmLRE3m 5tjE8Gh/nUyIbdQOLtga3IPYeUR3Hip5xUFGPWzKdV22FPNXf1ZJL44pJaznpZBK4pqz RNBg== X-Gm-Message-State: AO0yUKUjbvWfFJiTAWO3iTPBfqBU4bLIOnsIlErp2ZqWtU8DD2jtXit4 w+hf+8rgxyBad03k1qAZOvmxjFAFGI0= X-Google-Smtp-Source: AK7set9VcYe2w5w9J4jXspiIXHry2G1Aw4lI0UREe8mGlUXepJopTw8Y+J5y1PMiaIYiKdLli3P4Cg== X-Received: by 2002:a50:d081:0:b0:4ac:be85:8b27 with SMTP id v1-20020a50d081000000b004acbe858b27mr5507138edd.5.1676307426879; Mon, 13 Feb 2023 08:57:06 -0800 (PST) Received: from debian.localdomain ([37.45.245.36]) by smtp.googlemail.com with ESMTPSA id v1-20020a50c401000000b004a249a97d84sm6897592edf.23.2023.02.13.08.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:57:06 -0800 (PST) From: Dzmitry Sankouski To: u-boot@lists.denx.de Cc: Dzmitry Sankouski , Anatolij Gustschin Subject: [PATCH v2 3/8] video console: add support for fonts wider than 1 byte Date: Mon, 13 Feb 2023 19:56:55 +0300 Message-Id: <20230213165700.982691-4-dsankouski@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230213165700.982691-1-dsankouski@gmail.com> References: <20230213165700.982691-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 --- Charges for v2: - replace TAIL_BIT_COUNT macro with c code - rename refactoring drivers/video/console_simple.c | 93 +++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 34 deletions(-) diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c index 1eb47be449..cdc26cac30 100644 --- a/drivers/video/console_simple.c +++ b/drivers/video/console_simple.c @@ -13,6 +13,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 @@ -95,9 +96,9 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, static 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) @@ -111,21 +112,32 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv * 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; } @@ -158,7 +170,7 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv * static 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); @@ -174,23 +186,36 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi 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; } @@ -249,7 +274,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; @@ -358,7 +383,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; @@ -429,7 +454,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; @@ -504,7 +529,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; -- 2.30.2