diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2019-04-09 10:20:15 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2019-04-09 10:21:47 +0300 |
commit | 626edbe2fc845803ffdd25936e21202e4f123b63 (patch) | |
tree | ca438f77a5f1bdd2057c0769d4886ac9a534ca5b | |
parent | 521a8cdc9f34cc4707731b0640e72615cc89d9cb (diff) |
add support for more pixel formats
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
-rw-r--r-- | kms++/inc/kms++/pixelformats.h | 22 | ||||
-rw-r--r-- | kms++/src/pixelformats.cpp | 50 | ||||
-rw-r--r-- | kms++util/inc/kms++util/color.h | 9 | ||||
-rw-r--r-- | kms++util/src/color.cpp | 30 | ||||
-rw-r--r-- | kms++util/src/drawing.cpp | 46 | ||||
-rw-r--r-- | kms++util/src/testpat.cpp | 68 |
6 files changed, 172 insertions, 53 deletions
diff --git a/kms++/inc/kms++/pixelformats.h b/kms++/inc/kms++/pixelformats.h index 1e273ef..15fee7f 100644 --- a/kms++/inc/kms++/pixelformats.h +++ b/kms++/inc/kms++/pixelformats.h @@ -24,8 +24,13 @@ enum class PixelFormat : uint32_t XRGB8888 = MakeFourCC("XR24"), XBGR8888 = MakeFourCC("XB24"), + RGBX8888 = MakeFourCC("RX24"), + BGRX8888 = MakeFourCC("BX24"), + ARGB8888 = MakeFourCC("AR24"), ABGR8888 = MakeFourCC("AB24"), + RGBA8888 = MakeFourCC("RA24"), + BGRA8888 = MakeFourCC("BA24"), RGB888 = MakeFourCC("RG24"), BGR888 = MakeFourCC("BG24"), @@ -35,6 +40,16 @@ enum class PixelFormat : uint32_t ARGB4444 = MakeFourCC("AR12"), ARGB1555 = MakeFourCC("AR15"), + + XRGB2101010 = MakeFourCC("XR30"), + XBGR2101010 = MakeFourCC("XB30"), + RGBX1010102 = MakeFourCC("RX30"), + BGRX1010102 = MakeFourCC("BX30"), + + ARGB2101010 = MakeFourCC("AR30"), + ABGR2101010 = MakeFourCC("AB30"), + RGBA1010102 = MakeFourCC("RA30"), + BGRA1010102 = MakeFourCC("BA30"), }; static inline PixelFormat FourCCToPixelFormat(const std::string& fourcc) @@ -52,6 +67,12 @@ static inline std::string PixelFormatToFourCC(PixelFormat f) return std::string(buf); } +enum class PixelColorType +{ + RGB, + YUV, +}; + struct PixelFormatPlaneInfo { uint8_t bitspp; @@ -61,6 +82,7 @@ struct PixelFormatPlaneInfo struct PixelFormatInfo { + PixelColorType type; uint8_t num_planes; struct PixelFormatPlaneInfo planes[4]; }; diff --git a/kms++/src/pixelformats.cpp b/kms++/src/pixelformats.cpp index 819853b..ecca41d 100644 --- a/kms++/src/pixelformats.cpp +++ b/kms++/src/pixelformats.cpp @@ -8,31 +8,49 @@ namespace kms { static const map<PixelFormat, PixelFormatInfo> format_info_array = { /* YUV packed */ - { PixelFormat::UYVY, { 1, { { 16, 2, 1 } }, } }, - { PixelFormat::YUYV, { 1, { { 16, 2, 1 } }, } }, - { PixelFormat::YVYU, { 1, { { 16, 2, 1 } }, } }, - { PixelFormat::VYUY, { 1, { { 16, 2, 1 } }, } }, + { PixelFormat::UYVY, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, + { PixelFormat::YUYV, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, + { PixelFormat::YVYU, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, + { PixelFormat::VYUY, { PixelColorType::YUV, 1, { { 16, 2, 1 } }, } }, /* YUV semi-planar */ - { PixelFormat::NV12, { 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, - { PixelFormat::NV21, { 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, + { PixelFormat::NV12, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, + { PixelFormat::NV21, { PixelColorType::YUV, 2, { { 8, 1, 1, }, { 8, 2, 2 } }, } }, /* RGB16 */ - { PixelFormat::RGB565, { 1, { { 16, 1, 1 } }, } }, - { PixelFormat::BGR565, { 1, { { 16, 1, 1 } }, } }, + { PixelFormat::RGB565, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, + { PixelFormat::BGR565, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, /* RGB24 */ - { PixelFormat::RGB888, { 1, { { 24, 1, 1 } }, } }, - { PixelFormat::BGR888, { 1, { { 24, 1, 1 } }, } }, + { PixelFormat::RGB888, { PixelColorType::RGB, 1, { { 24, 1, 1 } }, } }, + { PixelFormat::BGR888, { PixelColorType::RGB, 1, { { 24, 1, 1 } }, } }, /* RGB32 */ - { PixelFormat::XRGB8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::XBGR8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ARGB8888, { 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ABGR8888, { 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XRGB8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XBGR8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::RGBX8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::BGRX8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, - { PixelFormat::ARGB4444, { 1, { { 16, 1, 1 } }, } }, - { PixelFormat::ARGB1555, { 1, { { 16, 1, 1 } }, } }, + { PixelFormat::ARGB8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ABGR8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::RGBA8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::BGRA8888, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + + { PixelFormat::XRGB2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::XBGR2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::RGBX1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::BGRX1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + + { PixelFormat::ARGB2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::ABGR2101010, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::RGBA1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + { PixelFormat::BGRA1010102, { PixelColorType::RGB, 1, { { 32, 1, 1 } }, } }, + + { PixelFormat::ARGB4444, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, + { PixelFormat::ARGB1555, { PixelColorType::RGB, 1, { { 16, 1, 1 } }, } }, }; const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format) { + if (!format_info_array.count(format)) + throw invalid_argument("get_pixel_format_info: Unsupported pixelformat"); + return format_info_array.at(format); } diff --git a/kms++util/inc/kms++util/color.h b/kms++util/inc/kms++util/color.h index 21eae66..2bf6e66 100644 --- a/kms++util/inc/kms++util/color.h +++ b/kms++util/inc/kms++util/color.h @@ -25,6 +25,15 @@ struct RGB uint32_t bgr888() const; uint32_t argb8888() const; uint32_t abgr8888() const; + uint32_t rgba8888() const; + uint32_t bgra8888() const; + + // XXX these functions leave the lowest 2 bits zero + uint32_t argb2101010() const; + uint32_t abgr2101010() const; + uint32_t rgba1010102() const; + uint32_t bgra1010102() const; + uint16_t rgb565() const; uint16_t bgr565() const; uint16_t argb4444() const; diff --git a/kms++util/src/color.cpp b/kms++util/src/color.cpp index 2a41502..80e4866 100644 --- a/kms++util/src/color.cpp +++ b/kms++util/src/color.cpp @@ -49,6 +49,36 @@ uint32_t RGB::abgr8888() const return (a << 24) | (b << 16) | (g << 8) | (r << 0); } +uint32_t RGB::rgba8888() const +{ + return (r << 24) | (g << 16) | (b << 8) | (a << 0); +} + +uint32_t RGB::bgra8888() const +{ + return (b << 24) | (g << 16) | (r << 8) | (a << 0); +} + +uint32_t RGB::argb2101010() const +{ + return ((a >> 6) << 30) | (r << 22) | (g << 12) | (b << 2); +} + +uint32_t RGB::abgr2101010() const +{ + return ((a >> 6) << 30) | (b << 22) | (g << 12) | (r << 2); +} + +uint32_t RGB::rgba1010102() const +{ + return (r << 24) | (g << 14) | (b << 4) | (a >> 6); +} + +uint32_t RGB::bgra1010102() const +{ + return (b << 24) | (g << 14) | (r << 4) | (a >> 6); +} + uint16_t RGB::rgb565() const { return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0); diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp index 9da7a77..194daf8 100644 --- a/kms++util/src/drawing.cpp +++ b/kms++util/src/drawing.cpp @@ -28,6 +28,48 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color) *p = color.abgr8888(); break; } + case PixelFormat::RGBX8888: + case PixelFormat::RGBA8888: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.rgba8888(); + break; + } + case PixelFormat::BGRX8888: + case PixelFormat::BGRA8888: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.bgra8888(); + break; + } + case PixelFormat::XRGB2101010: + case PixelFormat::ARGB2101010: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.argb2101010(); + break; + } + case PixelFormat::XBGR2101010: + case PixelFormat::ABGR2101010: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.abgr2101010(); + break; + } + case PixelFormat::RGBX1010102: + case PixelFormat::RGBA1010102: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.rgba1010102(); + break; + } + case PixelFormat::BGRX1010102: + case PixelFormat::BGRA1010102: + { + uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4); + *p = color.bgra1010102(); + break; + } case PixelFormat::RGB888: { uint8_t *p = buf.map(0) + buf.stride(0) * y + x * 3; @@ -210,7 +252,7 @@ void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, } break; default: - throw std::invalid_argument("unknown pixelformat"); + throw std::invalid_argument("draw_rect: unknown pixelformat"); } } @@ -296,7 +338,7 @@ static void draw_char(IFramebuffer& buf, uint32_t xpos, uint32_t ypos, char c, R } break; default: - throw std::invalid_argument("unknown pixelformat"); + throw std::invalid_argument("draw_char: unknown pixelformat"); } } 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"); } } |