From patchwork Wed Oct 25 07:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13435527 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E5B11C25B47 for ; Wed, 25 Oct 2023 07:24:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2276A10E55B; Wed, 25 Oct 2023 07:24:07 +0000 (UTC) Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 44DEB10E55B for ; Wed, 25 Oct 2023 07:24:05 +0000 (UTC) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:7faa:e55:54a:cff]) by baptiste.telenet-ops.be with bizsmtp id 27Q32B0015Uc89d017Q3fe; Wed, 25 Oct 2023 09:24:03 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qvYFA-007ScD-7e; Wed, 25 Oct 2023 09:24:03 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qvYFH-00Bs6Q-2j; Wed, 25 Oct 2023 09:24:03 +0200 From: Geert Uytterhoeven To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v3 6/9] util: add test pattern support for big-endian XRGB1555/RGB565 Date: Wed, 25 Oct 2023 09:23:46 +0200 Message-Id: <886c8b6cf12f6c9a66d2dbc811f8dd1a58b019dc.1698217235.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add support for drawing the SMPTE and tiles test patterns in buffers using big-endian formats. For now this is limited to XRGB1555 and RGB565, which are the most common big-endian formats. Signed-off-by: Geert Uytterhoeven --- v3: - Increase indentation after definition of cpu_to_be16(), v2: - New. --- tests/util/pattern.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/util/pattern.c b/tests/util/pattern.c index 89e79277c53fe1fe..1eee384f4c611d24 100644 --- a/tests/util/pattern.c +++ b/tests/util/pattern.c @@ -23,6 +23,7 @@ * IN THE SOFTWARE. */ +#include #include #include #include @@ -75,13 +76,17 @@ static inline uint32_t swap32(uint32_t x) } #if defined(__BIG_ENDIAN__) || defined(__ARM_BIG_ENDIAN) || defined(__mc68000__) || defined(__MIPSEB__) || defined(__s390__) || defined(__sparc__) +#define cpu_to_be16(x) (x) #define cpu_to_le16(x) swap16(x) #define cpu_to_le32(x) swap32(x) #else +#define cpu_to_be16(x) swap16(x) #define cpu_to_le16(x) (x) #define cpu_to_le32(x) (x) #endif +#define cpu_to_fb16(x) (fb_be ? cpu_to_be16(x) : cpu_to_le16(x)) + /* This function takes 8-bit color values */ static inline uint32_t shiftcolor8(const struct util_color_component *comp, uint32_t value) @@ -382,7 +387,7 @@ static void fill_smpte_yuv_packed(const struct util_yuv_info *yuv, void *mem, static void fill_smpte_rgb16(const struct util_rgb_info *rgb, void *mem, unsigned int width, unsigned int height, - unsigned int stride) + unsigned int stride, bool fb_be) { const uint16_t colors_top[] = { MAKE_RGBA(rgb, 192, 192, 192, 255), /* grey */ @@ -417,26 +422,26 @@ static void fill_smpte_rgb16(const struct util_rgb_info *rgb, void *mem, for (y = 0; y < height * 6 / 9; ++y) { for (x = 0; x < width; ++x) - ((uint16_t *)mem)[x] = cpu_to_le16(colors_top[x * 7 / width]); + ((uint16_t *)mem)[x] = cpu_to_fb16(colors_top[x * 7 / width]); mem += stride; } for (; y < height * 7 / 9; ++y) { for (x = 0; x < width; ++x) - ((uint16_t *)mem)[x] = cpu_to_le16(colors_middle[x * 7 / width]); + ((uint16_t *)mem)[x] = cpu_to_fb16(colors_middle[x * 7 / width]); mem += stride; } for (; y < height; ++y) { for (x = 0; x < width * 5 / 7; ++x) ((uint16_t *)mem)[x] = - cpu_to_le16(colors_bottom[x * 4 / (width * 5 / 7)]); + cpu_to_fb16(colors_bottom[x * 4 / (width * 5 / 7)]); for (; x < width * 6 / 7; ++x) ((uint16_t *)mem)[x] = - cpu_to_le16(colors_bottom[(x - width * 5 / 7) * 3 + cpu_to_fb16(colors_bottom[(x - width * 5 / 7) * 3 / (width / 7) + 4]); for (; x < width; ++x) - ((uint16_t *)mem)[x] = cpu_to_le16(colors_bottom[7]); + ((uint16_t *)mem)[x] = cpu_to_fb16(colors_bottom[7]); mem += stride; } } @@ -1089,9 +1094,11 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3], case DRM_FORMAT_BGRA4444: case DRM_FORMAT_BGRX4444: case DRM_FORMAT_RGB565: + case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN: case DRM_FORMAT_BGR565: case DRM_FORMAT_ARGB1555: case DRM_FORMAT_XRGB1555: + case DRM_FORMAT_XRGB1555 | DRM_FORMAT_BIG_ENDIAN: case DRM_FORMAT_ABGR1555: case DRM_FORMAT_XBGR1555: case DRM_FORMAT_RGBA5551: @@ -1099,7 +1106,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3], case DRM_FORMAT_BGRA5551: case DRM_FORMAT_BGRX5551: return fill_smpte_rgb16(&info->rgb, planes[0], - width, height, stride); + width, height, stride, + info->format & DRM_FORMAT_BIG_ENDIAN); case DRM_FORMAT_BGR888: case DRM_FORMAT_RGB888: @@ -1271,7 +1279,7 @@ static void fill_tiles_yuv_packed(const struct util_format_info *info, static void fill_tiles_rgb16(const struct util_format_info *info, void *mem, unsigned int width, unsigned int height, - unsigned int stride) + unsigned int stride, bool fb_be) { const struct util_rgb_info *rgb = &info->rgb; void *mem_base = mem; @@ -1287,7 +1295,7 @@ static void fill_tiles_rgb16(const struct util_format_info *info, void *mem, (rgb32 >> 8) & 0xff, rgb32 & 0xff, 255); - ((uint16_t *)mem)[x] = cpu_to_le16(color); + ((uint16_t *)mem)[x] = cpu_to_fb16(color); } mem += stride; } @@ -1411,9 +1419,11 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3], case DRM_FORMAT_BGRA4444: case DRM_FORMAT_BGRX4444: case DRM_FORMAT_RGB565: + case DRM_FORMAT_RGB565 | DRM_FORMAT_BIG_ENDIAN: case DRM_FORMAT_BGR565: case DRM_FORMAT_ARGB1555: case DRM_FORMAT_XRGB1555: + case DRM_FORMAT_XRGB1555 | DRM_FORMAT_BIG_ENDIAN: case DRM_FORMAT_ABGR1555: case DRM_FORMAT_XBGR1555: case DRM_FORMAT_RGBA5551: @@ -1421,7 +1431,8 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3], case DRM_FORMAT_BGRA5551: case DRM_FORMAT_BGRX5551: return fill_tiles_rgb16(info, planes[0], - width, height, stride); + width, height, stride, + info->format & DRM_FORMAT_BIG_ENDIAN); case DRM_FORMAT_BGR888: case DRM_FORMAT_RGB888: