[PATCH libdrm] tests: Fix pattern filler routines for 10-bit RGB colours

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The routines that fill the framebuffer with colour data don't work
properly for data formats that use 10 bits for RGB colours. Add
sibling routines for those formats and use them where appropriate.

Signed-off-by: Liviu Dudau <Liviu.Dudau@xxxxxxx>
---
 tests/util/pattern.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 100 insertions(+), 2 deletions(-)

diff --git a/tests/util/pattern.c b/tests/util/pattern.c
index 00b08a8c..4eed9771 100644
--- a/tests/util/pattern.c
+++ b/tests/util/pattern.c
@@ -70,6 +70,12 @@ struct color_yuv {
 	 (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
 	 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
 
+#define MAKE_RGBA30(rgb, r, g, b, a) \
+	((((r) >> (10 - (rgb)->red.length)) << (rgb)->red.offset) | \
+	 (((g) >> (10 - (rgb)->green.length)) << (rgb)->green.offset) | \
+	 (((b) >> (10 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
+	 (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
+
 #define MAKE_RGB24(rgb, r, g, b) \
 	{ .value = MAKE_RGBA(rgb, r, g, b, 0) }
 
@@ -461,6 +467,67 @@ static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem,
 	}
 }
 
+static void fill_smpte_rgb30(const struct util_rgb_info *rgb, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const uint32_t colors_top[] = {
+		MAKE_RGBA30(rgb, 768, 768, 768, 255),	/* grey */
+		MAKE_RGBA30(rgb, 768, 768, 0, 255),	/* yellow */
+		MAKE_RGBA30(rgb, 0, 768, 768, 255),	/* cyan */
+		MAKE_RGBA30(rgb, 0, 768, 0, 255),	/* green */
+		MAKE_RGBA30(rgb, 768, 0, 768, 255),	/* magenta */
+		MAKE_RGBA30(rgb, 768, 0, 0, 255),	/* red */
+		MAKE_RGBA30(rgb, 0, 0, 768, 255),	/* blue */
+	};
+	const uint32_t colors_middle[] = {
+		MAKE_RGBA30(rgb, 0, 0, 768, 127),	/* blue */
+		MAKE_RGBA30(rgb, 76, 76, 76, 127),	/* black */
+		MAKE_RGBA30(rgb, 768, 0, 768, 127),	/* magenta */
+		MAKE_RGBA30(rgb, 76, 76, 76, 127),	/* black */
+		MAKE_RGBA30(rgb, 0, 768, 768, 127),	/* cyan */
+		MAKE_RGBA30(rgb, 76, 76, 76, 127),	/* black */
+		MAKE_RGBA30(rgb, 768, 768, 768, 127),	/* grey */
+	};
+	const uint32_t colors_bottom[] = {
+		MAKE_RGBA30(rgb, 0, 132, 304, 255),	/* in-phase */
+		MAKE_RGBA30(rgb, 1020, 1020, 1020, 255),/* super white */
+		MAKE_RGBA30(rgb, 200, 0, 424, 255),	/* quadrature */
+		MAKE_RGBA30(rgb, 76, 76, 76, 255),	/* black */
+		MAKE_RGBA30(rgb, 36, 36, 36, 255),	/* 3.5% */
+		MAKE_RGBA30(rgb, 76, 76, 76, 255),	/* 7.5% */
+		MAKE_RGBA30(rgb, 116, 116, 116, 255),	/* 11.5% */
+		MAKE_RGBA30(rgb, 76, 76, 76, 255),	/* black */
+	};
+	unsigned int x;
+	unsigned int y;
+
+	for (y = 0; y < height * 6 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_top[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height * 7 / 9; ++y) {
+		for (x = 0; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
+		mem += stride;
+	}
+
+	for (; y < height; ++y) {
+		for (x = 0; x < width * 5 / 7; ++x)
+			((uint32_t *)mem)[x] =
+				colors_bottom[x * 4 / (width * 5 / 7)];
+		for (; x < width * 6 / 7; ++x)
+			((uint32_t *)mem)[x] =
+				colors_bottom[(x - width * 5 / 7) * 3
+					      / (width / 7) + 4];
+		for (; x < width; ++x)
+			((uint32_t *)mem)[x] = colors_bottom[7];
+		mem += stride;
+	}
+}
+
 static void fill_smpte(const struct util_format_info *info, void *planes[3],
 		       unsigned int width, unsigned int height,
 		       unsigned int stride)
@@ -525,6 +592,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
 	case DRM_FORMAT_RGBX8888:
 	case DRM_FORMAT_BGRA8888:
 	case DRM_FORMAT_BGRX8888:
+		return fill_smpte_rgb32(&info->rgb, planes[0],
+					width, height, stride);
 	case DRM_FORMAT_ARGB2101010:
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_ABGR2101010:
@@ -533,7 +602,7 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3],
 	case DRM_FORMAT_RGBX1010102:
 	case DRM_FORMAT_BGRA1010102:
 	case DRM_FORMAT_BGRX1010102:
-		return fill_smpte_rgb32(&info->rgb, planes[0],
+		return fill_smpte_rgb30(&info->rgb, planes[0],
 					width, height, stride);
 	}
 }
@@ -747,6 +816,33 @@ static void fill_tiles_rgb32(const struct util_format_info *info, void *mem,
 	make_pwetty(mem_base, width, height, stride, info->format);
 }
 
+static void fill_tiles_rgb30(const struct util_format_info *info, void *mem,
+			     unsigned int width, unsigned int height,
+			     unsigned int stride)
+{
+	const struct util_rgb_info *rgb = &info->rgb;
+	void *mem_base = mem;
+	unsigned int x, y;
+
+	for (y = 0; y < height; ++y) {
+		for (x = 0; x < width; ++x) {
+			div_t d = div(x+y, width);
+			uint32_t rgb32 = 0x004c1408 * (d.quot >> 6)
+				       + 0x00284480 * (d.rem >> 6);
+			uint32_t alpha = ((y < height/2) && (x < width/2)) ? 127 : 255;
+			uint32_t color =
+				MAKE_RGBA30(rgb, (rgb32 >> 16) & 0x3ff,
+					    (rgb32 >> 8) & 0x3ff, rgb32 & 0x3ff,
+					    alpha);
+
+			((uint32_t *)mem)[x] = color;
+		}
+		mem += stride;
+	}
+
+	make_pwetty(mem_base, width, height, stride, info->format);
+}
+
 static void fill_tiles(const struct util_format_info *info, void *planes[3],
 		       unsigned int width, unsigned int height,
 		       unsigned int stride)
@@ -811,6 +907,8 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
 	case DRM_FORMAT_RGBX8888:
 	case DRM_FORMAT_BGRA8888:
 	case DRM_FORMAT_BGRX8888:
+		return fill_tiles_rgb32(info, planes[0],
+					width, height, stride);
 	case DRM_FORMAT_ARGB2101010:
 	case DRM_FORMAT_XRGB2101010:
 	case DRM_FORMAT_ABGR2101010:
@@ -819,7 +917,7 @@ static void fill_tiles(const struct util_format_info *info, void *planes[3],
 	case DRM_FORMAT_RGBX1010102:
 	case DRM_FORMAT_BGRA1010102:
 	case DRM_FORMAT_BGRX1010102:
-		return fill_tiles_rgb32(info, planes[0],
+		return fill_tiles_rgb30(info, planes[0],
 					width, height, stride);
 	}
 }
-- 
2.11.0

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux