From 8353d25b01b31c2c3d50bb58e504370ac1fce320 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 9 May 2011 09:09:04 +0200 Subject: Add support for user-selectable test patterns The only currently supported test pattern is the SMPTE color bars. Signed-off-by: Laurent Pinchart --- fbdev.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/fbdev.c b/fbdev.c index f8069e8..e1e1495 100644 --- a/fbdev.c +++ b/fbdev.c @@ -50,6 +50,10 @@ enum fb_fill_mode { FB_FILL_VIRTUAL = 2, }; +enum fb_fill_pattern { + FB_PATTERN_SMPTE = 0, +}; + /* ----------------------------------------------------------------------------- * FB information display */ @@ -589,8 +593,8 @@ static int fb_pan(struct device *dev, unsigned int x, unsigned int y) (((b) >> (8 - (var)->blue.length)) << (var)->blue.offset)) static void -fb_fill_rgb16(struct device *dev, unsigned int xoffset, unsigned int yoffset, - unsigned int xres, unsigned int yres) +fb_fill_smpte_rgb16(struct device *dev, unsigned int xoffset, + unsigned int yoffset, unsigned int xres, unsigned int yres) { const uint16_t colors_top[] = { FB_MAKE_COLOR(&dev->var_info, 192, 192, 192), /* grey */ @@ -659,8 +663,8 @@ struct fb_color24 { { .value = FB_MAKE_COLOR(var, r, g, b) } static void -fb_fill_rgb24(struct device *dev, unsigned int xoffset, unsigned int yoffset, - unsigned int xres, unsigned int yres) +fb_fill_smpte_rgb24(struct device *dev, unsigned int xoffset, + unsigned int yoffset, unsigned int xres, unsigned int yres) { const struct fb_color24 colors_top[] = { FB_MAKE_COLOR24(&dev->var_info, 192, 192, 192), /* grey */ @@ -724,8 +728,8 @@ fb_fill_rgb24(struct device *dev, unsigned int xoffset, unsigned int yoffset, } static void -fb_fill_rgb32(struct device *dev, unsigned int xoffset, unsigned int yoffset, - unsigned int xres, unsigned int yres) +fb_fill_smpte_rgb32(struct device *dev, unsigned int xoffset, + unsigned int yoffset, unsigned int xres, unsigned int yres) { const uint32_t colors_top[] = { FB_MAKE_COLOR(&dev->var_info, 192, 192, 192), /* grey */ @@ -787,15 +791,42 @@ fb_fill_rgb32(struct device *dev, unsigned int xoffset, unsigned int yoffset, } /* - * fb_fill - Fill the frame buffer with an SMPTE test pattern + * fb_fill_smpte - Fill the frame buffer with an SMPTE test pattern + * @dev: FB device + * @xoffset: Horizontal offset, in pixels + * @yoffset: Vertical offset, in pixels + * @xres: Horizontal size, in pixels + * @yres: Vertical size, in pixels + * + * Fill the display (when mode is FB_FILL_DISPLAY) or virtual frame buffer area + * (when mode is FB_FILL_VIRTUAL) with an SMPTE color bars pattern. + */ +static void +fb_fill_smpte(struct device *dev, unsigned int xoffset, unsigned int yoffset, + unsigned int xres, unsigned int yres) +{ + switch (dev->var_info.bits_per_pixel) { + case 16: + return fb_fill_smpte_rgb16(dev, xoffset, yoffset, xres, yres); + case 24: + return fb_fill_smpte_rgb24(dev, xoffset, yoffset, xres, yres); + case 32: + return fb_fill_smpte_rgb32(dev, xoffset, yoffset, xres, yres); + } +} + +/* + * fb_fill - Fill the frame buffer with a test pattern * @dev: FB device * @mode: Fill mode + * @pattern: Test pattern * * Fill the display (when mode is FB_FILL_DISPLAY) or virtual frame buffer area - * (when mode is FB_FILL_VIRTUAL) with an SMPTE color bars pattern. Only RGB16, - * RGB24 and RGB32 on true color visuals are supported. + * (when mode is FB_FILL_VIRTUAL) with the test pattern specified by the pattern + * parameter. Only RGB16, RGB24 and RGB32 on true color visuals are supported. */ -static void fb_fill(struct device *dev, enum fb_fill_mode mode) +static void +fb_fill(struct device *dev, enum fb_fill_mode mode, enum fb_fill_pattern pattern) { unsigned int xoffset, yoffset; unsigned int xres, yres; @@ -806,7 +837,13 @@ static void fb_fill(struct device *dev, enum fb_fill_mode mode) return; } - printf("Filling frame buffer with SMPTE test pattern\n"); + if (dev->var_info.bits_per_pixel != 16 && + dev->var_info.bits_per_pixel != 24 && + dev->var_info.bits_per_pixel != 32) { + printf("Error: display depth %u bpp not supported.\n", + dev->var_info.bits_per_pixel); + return; + } if (mode == FB_FILL_DISPLAY) { xoffset = dev->var_info.xoffset; @@ -820,16 +857,13 @@ static void fb_fill(struct device *dev, enum fb_fill_mode mode) yres = dev->var_info.yres_virtual; } - switch (dev->var_info.bits_per_pixel) { - case 16: - return fb_fill_rgb16(dev, xoffset, yoffset, xres, yres); - case 24: - return fb_fill_rgb24(dev, xoffset, yoffset, xres, yres); - case 32: - return fb_fill_rgb32(dev, xoffset, yoffset, xres, yres); + switch (pattern) { + case FB_PATTERN_SMPTE: + printf("Filling frame buffer with SMPTE test pattern\n"); + return fb_fill_smpte(dev, xoffset, yoffset, xres, yres); + default: - printf("Error: display depth %u bpp not supported.\n", - dev->var_info.bits_per_pixel); + printf("Error: unsupported test pattern %u.\n", pattern); break; } } @@ -847,13 +881,16 @@ static void usage(const char *argv0) printf("-F, --format bpp Set the number of bits per pixel\n"); printf("-h, --help Show this help screen\n"); printf("-p, --pan x,y Pan the display to position (x,y)\n"); + printf("-P, --pattern name Test pattern name\n"); printf("-r, --resolution wxh Set the display resolution to width x height\n"); printf("-v, --virtual wxh Set the display virtual resolution to width x height\n"); printf("-w, --wait-vsync[=screen] Wait for VSync on the given screen\n"); printf("\n"); printf("Support fill modes are:\n"); - printf("display Fill the displayed frame buffer only\n"); - printf("virtual Fill the whole virtual frame buffer\n"); + printf(" display Fill the displayed frame buffer only\n"); + printf(" virtual Fill the whole virtual frame buffer\n"); + printf("Support test pattern are:\n"); + printf(" smpte SMPTE color bars\n"); printf("Supported blanking modes are:\n"); printf(" off Blanking off, screen active\n"); printf(" on Blanked, HSync on, VSync on\n"); @@ -868,6 +905,7 @@ static struct option opts[] = { {"format", 1, 0, 'F'}, {"help", 0, 0, 'h'}, {"pan", 1, 0, 'p'}, + {"pattern", 1, 0, 'P'}, {"resolution", 1, 0, 'r'}, {"virtual", 1, 0, 'v'}, {"wait-vsync", 2, 0, 'w'}, @@ -943,6 +981,7 @@ int main(int argc, char *argv[]) int blank = 0; enum fb_fill_mode fill_mode = FB_FILL_NONE; + enum fb_fill_pattern fill_pattern = FB_PATTERN_SMPTE; bool do_format = false; unsigned int bpp = 0; @@ -963,7 +1002,7 @@ int main(int argc, char *argv[]) int c; opterr = 0; - while ((c = getopt_long(argc, argv, "b:f::F:hp:r:v:w::", opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "b:f::F:hp:P:r:v:w::", opts, NULL)) != -1) { switch (c) { case 'b': @@ -1002,6 +1041,15 @@ int main(int argc, char *argv[]) return 1; } break; + case 'P': + if (strcmp(optarg, "smpte") == 0) + fill_pattern = FB_PATTERN_SMPTE; + else { + printf("Invalid test pattern `%s'\n", optarg); + printf("Run %s -h for help.\n", argv[0]); + return 1; + } + break; case 'r': do_resolution = true; if (fb_size_parse(optarg, &xres, &yres) < 0) { @@ -1049,7 +1097,7 @@ int main(int argc, char *argv[]) fb_set_resolution(&dev, xres, yres, xres_virtual, yres_virtual); if (fill_mode != FB_FILL_NONE) - fb_fill(&dev, fill_mode); + fb_fill(&dev, fill_mode, fill_pattern); if (do_pan) fb_pan(&dev, pan_x, pan_y); -- cgit v1.2.3