All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Anatolij Gustschin <agust@denx.de>, Tom Rini <trini@konsulko.com>,
	Simon Glass <sjg@chromium.org>
Subject: [PATCH 11/23] video: bmp: Update RLE8 support to use the write function
Date: Fri, 19 Nov 2021 13:23:55 -0700	[thread overview]
Message-ID: <20211119202408.1815506-12-sjg@chromium.org> (raw)
In-Reply-To: <20211119202408.1815506-1-sjg@chromium.org>

Update this code to use write_pix8() rather than writing the pixels only
for a single supported display depth. This allows us to support any
depth.

Add some more tests too.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/video_bmp.c | 49 +++++++++++++++++++++------------------
 test/dm/video.c           | 38 ++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 22 deletions(-)

diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 8d152c894cb..2a3536c7907 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -67,28 +67,37 @@ static void write_pix8(u8 *fb, uint bpix, struct bmp_color_table_entry *palette,
 }
 
 #ifdef CONFIG_VIDEO_BMP_RLE8
-static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
+static void draw_unencoded_bitmap(u8 **fbp, uint bpix, uchar *bmap,
+				  struct bmp_color_table_entry *palette,
 				  int cnt)
 {
+	u8 *fb = *fbp;
+
 	while (cnt > 0) {
-		*(*fbp)++ = cmap[*bmap++];
+		write_pix8(fb, bpix, palette, bmap++);
+		fb += bpix / 8;
 		cnt--;
 	}
+	*fbp = fb;
 }
 
-static void draw_encoded_bitmap(ushort **fbp, ushort col, int cnt)
+static void draw_encoded_bitmap(u8 **fbp, uint bpix,
+				struct bmp_color_table_entry *palette, u8 *bmap,
+				int cnt)
 {
-	ushort *fb = *fbp;
+	u8 *fb = *fbp;
 
 	while (cnt > 0) {
-		*fb++ = col;
+		write_pix8(fb, bpix, palette, bmap);
+		fb += bpix / 8;
 		cnt--;
 	}
 	*fbp = fb;
 }
 
 static void video_display_rle8_bitmap(struct udevice *dev,
-				      struct bmp_image *bmp, ushort *cmap,
+				      struct bmp_image *bmp, uint bpix,
+				      struct bmp_color_table_entry *palette,
 				      uchar *fb, int x_off, int y_off,
 				      ulong width, ulong height)
 {
@@ -97,6 +106,7 @@ static void video_display_rle8_bitmap(struct udevice *dev,
 	ulong cnt, runlen;
 	int x, y;
 	int decode = 1;
+	uint bytes_per_pixel = bpix / 8;
 
 	debug("%s\n", __func__);
 	bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
@@ -112,8 +122,8 @@ static void video_display_rle8_bitmap(struct udevice *dev,
 				bmap += 2;
 				x = 0;
 				y--;
-				/* 16bpix, 2-byte per pixel, width should *2 */
-				fb -= (width * 2 + priv->line_length);
+				fb -= width * bytes_per_pixel +
+					priv->line_length;
 				break;
 			case BMP_RLE8_EOBMP:
 				/* end of bitmap */
@@ -123,9 +133,9 @@ static void video_display_rle8_bitmap(struct udevice *dev,
 				/* delta run */
 				x += bmap[2];
 				y -= bmap[3];
-				/* 16bpix, 2-byte per pixel, x should *2 */
-				fb = (uchar *)(priv->fb + (y + y_off - 1)
-					* priv->line_length + (x + x_off) * 2);
+				fb = (uchar *)(priv->fb +
+					(y + y_off - 1) * priv->line_length +
+					(x + x_off) * bytes_per_pixel);
 				bmap += 4;
 				break;
 			default:
@@ -139,8 +149,8 @@ static void video_display_rle8_bitmap(struct udevice *dev,
 						else
 							cnt = runlen;
 						draw_unencoded_bitmap(
-							(ushort **)&fb,
-							bmap, cmap, cnt);
+							&fb, bpix,
+							bmap, palette, cnt);
 					}
 					x += runlen;
 				}
@@ -164,8 +174,8 @@ static void video_display_rle8_bitmap(struct udevice *dev,
 						cnt = width - x;
 					else
 						cnt = runlen;
-					draw_encoded_bitmap((ushort **)&fb,
-						cmap[bmap[1]], cnt);
+					draw_encoded_bitmap(&fb, bpix, palette,
+							    &bmap[1], cnt);
 				}
 				x += runlen;
 			}
@@ -311,13 +321,8 @@ int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
 		u32 compression = get_unaligned_le32(&bmp->header.compression);
 		debug("compressed %d %d\n", compression, BMP_BI_RLE8);
 		if (compression == BMP_BI_RLE8) {
-			if (bpix != 16) {
-				/* TODO implement render code for bpix != 16 */
-				printf("Error: only support 16 bpix");
-				return -EPROTONOSUPPORT;
-			}
-			video_display_rle8_bitmap(dev, bmp, cmap_base, fb, x,
-						  y, width, height);
+			video_display_rle8_bitmap(dev, bmp, bpix, palette, fb,
+						  x, y, width, height);
 			break;
 		}
 #endif
diff --git a/test/dm/video.c b/test/dm/video.c
index c8c6668c8b3..d5648f0c59b 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -373,6 +373,44 @@ static int dm_test_video_bmp_comp(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_video_bmp_comp, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+/* Test drawing a bitmap file on a 32bpp display */
+static int dm_test_video_comp_bmp32(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	ulong addr;
+
+	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+	ut_assertnonnull(dev);
+	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP32));
+
+	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+	ut_asserteq(2024, compress_frame_buffer(uts, dev));
+
+	return 0;
+}
+DM_TEST(dm_test_video_comp_bmp32, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test drawing a bitmap file on a 8bpp display */
+static int dm_test_video_comp_bmp8(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	ulong addr;
+
+	ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+	ut_assertnonnull(dev);
+	ut_assertok(sandbox_sdl_set_bpp(dev, VIDEO_BPP8));
+
+	ut_assertok(read_file(uts, "tools/logos/denx.bmp", &addr));
+
+	ut_assertok(video_bmp_display(dev, addr, 0, 0, false));
+	ut_asserteq(1247, compress_frame_buffer(uts, dev));
+
+	return 0;
+}
+DM_TEST(dm_test_video_comp_bmp8, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test TrueType console */
 static int dm_test_video_truetype(struct unit_test_state *uts)
 {
-- 
2.34.0.rc2.393.gf8c9666880-goog


  parent reply	other threads:[~2021-11-19 20:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19 20:23 [PATCH 00/23] video: Support a U-Boot logo more easily Simon Glass
2021-11-19 20:23 ` [PATCH 01/23] sandbox: video: Support 8bpp depth Simon Glass
2021-11-19 20:23 ` [PATCH 02/23] video: sandbox: Avoid duplicate display windows Simon Glass
2021-11-19 20:23 ` [PATCH 03/23] console: Avoid serial output before the console is running Simon Glass
2021-11-19 20:23 ` [PATCH 04/23] video: sandbox: Set a maximum frame-buffer size Simon Glass
2021-11-19 20:23 ` [PATCH 05/23] sandbox: video: Correct the address of the copy base Simon Glass
2021-11-19 20:23 ` [PATCH 06/23] sandbox: video: Add BMP tests for 32bpp and 8bpp modes Simon Glass
2021-11-19 20:23 ` [PATCH 07/23] video: Expand video debugging buffer size Simon Glass
2021-11-19 20:23 ` [PATCH 08/23] sandbox: Enable support for the gzip command Simon Glass
2021-11-19 20:23 ` [PATCH 09/23] video: Drop fb_put_byte() el at Simon Glass
2021-11-19 20:23 ` [PATCH 10/23] video: Move BMP pixel-writing into a function Simon Glass
2021-11-19 20:23 ` Simon Glass [this message]
2021-11-19 20:23 ` [PATCH 12/23] video: Drop the uclass colour map Simon Glass
2021-11-19 20:23 ` [PATCH 13/23] video: Tidy up 24/32 BMP blitting Simon Glass
2021-11-19 20:23 ` [PATCH 14/23] video: Add a test for 16bpp BMP files Simon Glass
2021-11-19 20:23 ` [PATCH 15/23] video: theadorable: Use RGB565 for BMP blitting Simon Glass
2021-11-19 20:24 ` [PATCH 16/23] video: Drop #ifdefs from video_bmp Simon Glass
2021-11-19 20:24 ` [PATCH 17/23] video: Convert CONFIG_VIDEO_LOGO to Kconfig Simon Glass
2022-01-22 13:26   ` Pali Rohár
2022-01-22 15:29     ` Tom Rini
2022-01-22 15:41       ` Pali Rohár
2022-01-22 18:41         ` Tom Rini
2022-01-23 14:48           ` Pali Rohár
2022-01-23 14:54             ` Tom Rini
2022-01-23 15:11               ` Pali Rohár
2022-01-23 16:14                 ` Tom Rini
2022-01-24  9:39                 ` Merlijn Wajer
2022-01-24 14:42                   ` Tom Rini
2022-01-22 17:17     ` Simon Glass
2021-11-19 20:24 ` [PATCH 18/23] video: Drop VIDEO_LOGO from cfb_console Simon Glass
2021-11-19 20:24 ` [PATCH 19/23] video: Support showing the U-Boot logo Simon Glass
2022-03-15 16:13   ` Tim Harvey
2022-03-28  6:35     ` Simon Glass
2022-03-28 18:50       ` Tim Harvey
2022-03-28 19:00         ` Fabio Estevam
2021-11-19 20:24 ` [PATCH 20/23] video: Show the U-Boot logo by default Simon Glass
2021-11-19 20:24 ` [PATCH 21/23] video: Support virtio devices with the splash screen Simon Glass
2021-11-23  2:08   ` Jaehoon Chung
2021-11-23  3:02     ` Peng Fan (OSS)
2021-11-19 20:24 ` [PATCH 22/23] x86: coreboot: Support getting a logo from virtio Simon Glass
2021-11-19 20:24 ` [PATCH 23/23] x86: coreboot: Add a sample script to build a qemu image Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211119202408.1815506-12-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=agust@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.