From patchwork Fri Oct 3 16:55:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 494 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510603; bh=+z0M54OjDsr9b9L9hQM3e+ZAaP+EXhJiJ0En3Z0EoSM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=f0MFqRFrncn5G6kMwo1m2PB3zzRh0kRMmv1IzrxNDRbwr8EFbpcpOBUSaHKAOePBi rWBvfjAw62wHO0EZIfU6g++8xsuP9KRzbs25yNds346IYoejZftxXJJGV8sTE5AjPD kXzygyrmkv0At556LezSev5upRt3sikM4D904Qo3fymBM6Y9nvvohS9jwp1dHhm7iM TVWAEwGgEjQawHXunK95wuLaxTvIvc1bbRGedjR5pqgbqhPR+j8M1/zjEr4T1a7wi0 dYq5ADWJsx9BoRSN2qYvX94eSjlzQufywq9oZ5P8zCslyU+/X3i7XkZbHKJH1y4XzW iKZhOXLPnBNjA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CE9AC67E12 for ; Fri, 3 Oct 2025 10:56:43 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id FARxea9FutNp for ; Fri, 3 Oct 2025 10:56:43 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510603; bh=+z0M54OjDsr9b9L9hQM3e+ZAaP+EXhJiJ0En3Z0EoSM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=f0MFqRFrncn5G6kMwo1m2PB3zzRh0kRMmv1IzrxNDRbwr8EFbpcpOBUSaHKAOePBi rWBvfjAw62wHO0EZIfU6g++8xsuP9KRzbs25yNds346IYoejZftxXJJGV8sTE5AjPD kXzygyrmkv0At556LezSev5upRt3sikM4D904Qo3fymBM6Y9nvvohS9jwp1dHhm7iM TVWAEwGgEjQawHXunK95wuLaxTvIvc1bbRGedjR5pqgbqhPR+j8M1/zjEr4T1a7wi0 dYq5ADWJsx9BoRSN2qYvX94eSjlzQufywq9oZ5P8zCslyU+/X3i7XkZbHKJH1y4XzW iKZhOXLPnBNjA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BC3CD67E82 for ; Fri, 3 Oct 2025 10:56:43 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510601; bh=KImV8YTcH5gM+ARb6/vctDO74ZoJDVKt12o69/TG1G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUbtqdQ9MgLUw5fQqslQ8n8eNkgdZYSl+w9im9cS4TSgLNF7iK/5nAzpoo2wDBhRJ aePtg6eb8XUKL85kUxpmdDhiY8ox1nUQbrXvJIkn0YIyVMD6/ob2kgGi0lhg8dCWXU RcbWARa//xkmxhG4tUB8kjHp/WAe3WNq14RpTpdGhC/e2hYU+Uz06+QrgScLDO7cwR 6/tFkUBvc3yy+VReYeasItq3TXgmo4HMROnOqOg3nyJJD9pnqnT3rywhVoW+beD+DY ItnoV7xCfADD1JXHbyCrAunK6H1qfBFDuxK0XoEqGjc3kAJjmmFji6+bOsTdZm+Gt2 wxL/MWcO2Wkhg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6399067E12; Fri, 3 Oct 2025 10:56:41 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id 2Hti2pAAH3za; Fri, 3 Oct 2025 10:56:41 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510595; bh=9DPh9l9pu79kxPZYTcEvxYxTNtCVMOIHDD8toyfpmOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uhV1q1vYw0r5WkJLrhGhLxMyq9gNq+yENj+kYf8sw/AesP4kRBwUhkKcQdGT0gn2O 77GYDQr+WCPrg/+Hui9lL+mlKopYzfp2NCIDQjbvagDZNYbVIM6n+zyjWayCymzIYJ FxR5yirXMKqySDa+AOUryzRfkshU1VDWrpzptLg83SVCnaaAwLJt13M86yzjb1TfG6 PxhsXRAtykR0z+eOfv6qn9jhsLD0bcLJbHGIHg/PQqFnyB5DJ6EBarHfXHYxqyE4Y2 WSSKdmJcje9urw2IVSyIBbgkH8pg3zek42RJLPB6LP6Pk5pqawuUwS7DAr2bamWNJC xyOTqF85x6h7A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 58E7E67E7C; Fri, 3 Oct 2025 10:56:35 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Oct 2025 10:55:06 -0600 Message-ID: <20251003165525.440173-14-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251003165525.440173-1-sjg@u-boot.org> References: <20251003165525.440173-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: SV6ZK3DJZYH4FP7OBCDHYIKYKCYVOYMH X-Message-ID-Hash: SV6ZK3DJZYH4FP7OBCDHYIKYKCYVOYMH X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 13/22] video: Export a function to draw a BMP with transparency List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Provide a new BMP function which can draw a bitmap while regarding a chosen colour as transparent. Signed-off-by: Simon Glass --- drivers/video/video_bmp.c | 6 ++++ include/video.h | 16 ++++++++++ test/dm/video.c | 62 ++++++++++++++++++++++++++++++++------- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c index ebdf73e25a9..43aa45f0efe 100644 --- a/drivers/video/video_bmp.c +++ b/drivers/video/video_bmp.c @@ -507,3 +507,9 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, { return draw_bmp(dev, bmp_image, x, y, align, false, 0); } + +int video_bmp_displaya(struct udevice *dev, ulong bmp_image, int x, int y, + bool align, bool alpha, u32 acolour) +{ + return draw_bmp(dev, bmp_image, x, y, align, alpha, acolour); +} diff --git a/include/video.h b/include/video.h index 9d9a725d30d..1ad5868e2f6 100644 --- a/include/video.h +++ b/include/video.h @@ -383,6 +383,22 @@ void video_bmp_get_info(const void *bmp_image, ulong *widthp, ulong *heightp, int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, bool align); +/** + * video_bmp_displaya() - Display a BMP image with alpha transparency + * + * @dev: Device to use + * @bmp_image: Address of BMP image + * @x: X position to draw image + * @y: Y position to draw image + * @align: true to adjust the coordinates to centre the image (see + * video_bmp_display() for details) + * @alpha: true to enable alpha transparency + * @acolour: Color to treat as transparent (RGB888 format: 0xRRGGBB) + * Return: 0 if OK, -ve on error + */ +int video_bmp_displaya(struct udevice *dev, ulong bmp_image, int x, int y, + bool align, bool alpha, u32 acolour); + /** * video_get_xsize() - Get the width of the display in pixels * diff --git a/test/dm/video.c b/test/dm/video.c index a802228b790..3defa184b14 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -667,15 +667,25 @@ static int dm_test_video_comp_bmp8(struct unit_test_state *uts) } DM_TEST(dm_test_video_comp_bmp8, UTF_SCAN_PDATA | UTF_SCAN_FDT); -/* Test drawing the riscos pointer */ -static int dm_test_video_bmp_alpha(struct unit_test_state *uts) +/** + * check_bmp_alpha() - Test drawing the riscos pointer with transparency + * + * Draws the riscos pointer BMP in various positions with and without + * transparency to verify alpha blending works correctly + * + * @uts: Test state + * @dev: Video device + * @first: Expected compression after first pointer draw + * @second: Expected compression after second pointer draw + * @trans: Expected compression after drawing with transparency + * Return: 0 if OK, -ve on error + */ +static int check_bmp_alpha(struct unit_test_state *uts, struct udevice *dev, + int first, int second, int trans) { - struct video_priv *priv; - struct udevice *dev; + struct video_priv *priv = dev_get_uclass_priv(dev); ulong addr; - ut_assertok(video_get_nologo(uts, &dev)); - priv = dev_get_uclass_priv(dev); addr = map_to_sysmem(video_image_getptr(riscos_arrow)); /* Draw a black rectangle first */ @@ -684,17 +694,49 @@ static int dm_test_video_bmp_alpha(struct unit_test_state *uts) /* Draw the pointer on top of the black rectangle */ ut_assertok(video_bmp_display(dev, addr, 110, 110, false)); - ut_asserteq(174, video_compress_fb(uts, dev, false)); + ut_asserteq(first, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); - /* Draw the pointer on top of the black rectangle */ + /* Draw the pointer on top of the white background */ ut_assertok(video_bmp_display(dev, addr, 350, 110, false)); - ut_asserteq(249, video_compress_fb(uts, dev, false)); + ut_asserteq(second, video_compress_fb(uts, dev, false)); + + /* Draw the pointer with white (0xffffff) as transparent */ + ut_assertok(video_bmp_displaya(dev, addr, 110, 160, false, true, + 0xffffff)); + ut_assertok(video_bmp_displaya(dev, addr, 350, 160, false, true, + 0xffffff)); + ut_asserteq(trans, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); return 0; } -DM_TEST(dm_test_video_bmp_alpha, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +/* Test drawing the riscos pointer on a 16bpp display */ +static int dm_test_video_bmp_alpha16(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(video_get_nologo(uts, &dev)); + ut_assertok(check_bmp_alpha(uts, dev, 174, 249, 358)); + + return 0; +} +DM_TEST(dm_test_video_bmp_alpha16, UTF_SCAN_PDATA | UTF_SCAN_FDT); + +/* Test drawing the riscos pointer on 32bpp display */ +static int dm_test_video_bmp_alpha32(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev)); + ut_assertnonnull(dev); + ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32)); + ut_assertok(check_bmp_alpha(uts, dev, 641, 710, 869)); + + return 0; +} +DM_TEST(dm_test_video_bmp_alpha32, UTF_SCAN_PDATA | UTF_SCAN_FDT); /* Test TrueType console */ static int dm_test_video_truetype(struct unit_test_state *uts)