From patchwork Fri Oct 10 03:42:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 567 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=1760067801; bh=lfUk1W7sJMaLm0CbS8q+N42aacPNy/mq4UZoHRTbNRc=; 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=HLulwZ8PYN2uWDJMkOPg1+wYE6Tebtux5Bgb4MaxTn39Esw73KEBzjqV2gHVBYEQY OtLKdW86t/S/oFhTUDrCMXonkpSew1akHf6+4zSq82k1iWYgJ9/Elhn6QFaP5ZDev+ dg4JICoW5oMizqPW2q2cXd3717+BUYAvKFObeeHAmZd73RFnOOhcG6ibVgZhPF6ATa UZrp7zTiSis4LobIxEhfAKO1XkMY4RvY06vnt2G8UIYGvUxLvVsQAf9rHKBLk3R9AP 5aOwgOoK+U/dHhCQk2w1tArZVngN8PrEom+hAFOMC7jUTUFEiKmfByaHPTTdAXvDSh qWvsw/rBj+Idw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6BFB96806E for ; Thu, 9 Oct 2025 21:43:21 -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 ZZQDIpFabrYb for ; Thu, 9 Oct 2025 21:43:21 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067799; bh=lfUk1W7sJMaLm0CbS8q+N42aacPNy/mq4UZoHRTbNRc=; 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=XpAFesw5nAPZkdyDtSZTZD4uuEQOdag/dBeO2miF8DeAteMDUJfb1q9KKmRVV20YL Kk573zyOfnJbeH9lGGL1FurlVrcl/x+uKfb4odhsZ9sur2whXRuaFoeVKhrEpdrQ1Q xV0Ks/m1PjGDdGk50RXkWiY5Ksf/JkETMXToPZIA5GkoNoIjpspl76YRIwsxEFCJbS SPJtPPFZJER0HtnRm1ccyu0Xe1YIB81xa8lvgB6fRY9WtS9AbBcVixusICAbeMZqt5 XfT702gsHMsuVNnOlJR++XNunPgwoNgEyyTGq1qHQypLk92S5WZ8IGcWVQOUwHDOub skyS/jCCClXQg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 674E068030 for ; Thu, 9 Oct 2025 21:43:19 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067796; bh=OW+1y5QZ7sYJM4/7nhbepDTzl0uQzkie8F5bdC5V3Zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qjq1zED5nVLao+j34LDdj3RbvSBJkLboVKz/NZOtbS1kXscNI+sMx0QERCI4qRWGD 52I2s927cGAfpGqWqtGYWKwCx0gA6sB92P9erIyreJPRxKRAb8ZTPT4DtKhAU4AYuu UE+gBNrauB/yTV9Q6JcH9kScHzzkHb8KKaQb6l2BMncPre/lY+8NfztYp5VgfRMx2J tCrxDx62jBMy1D2n2LoEnACC2QegH3mve8Xfk/TaVl+DU6q+5+/Wd5VhD92nAxzW8Z VpbkAEesWf4O+6bSM9CpwHT41ZZ4QiHDMqQYzwRzlt6lW8JIjdZOApAt5Y/jkwc6oC SwBLyd3br50GA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6CDD668030; Thu, 9 Oct 2025 21:43:16 -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 SgJ24jDx-Cia; Thu, 9 Oct 2025 21:43:16 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760067796; bh=gdLGaWAobmqg5PACWXuwI2qthZmekqzTstBF21Y8gaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zmkmp9xm64ySeCxamUnn/e77SwMOV5Ma81K679tU4P8ULDqI9MhXkTSNXNsr+AkJp BMjW+7WXYpQ5fBemJbFCZ7e7MM+qnfviRmgy+tD71m6o/2KsjusUlI7kZ+Kc6mCgKf M4nkB979KPJxncw0VV+r9PNzMHyuxSk3SV+CL2OlMnl3/2hUPlBx9wTnKK5f+8hSKQ WI7H7nFtCYRU5ZQWSAP1O002QYOhq9cf8Fov5PvCaVOhJ7DPQObRagCfbegyG2QK+P ifz9wfKtd2qJe0jKIIoGcXJc9bC9YfeTXUlj9aI95G4gJzf3GzE+Th2jxmsWZghsZ5 XnZUrbGfuN0Lg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C181167F7F; Thu, 9 Oct 2025 21:43:15 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 9 Oct 2025 21:42:29 -0600 Message-ID: <20251010034255.1099728-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251010034255.1099728-1-sjg@u-boot.org> References: <20251010034255.1099728-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6NGYLHRUQLIMG7ARMNJNH4O4R2T75NRZ X-Message-ID-Hash: 6NGYLHRUQLIMG7ARMNJNH4O4R2T75NRZ 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/18] test: video: Fix 16bpp BMP pixel format conversion 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 The video_write_bmp() function was writing 16bpp framebuffer data directly to BMP files without proper format conversion. The framebuffer uses RGB565 format (5 red, 6 green, 5 blue), but standard Windows BMP 16bpp format uses RGB555 (5 red, 5 green, 5 blue). Convert pixels from RGB565 to RGB555 by: - Extracting the 5-bit red, 6-bit green, and 5-bit blue components - Dropping the LSB of the green channel to convert from 6 to 5 bits - Reconstructing as RGB555 with the same R/B order This fixes incorrect colors in BMP output files (e.g., orange appearing as blue). Co-developed-by: Claude Signed-off-by: Simon Glass --- test/dm/video.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/dm/video.c b/test/dm/video.c index b06facec6e1..e51ff7789c7 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -70,7 +70,7 @@ static int video_write_bmp(struct unit_test_state *uts, struct udevice *dev, void *bmp_data; int ret, y; - /* Support 16bpp and 32bpp */ + /* Support 16bpp (converted to 15bpp for BMP) and 32bpp */ switch (priv->bpix) { case VIDEO_BPP16: bpp = 16; @@ -112,7 +112,24 @@ static int video_write_bmp(struct unit_test_state *uts, struct udevice *dev, void *src = priv->fb + (height - 1 - y) * priv->line_length; void *dst = bmp_data + y * row_bytes; - memcpy(dst, src, width * bytes_per_pixel); + if (bpp == 16) { + /* Convert RGB565 to RGB555 for BMP format */ + u16 *src16 = (u16 *)src; + u16 *dst16 = (u16 *)dst; + int x; + + for (x = 0; x < width; x++) { + u16 pixel = src16[x]; + /* Extract RGB565 components */ + u16 r = (pixel >> 11) & 0x1f; /* 5 bits */ + u16 g = (pixel >> 5) & 0x3f; /* 6 bits */ + u16 b = pixel & 0x1f; /* 5 bits */ + /* Convert to RGB555: drop LSB of green */ + dst16[x] = (r << 10) | ((g >> 1) << 5) | b; + } + } else { + memcpy(dst, src, width * bytes_per_pixel); + } } ret = os_write_file(fname, bmp, bmp_size);