From 626edbe2fc845803ffdd25936e21202e4f123b63 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 9 Apr 2019 10:20:15 +0300 Subject: add support for more pixel formats Signed-off-by: Tomi Valkeinen --- kms++util/src/testpat.cpp | 68 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'kms++util/src/testpat.cpp') diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp index ab197dc..f9a3c8a 100644 --- a/kms++util/src/testpat.cpp +++ b/kms++util/src/testpat.cpp @@ -105,17 +105,10 @@ static void draw_test_pattern_part(IFramebuffer& fb, unsigned start_y, unsigned unsigned x, y; unsigned w = fb.width(); - switch (fb.format()) { - case PixelFormat::XRGB8888: - case PixelFormat::XBGR8888: - case PixelFormat::ARGB8888: - case PixelFormat::ABGR8888: - case PixelFormat::RGB888: - case PixelFormat::BGR888: - case PixelFormat::RGB565: - case PixelFormat::BGR565: - case PixelFormat::ARGB4444: - case PixelFormat::ARGB1555: + const PixelFormatInfo& format_info = get_pixel_format_info(fb.format()); + + switch (format_info.type) { + case PixelColorType::RGB: for (y = start_y; y < end_y; y++) { for (x = 0; x < w; x++) { RGB pixel = get_test_pattern_pixel(fb, x, y); @@ -124,35 +117,40 @@ static void draw_test_pattern_part(IFramebuffer& fb, unsigned start_y, unsigned } break; - case PixelFormat::UYVY: - case PixelFormat::YUYV: - case PixelFormat::YVYU: - case PixelFormat::VYUY: - for (y = start_y; y < end_y; y++) { - for (x = 0; x < w; x += 2) { - RGB pixel1 = get_test_pattern_pixel(fb, x, y); - RGB pixel2 = get_test_pattern_pixel(fb, x + 1, y); - draw_yuv422_macropixel(fb, x, y, pixel1.yuv(yuvt), pixel2.yuv(yuvt)); + case PixelColorType::YUV: + switch (format_info.num_planes) { + case 1: + for (y = start_y; y < end_y; y++) { + for (x = 0; x < w; x += 2) { + RGB pixel1 = get_test_pattern_pixel(fb, x, y); + RGB pixel2 = get_test_pattern_pixel(fb, x + 1, y); + draw_yuv422_macropixel(fb, x, y, pixel1.yuv(yuvt), pixel2.yuv(yuvt)); + } } - } - break; - - case PixelFormat::NV12: - case PixelFormat::NV21: - for (y = start_y; y < end_y; y += 2) { - for (x = 0; x < w; x += 2) { - RGB pixel00 = get_test_pattern_pixel(fb, x, y); - RGB pixel10 = get_test_pattern_pixel(fb, x + 1, y); - RGB pixel01 = get_test_pattern_pixel(fb, x, y + 1); - RGB pixel11 = get_test_pattern_pixel(fb, x + 1, y + 1); - draw_yuv420_macropixel(fb, x, y, - pixel00.yuv(yuvt), pixel10.yuv(yuvt), - pixel01.yuv(yuvt), pixel11.yuv(yuvt)); + break; + + case 2: + for (y = start_y; y < end_y; y += 2) { + for (x = 0; x < w; x += 2) { + RGB pixel00 = get_test_pattern_pixel(fb, x, y); + RGB pixel10 = get_test_pattern_pixel(fb, x + 1, y); + RGB pixel01 = get_test_pattern_pixel(fb, x, y + 1); + RGB pixel11 = get_test_pattern_pixel(fb, x + 1, y + 1); + draw_yuv420_macropixel(fb, x, y, + pixel00.yuv(yuvt), pixel10.yuv(yuvt), + pixel01.yuv(yuvt), pixel11.yuv(yuvt)); + } } + break; + + default: + throw invalid_argument("unsupported number of pixel format planes"); } + break; + default: - throw std::invalid_argument("unknown pixelformat"); + throw invalid_argument("unsupported pixel format"); } } -- cgit v1.2.3