summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert@linux-m68k.org>2022-03-03 17:58:08 +0100
committerDmitry Baryshkov <dbaryshkov@gmail.com>2023-10-31 13:24:32 +0000
commit1b8d0e5ccd6db08185c4c178db40535b69e2505f (patch)
tree7eedaa32be5b48e09efd9194c18553818c561540
parent8cb6d837ccd140da54ab021e3860b7ef32c63e72 (diff)
downloadlibdrm-1b8d0e5ccd6db08185c4c178db40535b69e2505f.tar.gz
libdrm-1b8d0e5ccd6db08185c4c178db40535b69e2505f.tar.bz2
libdrm-1b8d0e5ccd6db08185c4c178db40535b69e2505f.zip
util: fix 16 bpp patterns on big-endian
DRM formats are defined to be little-endian, unless the DRM_FORMAT_BIG_ENDIAN flag is set. Hence writes of multi-byte pixel values need to take endianness into account. Introduce a swap16() helper to byteswap 16-bit values, and a cpu_to_le16() helper to convert 16-bit values from CPU-endian to little-endian, and use the latter in the various pattern fill functions for 16-bit formats. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> --- v5: - Add Reviewed-by, v4: - No changes, v3: - Increase indentation after definition of cpu_to_le16(), v2: - New.
-rw-r--r--tests/util/pattern.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/tests/util/pattern.c b/tests/util/pattern.c
index 1fbe642e..85cb3db7 100644
--- a/tests/util/pattern.c
+++ b/tests/util/pattern.c
@@ -61,6 +61,11 @@ struct color_yuv {
.u = MAKE_YUV_601_U(r, g, b), \
.v = MAKE_YUV_601_V(r, g, b) }
+static inline uint16_t swap16(uint16_t x)
+{
+ return ((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8);
+}
+
static inline uint32_t swap32(uint32_t x)
{
return ((x & 0x000000ffU) << 24) |
@@ -70,8 +75,10 @@ static inline uint32_t swap32(uint32_t x)
}
#ifdef HAVE_BIG_ENDIAN
+#define cpu_to_le16(x) swap16(x)
#define cpu_to_le32(x) swap32(x)
#else
+#define cpu_to_le16(x) (x)
#define cpu_to_le32(x) (x)
#endif
@@ -552,26 +559,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] = colors_top[x * 7 / width];
+ ((uint16_t *)mem)[x] = cpu_to_le16(colors_top[x * 7 / width]);
mem += stride;
}
for (; y < height * 7 / 9; ++y) {
for (x = 0; x < width; ++x)
- ((uint16_t *)mem)[x] = colors_middle[x * 7 / width];
+ ((uint16_t *)mem)[x] = cpu_to_le16(colors_middle[x * 7 / width]);
mem += stride;
}
for (; y < height; ++y) {
for (x = 0; x < width * 5 / 7; ++x)
((uint16_t *)mem)[x] =
- colors_bottom[x * 4 / (width * 5 / 7)];
+ cpu_to_le16(colors_bottom[x * 4 / (width * 5 / 7)]);
for (; x < width * 6 / 7; ++x)
((uint16_t *)mem)[x] =
- colors_bottom[(x - width * 5 / 7) * 3
- / (width / 7) + 4];
+ cpu_to_le16(colors_bottom[(x - width * 5 / 7) * 3
+ / (width / 7) + 4]);
for (; x < width; ++x)
- ((uint16_t *)mem)[x] = colors_bottom[7];
+ ((uint16_t *)mem)[x] = cpu_to_le16(colors_bottom[7]);
mem += stride;
}
}
@@ -1472,7 +1479,7 @@ static void fill_tiles_rgb16(const struct util_format_info *info, void *mem,
(rgb32 >> 8) & 0xff, rgb32 & 0xff,
255);
- ((uint16_t *)mem)[x] = color;
+ ((uint16_t *)mem)[x] = cpu_to_le16(color);
}
mem += stride;
}