diff mbox series

[libdrm,02/10] util: fix MAKE_RGBA macro for 10bpp modes

Message ID 20190603004017.7114-3-imirkin@alum.mit.edu (mailing list archive)
State New, archived
Headers show
Series Add C8, 30bpp and FP16 support to modetest | expand

Commit Message

Ilia Mirkin June 3, 2019, 12:40 a.m. UTC
We need to shift the values up, otherwise we'd end up with a negative
shift. This works for up-to 16-bit components, which is fine for now.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
---
 tests/util/pattern.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/tests/util/pattern.c b/tests/util/pattern.c
index c84fee5a..8bdebd2c 100644
--- a/tests/util/pattern.c
+++ b/tests/util/pattern.c
@@ -60,11 +60,22 @@  struct color_yuv {
 	  .u = MAKE_YUV_601_U(r, g, b), \
 	  .v = MAKE_YUV_601_V(r, g, b) }
 
+static inline uint32_t shiftcolor(const struct util_color_component *comp,
+				  uint32_t value)
+{
+	/* Fill the low bits with the high bits. */
+	value = (value << 8) | value;
+	/* Shift down to remove unwanted low bits */
+	value = value >> (16 - comp->length);
+	/* Shift back up to where the value should be */
+	return value << comp->offset;
+}
+
 #define MAKE_RGBA(rgb, r, g, b, a) \
-	((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
-	 (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
-	 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
-	 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
+	(shiftcolor(&(rgb)->red, (r)) | \
+	 shiftcolor(&(rgb)->green, (g)) | \
+	 shiftcolor(&(rgb)->blue, (b)) | \
+	 shiftcolor(&(rgb)->alpha, (a)))
 
 #define MAKE_RGB24(rgb, r, g, b) \
 	{ .value = MAKE_RGBA(rgb, r, g, b, 0) }