From patchwork Wed Feb 9 21:16:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janne Grunau X-Patchwork-Id: 1590727 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JvCP056kxz9s9c for ; Thu, 10 Feb 2022 08:16:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 98C3A83A34; Wed, 9 Feb 2022 22:16:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 2CF3983EDF; Wed, 9 Feb 2022 22:16:27 +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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from soltyk.jannau.net (soltyk.jannau.net [144.76.91.90]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8C44683A2B for ; Wed, 9 Feb 2022 22:16:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=jannau.net Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=j@jannau.net Received: from coburn.home.jannau.net (p579ad520.dip0.t-ipconnect.de [87.154.213.32]) by soltyk.jannau.net (Postfix) with ESMTPSA id 2487E26E39F; Wed, 9 Feb 2022 22:16:23 +0100 (CET) From: Janne Grunau To: u-boot@lists.denx.de Cc: Mark Kettenis , Tom Rini , sjg@chromium.com Subject: [PATCH 1/1] video: bmp: Support x2r10g10b10 pixel format Date: Wed, 9 Feb 2022 22:16:22 +0100 Message-Id: <20220209211622.23599-1-j@jannau.net> X-Mailer: git-send-email 2.35.1 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.5 at phobos.denx.de X-Virus-Status: Clean Fixes the display of the u-boot logo on Apple silicon devices. Signed-off-by: Janne Grunau Reviewed-by: Simon Glass --- drivers/video/video_bmp.c | 70 +++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c index c8c3fd3549..4d2d961696 100644 --- a/drivers/video/video_bmp.c +++ b/drivers/video/video_bmp.c @@ -30,6 +30,18 @@ static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte) ((cte.blue >> 3) & 0x001f); } +/** + * get_bmp_col_x2r10g10b10() - Convert a colour-table entry into a x2r10g10b10 pixel value + * + * Return: value to write to the x2r10g10b10 frame buffer for this palette entry + */ +static u32 get_bmp_col_x2r10g10b10(struct bmp_color_table_entry *cte) +{ + return ((cte->red << 22U) | + (cte->green << 12U) | + (cte->blue << 2U)); +} + /** * write_pix8() - Write a pixel from a BMP image into the framebuffer * @@ -42,8 +54,8 @@ static uint get_bmp_col_16bpp(struct bmp_color_table_entry cte) * 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) +static void write_pix8(u8 *fb, uint bpix, enum video_format eformat, + struct bmp_color_table_entry *palette, u8 *bmap) { if (bpix == 8) { *fb++ = *bmap; @@ -57,6 +69,8 @@ static void write_pix8(u8 *fb, uint bpix, struct bmp_color_table_entry *palette, *fb++ = cte->red; *fb++ = cte->green; *fb++ = cte->blue; + } else if (eformat == VIDEO_X2R10G10B10) { + *(u32 *)fb = get_bmp_col_x2r10g10b10(cte); } else { *fb++ = cte->blue; *fb++ = cte->green; @@ -66,28 +80,29 @@ static void write_pix8(u8 *fb, uint bpix, struct bmp_color_table_entry *palette, } } -static void draw_unencoded_bitmap(u8 **fbp, uint bpix, uchar *bmap, +static void draw_unencoded_bitmap(u8 **fbp, uint bpix, + enum video_format eformat, uchar *bmap, struct bmp_color_table_entry *palette, int cnt) { u8 *fb = *fbp; while (cnt > 0) { - write_pix8(fb, bpix, palette, bmap++); + write_pix8(fb, bpix, eformat, palette, bmap++); fb += bpix / 8; cnt--; } *fbp = fb; } -static void draw_encoded_bitmap(u8 **fbp, uint bpix, +static void draw_encoded_bitmap(u8 **fbp, uint bpix, enum video_format eformat, struct bmp_color_table_entry *palette, u8 *bmap, int cnt) { u8 *fb = *fbp; while (cnt > 0) { - write_pix8(fb, bpix, palette, bmap); + write_pix8(fb, bpix, eformat, palette, bmap); fb += bpix / 8; cnt--; } @@ -106,6 +121,7 @@ static void video_display_rle8_bitmap(struct udevice *dev, int x, y; int decode = 1; uint bytes_per_pixel = bpix / 8; + enum video_format eformat = priv->format; debug("%s\n", __func__); bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); @@ -148,7 +164,7 @@ static void video_display_rle8_bitmap(struct udevice *dev, else cnt = runlen; draw_unencoded_bitmap( - &fb, bpix, + &fb, bpix, eformat, bmap, palette, cnt); } x += runlen; @@ -173,8 +189,9 @@ static void video_display_rle8_bitmap(struct udevice *dev, cnt = width - x; else cnt = runlen; - draw_encoded_bitmap(&fb, bpix, palette, - &bmap[1], cnt); + draw_encoded_bitmap(&fb, bpix, eformat, + palette, &bmap[1], + cnt); } x += runlen; } @@ -224,6 +241,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, unsigned long width, height, byte_width; unsigned long pwidth = priv->xsize; unsigned colours, bpix, bmp_bpix; + enum video_format eformat; struct bmp_color_table_entry *palette; int hdr_size; int ret; @@ -245,6 +263,7 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, colours = 1 << bmp_bpix; bpix = VNBITS(priv->bpix); + eformat = priv->format; if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { printf("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", @@ -312,7 +331,7 @@ 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++) { - write_pix8(fb, bpix, palette, bmap); + write_pix8(fb, bpix, eformat, palette, bmap); bmap++; fb += bpix / 8; } @@ -345,6 +364,16 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, (bmap[0] >> 3); bmap += 3; fb += 2; + } else if (eformat == VIDEO_X2R10G10B10) { + u32 pix; + + pix = *bmap++ << 2U; + pix |= *bmap++ << 12U; + pix |= *bmap++ << 22U; + *fb++ = pix & 0xff; + *fb++ = (pix >> 8) & 0xff; + *fb++ = (pix >> 16) & 0xff; + *fb++ = pix >> 24; } else { *fb++ = *bmap++; *fb++ = *bmap++; @@ -361,10 +390,23 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, if (IS_ENABLED(CONFIG_BMP_32BPP)) { for (i = 0; i < height; ++i) { for (j = 0; j < width; j++) { - *fb++ = *bmap++; - *fb++ = *bmap++; - *fb++ = *bmap++; - *fb++ = *bmap++; + if (eformat == VIDEO_X2R10G10B10) { + u32 pix; + + pix = *bmap++ << 2U; + pix |= *bmap++ << 12U; + pix |= *bmap++ << 22U; + pix |= (*bmap++ >> 6) << 30U; + *fb++ = pix & 0xff; + *fb++ = (pix >> 8) & 0xff; + *fb++ = (pix >> 16) & 0xff; + *fb++ = pix >> 24; + } else { + *fb++ = *bmap++; + *fb++ = *bmap++; + *fb++ = *bmap++; + *fb++ = *bmap++; + } } fb -= priv->line_length + width * (bpix / 8); }