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 mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE947C433EF for ; Fri, 19 Nov 2021 20:26:55 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 57F4261AA2 for ; Fri, 19 Nov 2021 20:26:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 57F4261AA2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 235EB837A8; Fri, 19 Nov 2021 21:25:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="mkGm75GW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DF0878341B; Fri, 19 Nov 2021 21:25:07 +0100 (CET) Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) (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 1FE6083763 for ; Fri, 19 Nov 2021 21:24:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22e.google.com with SMTP id s139so23800063oie.13 for ; Fri, 19 Nov 2021 12:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ssD4iCtw8GtetCQvM9JZI8eWeDflO6VGnZdwLXf0Jg=; b=mkGm75GW0jBTv2pV9WUYe+3fNHW1utW24oaY6U1Ne+dTO7frTI0/mroM2iz5LYUR0N kXlxRYyGl4Deeu4gNu7K/dpBunTUrPlezzqEKPo00E7JjYHPGrJcPPhI3CSFvNNUkg/4 DoOudvn0aWW7nkHJNOhb/R1J0lRpyULIGoug4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ssD4iCtw8GtetCQvM9JZI8eWeDflO6VGnZdwLXf0Jg=; b=2/TcrUEZb9z+uwZCtHEr+qYqrGw18ewY4f8htpUckcQ5Z63kyqVtP2rrJWH8HBGkij M8hJ/PF+52VuLo1RZ8/BkNr3Jy7Y15Mkq2dMknQVGBZBPq8dIi2tl5PGFbrAGHJFhre8 6rKfFSIShkMdUYTc+HT2hgUOMxSHmnuBWZAa5xXBujbkPFMr/JlYgghF84/smygGHkq6 uK6w01S1Rkv7xzKFRu4PvuWyeUaZ4TLnRHmEbNhbdAmhECkN8au6/piMlSbqD5F6K1DX gFmTBxmjddTZWQ67sCFC5K0VPIC0gUI3mPm8LV+0/cnsmOqMZdW0XAMuZ+Amc17j6PdU shSw== X-Gm-Message-State: AOAM533BPZoGafUuvdS/8uSpoBdyeUVyH61AiTC9yZuDTpxTSKCz2mCH rJIdb7WpnepARzzqEjnGgdGR5PeMo20Thg== X-Google-Smtp-Source: ABdhPJz04f3ehF7/g2h14tGl8sPHvlot09/ZNLi0gmhUJRwlLVI/ADsF7NbDZcSs5qYj+AF4B7ZXiA== X-Received: by 2002:aca:d07:: with SMTP id 7mr2362441oin.92.1637353468603; Fri, 19 Nov 2021 12:24:28 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id bl33sm197093oib.47.2021.11.19.12.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 12:24:28 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Anatolij Gustschin , Tom Rini , Simon Glass Subject: [PATCH 10/23] video: Move BMP pixel-writing into a function Date: Fri, 19 Nov 2021 13:23:54 -0700 Message-Id: <20211119202408.1815506-11-sjg@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211119202408.1815506-1-sjg@chromium.org> References: <20211119202408.1815506-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 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.2 at phobos.denx.de X-Virus-Status: Clean At present the code that writes to a pixel is quite convoluted. It uses a colour map which is in the uclass and the same code is repeated in different places within video_bmp_display(). As a first step, create a function which can write a pixel from the bitmap, no matter what the display depth. Use any provided palette directly, rather than using the uclass version. Signed-off-by: Simon Glass --- drivers/video/video_bmp.c | 75 +++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c index 7b3e15b7094..8d152c894cb 100644 --- a/drivers/video/video_bmp.c +++ b/drivers/video/video_bmp.c @@ -13,12 +13,60 @@ #include #include -#ifdef CONFIG_VIDEO_BMP_RLE8 #define BMP_RLE8_ESCAPE 0 #define BMP_RLE8_EOL 0 #define BMP_RLE8_EOBMP 1 #define BMP_RLE8_DELTA 2 +/** + * get_bmp_col_16bpp() - Convert a colour-table entry into a 16bpp pixel value + * + * @return value to write to the 16bpp frame buffer for this palette entry + */ +static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte) +{ + return ((cte.red << 8) & 0xf800) | + ((cte.green << 3) & 0x07e0) | + ((cte.blue >> 3) & 0x001f); +} + +/** + * write_pix8() - Write a pixel from a BMP image into the framebuffer + * + * This handles frame buffers with 8, 16, 24 or 32 bits per pixel + * + * @fb: Place in frame buffer to update + * @bpix: Frame buffer bits-per-pixel, which controls how many bytes are written + * @palette: BMP palette table + * @bmap: Pointer to BMP bitmap position to write. This contains a single byte + * which is either written directly (bpix == 8) or used to look up the + * palette to get a colour to write + */ +static void write_pix8(u8 *fb, uint bpix, struct bmp_color_table_entry *palette, + u8 *bmap) +{ + if (bpix == 8) { + *fb++ = *bmap; + } else if (bpix == 16) { + *(u16 *)fb = get_bmp_col_16bpp(palette[*bmap]); + } else { + /* Only support big endian */ + struct bmp_color_table_entry *cte = &palette[*bmap]; + + if (bpix == 24) { + *fb++ = cte->red; + *fb++ = cte->green; + *fb++ = cte->blue; + } else { + *fb++ = cte->blue; + *fb++ = cte->green; + *fb++ = cte->red; + *fb++ = 0; + } + } +} + +#ifdef CONFIG_VIDEO_BMP_RLE8 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, int cnt) { @@ -258,7 +306,6 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, switch (bmp_bpix) { case 1: case 8: { - struct bmp_color_table_entry *cte; cmap_base = priv->cmap; #ifdef CONFIG_VIDEO_BMP_RLE8 u32 compression = get_unaligned_le32(&bmp->header.compression); @@ -281,27 +328,9 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, for (i = 0; i < height; ++i) { WATCHDOG_RESET(); for (j = 0; j < width; j++) { - if (bpix == 8) { - *fb++ = *bmap++; - } else if (bpix == 16) { - *(uint16_t *)fb = cmap_base[*bmap]; - bmap++; - fb += sizeof(uint16_t) / sizeof(*fb); - } else { - /* Only support big endian */ - cte = &palette[*bmap]; - bmap++; - if (bpix == 24) { - *(fb++) = cte->red; - *(fb++) = cte->green; - *(fb++) = cte->blue; - } else { - *(fb++) = cte->blue; - *(fb++) = cte->green; - *(fb++) = cte->red; - *(fb++) = 0; - } - } + write_pix8(fb, bpix, palette, bmap); + bmap++; + fb += bpix / 8; } bmap += (padded_width - width); fb -= byte_width + priv->line_length; -- 2.34.0.rc2.393.gf8c9666880-goog