diff options
author | Ilia Mirkin <imirkin@alum.mit.edu> | 2019-06-02 17:51:08 -0400 |
---|---|---|
committer | Ilia Mirkin <imirkin@alum.mit.edu> | 2019-06-22 13:29:54 -0400 |
commit | 8d27deced945374813e11e32630bef8bb3d41529 (patch) | |
tree | 2e0c82d8410fbf97eda25e2e8ec4b03eb0fef22a | |
parent | 0eaf5df5535e2d7125cf6d8eae04058b2dd2d294 (diff) | |
download | libdrm-8d27deced945374813e11e32630bef8bb3d41529.tar.gz libdrm-8d27deced945374813e11e32630bef8bb3d41529.tar.bz2 libdrm-8d27deced945374813e11e32630bef8bb3d41529.zip |
util: add C8 format, support it with SMPTE pattern
This also adds a helper to generate a color LUT, which has to be used in
conjunction with the C8 indexed format.
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Acked-by: Emil Velikov <emil.velikov@collabora.com>
-rw-r--r-- | tests/util/format.c | 2 | ||||
-rw-r--r-- | tests/util/pattern.c | 75 | ||||
-rw-r--r-- | tests/util/pattern.h | 4 |
3 files changed, 81 insertions, 0 deletions
diff --git a/tests/util/format.c b/tests/util/format.c index 15ac5e1e..e52213bb 100644 --- a/tests/util/format.c +++ b/tests/util/format.c @@ -39,6 +39,8 @@ .yuv = { (order), (xsub), (ysub), (chroma_stride) } static const struct util_format_info format_info[] = { + /* Indexed */ + { DRM_FORMAT_C8, "C8" }, /* YUV packed */ { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) }, { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) }, diff --git a/tests/util/pattern.c b/tests/util/pattern.c index 9fa0a417..c84fee5a 100644 --- a/tests/util/pattern.c +++ b/tests/util/pattern.c @@ -457,6 +457,79 @@ static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem, } } +static void fill_smpte_c8(void *mem, unsigned int width, unsigned int height, + unsigned int stride) +{ + unsigned int x; + unsigned int y; + + for (y = 0; y < height * 6 / 9; ++y) { + for (x = 0; x < width; ++x) + ((uint8_t *)mem)[x] = x * 7 / width; + mem += stride; + } + + for (; y < height * 7 / 9; ++y) { + for (x = 0; x < width; ++x) + ((uint8_t *)mem)[x] = 7 + (x * 7 / width); + mem += stride; + } + + for (; y < height; ++y) { + for (x = 0; x < width * 5 / 7; ++x) + ((uint8_t *)mem)[x] = + 14 + (x * 4 / (width * 5 / 7)); + for (; x < width * 6 / 7; ++x) + ((uint8_t *)mem)[x] = + 14 + ((x - width * 5 / 7) * 3 + / (width / 7) + 4); + for (; x < width; ++x) + ((uint8_t *)mem)[x] = 14 + 7; + mem += stride; + } +} + +void util_smpte_c8_gamma(unsigned size, struct drm_color_lut *lut) +{ + if (size < 7 + 7 + 8) { + printf("Error: gamma too small: %d < %d\n", size, 7 + 7 + 8); + return; + } + memset(lut, size * sizeof(struct drm_color_lut), 0); + +#define FILL_COLOR(idx, r, g, b) \ + lut[idx].red = (r) << 8; \ + lut[idx].green = (g) << 8; \ + lut[idx].blue = (b) << 8 + + FILL_COLOR( 0, 192, 192, 192); /* grey */ + FILL_COLOR( 1, 192, 192, 0 ); /* yellow */ + FILL_COLOR( 2, 0, 192, 192); /* cyan */ + FILL_COLOR( 3, 0, 192, 0 ); /* green */ + FILL_COLOR( 4, 192, 0, 192); /* magenta */ + FILL_COLOR( 5, 192, 0, 0 ); /* red */ + FILL_COLOR( 6, 0, 0, 192); /* blue */ + + FILL_COLOR( 7, 0, 0, 192); /* blue */ + FILL_COLOR( 8, 19, 19, 19 ); /* black */ + FILL_COLOR( 9, 192, 0, 192); /* magenta */ + FILL_COLOR(10, 19, 19, 19 ); /* black */ + FILL_COLOR(11, 0, 192, 192); /* cyan */ + FILL_COLOR(12, 19, 19, 19 ); /* black */ + FILL_COLOR(13, 192, 192, 192); /* grey */ + + FILL_COLOR(14, 0, 33, 76); /* in-phase */ + FILL_COLOR(15, 255, 255, 255); /* super white */ + FILL_COLOR(16, 50, 0, 106); /* quadrature */ + FILL_COLOR(17, 19, 19, 19); /* black */ + FILL_COLOR(18, 9, 9, 9); /* 3.5% */ + FILL_COLOR(19, 19, 19, 19); /* 7.5% */ + FILL_COLOR(20, 29, 29, 29); /* 11.5% */ + FILL_COLOR(21, 19, 19, 19); /* black */ + +#undef FILL_COLOR +} + static void fill_smpte(const struct util_format_info *info, void *planes[3], unsigned int width, unsigned int height, unsigned int stride) @@ -464,6 +537,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3], unsigned char *u, *v; switch (info->format) { + case DRM_FORMAT_C8: + return fill_smpte_c8(planes[0], width, height, stride); case DRM_FORMAT_UYVY: case DRM_FORMAT_VYUY: case DRM_FORMAT_YUYV: diff --git a/tests/util/pattern.h b/tests/util/pattern.h index d5c4260c..c8708d02 100644 --- a/tests/util/pattern.h +++ b/tests/util/pattern.h @@ -26,6 +26,8 @@ #ifndef UTIL_PATTERN_H #define UTIL_PATTERN_H +#include <drm/drm_mode.h> + enum util_fill_pattern { UTIL_PATTERN_TILES, UTIL_PATTERN_PLAIN, @@ -36,4 +38,6 @@ void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, void *planes[3], unsigned int width, unsigned int height, unsigned int stride); +void util_smpte_c8_gamma(unsigned size, struct drm_color_lut *lut); + #endif /* UTIL_PATTERN_H */ |