Commit f21d62c9 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/format-helper: Store RGB565 in little-endian order

Fix to-RGB565 conversion helpers to store the result in little-
endian byte order. Update test cases as well.
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarMaíra Canal <mcanal@igalia.com>
Reviewed-by: default avatarJosé Expósito <jose.exposito89@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230102112927.26565-5-tzimmermann@suse.de
parent 58f5d983
...@@ -322,7 +322,7 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332); ...@@ -322,7 +322,7 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels) static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
{ {
u16 *dbuf16 = dbuf; __le16 *dbuf16 = dbuf;
const __le32 *sbuf32 = sbuf; const __le32 *sbuf32 = sbuf;
unsigned int x; unsigned int x;
u16 val16; u16 val16;
...@@ -333,14 +333,15 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne ...@@ -333,14 +333,15 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne
val16 = ((pix & 0x00F80000) >> 8) | val16 = ((pix & 0x00F80000) >> 8) |
((pix & 0x0000FC00) >> 5) | ((pix & 0x0000FC00) >> 5) |
((pix & 0x000000F8) >> 3); ((pix & 0x000000F8) >> 3);
dbuf16[x] = val16; dbuf16[x] = cpu_to_le16(val16);
} }
} }
/* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf, static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
unsigned int pixels) unsigned int pixels)
{ {
u16 *dbuf16 = dbuf; __le16 *dbuf16 = dbuf;
const __le32 *sbuf32 = sbuf; const __le32 *sbuf32 = sbuf;
unsigned int x; unsigned int x;
u16 val16; u16 val16;
...@@ -351,7 +352,7 @@ static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf, ...@@ -351,7 +352,7 @@ static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
val16 = ((pix & 0x00F80000) >> 8) | val16 = ((pix & 0x00F80000) >> 8) |
((pix & 0x0000FC00) >> 5) | ((pix & 0x0000FC00) >> 5) |
((pix & 0x000000F8) >> 3); ((pix & 0x000000F8) >> 3);
dbuf16[x] = swab16(val16); dbuf16[x] = cpu_to_le16(swab16(val16));
} }
} }
......
...@@ -264,6 +264,21 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch, ...@@ -264,6 +264,21 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
return dst_pitch * drm_rect_height(clip); return dst_pitch * drm_rect_height(clip);
} }
static u16 *le16buf_to_cpu(struct kunit *test, const __le16 *buf, size_t buf_size)
{
u16 *dst = NULL;
int n;
dst = kunit_kzalloc(test, sizeof(*dst) * buf_size, GFP_KERNEL);
if (!dst)
return NULL;
for (n = 0; n < buf_size; n++)
dst[n] = le16_to_cpu(buf[n]);
return dst;
}
static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size) static u32 *le32buf_to_cpu(struct kunit *test, const u32 *buf, size_t buf_size)
{ {
u32 *dst = NULL; u32 *dst = NULL;
...@@ -368,7 +383,7 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) ...@@ -368,7 +383,7 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
const struct convert_xrgb8888_case *params = test->param_value; const struct convert_xrgb8888_case *params = test->param_value;
const struct convert_to_rgb565_result *result = &params->rgb565_result; const struct convert_to_rgb565_result *result = &params->rgb565_result;
size_t dst_size; size_t dst_size;
__u16 *buf = NULL; u16 *buf = NULL;
__le32 *xrgb8888 = NULL; __le32 *xrgb8888 = NULL;
struct iosys_map dst, src; struct iosys_map dst, src;
...@@ -390,9 +405,12 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test) ...@@ -390,9 +405,12 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
iosys_map_set_vaddr(&src, xrgb8888); iosys_map_set_vaddr(&src, xrgb8888);
drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip, false); drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip, false);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0); KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected, dst_size), 0);
buf = dst.vaddr; /* restore original value of buf */
drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip, true); drm_fb_xrgb8888_to_rgb565(&dst, &result->dst_pitch, &src, &fb, &params->clip, true);
buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0); KUNIT_EXPECT_EQ(test, memcmp(buf, result->expected_swab, dst_size), 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment