diff options
| author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-02-05 11:57:52 +0200 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-03-26 15:44:00 +0200 |
| commit | 1936a703bf1a3b27db9bb4d503b861f6d1fa2e74 (patch) | |
| tree | 32cd970cb30f072540b19bfedb4eccb6be590584 | |
| parent | a9e7ecab862183399c5947931f2bad69ecec393d (diff) | |
PixelFormats: clean fourcc management
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
| -rw-r--r-- | kms++/inc/kms++/pixelformats.h | 124 | ||||
| -rw-r--r-- | kms++/src/dmabufframebuffer.cpp | 2 | ||||
| -rw-r--r-- | kms++/src/dumbframebuffer.cpp | 2 | ||||
| -rw-r--r-- | kms++/src/omap/omapframebuffer.cpp | 2 | ||||
| -rw-r--r-- | py/pykms/pykmsbase.cpp | 4 | ||||
| -rw-r--r-- | utils/kmsprint.cpp | 4 | ||||
| -rw-r--r-- | utils/kmstest.cpp | 6 | ||||
| -rw-r--r-- | utils/kmsview.cpp | 2 |
8 files changed, 80 insertions, 66 deletions
diff --git a/kms++/inc/kms++/pixelformats.h b/kms++/inc/kms++/pixelformats.h index 74f69b2..6c58f79 100644 --- a/kms++/inc/kms++/pixelformats.h +++ b/kms++/inc/kms++/pixelformats.h @@ -7,7 +7,7 @@ namespace kms { -constexpr uint32_t MakeFourCC(const std::string& fourcc) +constexpr uint32_t str_to_fourcc(const std::string& fourcc) { if (fourcc.empty()) return 0; @@ -15,80 +15,94 @@ constexpr uint32_t MakeFourCC(const std::string& fourcc) return fourcc[0] | (fourcc[1] << 8) | (fourcc[2] << 16) | (fourcc[3] << 24); } +constexpr std::string fourcc_to_str(uint32_t fourcc) +{ + char buf[4] = { + (char)((fourcc >> 0) & 0xff), + (char)((fourcc >> 8) & 0xff), + (char)((fourcc >> 16) & 0xff), + (char)((fourcc >> 24) & 0xff), + }; + return std::string(buf, 4); +} + enum class PixelFormat : uint32_t { Undefined = 0, - NV12 = MakeFourCC("NV12"), - NV21 = MakeFourCC("NV21"), - NV16 = MakeFourCC("NV16"), - NV61 = MakeFourCC("NV61"), + NV12 = str_to_fourcc("NV12"), + NV21 = str_to_fourcc("NV21"), + NV16 = str_to_fourcc("NV16"), + NV61 = str_to_fourcc("NV61"), - YUV420 = MakeFourCC("YU12"), - YVU420 = MakeFourCC("YV12"), - YUV422 = MakeFourCC("YU16"), - YVU422 = MakeFourCC("YV16"), - YUV444 = MakeFourCC("YU24"), - YVU444 = MakeFourCC("YV24"), + YUV420 = str_to_fourcc("YU12"), + YVU420 = str_to_fourcc("YV12"), + YUV422 = str_to_fourcc("YU16"), + YVU422 = str_to_fourcc("YV16"), + YUV444 = str_to_fourcc("YU24"), + YVU444 = str_to_fourcc("YV24"), - UYVY = MakeFourCC("UYVY"), - YUYV = MakeFourCC("YUYV"), - YVYU = MakeFourCC("YVYU"), - VYUY = MakeFourCC("VYUY"), + UYVY = str_to_fourcc("UYVY"), + YUYV = str_to_fourcc("YUYV"), + YVYU = str_to_fourcc("YVYU"), + VYUY = str_to_fourcc("VYUY"), - Y210 = MakeFourCC("Y210"), - Y212 = MakeFourCC("Y212"), - Y216 = MakeFourCC("Y216"), + Y210 = str_to_fourcc("Y210"), + Y212 = str_to_fourcc("Y212"), + Y216 = str_to_fourcc("Y216"), - XRGB8888 = MakeFourCC("XR24"), - XBGR8888 = MakeFourCC("XB24"), - RGBX8888 = MakeFourCC("RX24"), - BGRX8888 = MakeFourCC("BX24"), + XRGB8888 = str_to_fourcc("XR24"), + XBGR8888 = str_to_fourcc("XB24"), + RGBX8888 = str_to_fourcc("RX24"), + BGRX8888 = str_to_fourcc("BX24"), - ARGB8888 = MakeFourCC("AR24"), - ABGR8888 = MakeFourCC("AB24"), - RGBA8888 = MakeFourCC("RA24"), - BGRA8888 = MakeFourCC("BA24"), + ARGB8888 = str_to_fourcc("AR24"), + ABGR8888 = str_to_fourcc("AB24"), + RGBA8888 = str_to_fourcc("RA24"), + BGRA8888 = str_to_fourcc("BA24"), - RGB888 = MakeFourCC("RG24"), - BGR888 = MakeFourCC("BG24"), + RGB888 = str_to_fourcc("RG24"), + BGR888 = str_to_fourcc("BG24"), - RGB332 = MakeFourCC("RGB8"), + RGB332 = str_to_fourcc("RGB8"), - RGB565 = MakeFourCC("RG16"), - BGR565 = MakeFourCC("BG16"), + RGB565 = str_to_fourcc("RG16"), + BGR565 = str_to_fourcc("BG16"), - XRGB4444 = MakeFourCC("XR12"), - XRGB1555 = MakeFourCC("XR15"), + XRGB4444 = str_to_fourcc("XR12"), + XRGB1555 = str_to_fourcc("XR15"), - ARGB4444 = MakeFourCC("AR12"), - ARGB1555 = MakeFourCC("AR15"), + ARGB4444 = str_to_fourcc("AR12"), + ARGB1555 = str_to_fourcc("AR15"), - XRGB2101010 = MakeFourCC("XR30"), - XBGR2101010 = MakeFourCC("XB30"), - RGBX1010102 = MakeFourCC("RX30"), - BGRX1010102 = MakeFourCC("BX30"), + XRGB2101010 = str_to_fourcc("XR30"), + XBGR2101010 = str_to_fourcc("XB30"), + RGBX1010102 = str_to_fourcc("RX30"), + BGRX1010102 = str_to_fourcc("BX30"), - ARGB2101010 = MakeFourCC("AR30"), - ABGR2101010 = MakeFourCC("AB30"), - RGBA1010102 = MakeFourCC("RA30"), - BGRA1010102 = MakeFourCC("BA30"), + ARGB2101010 = str_to_fourcc("AR30"), + ABGR2101010 = str_to_fourcc("AB30"), + RGBA1010102 = str_to_fourcc("RA30"), + BGRA1010102 = str_to_fourcc("BA30"), }; -inline PixelFormat FourCCToPixelFormat(const std::string& fourcc) +inline PixelFormat fourcc_to_pixel_format(uint32_t fourcc) +{ + return (PixelFormat)fourcc; +} + +inline uint32_t pixel_format_to_fourcc(PixelFormat f) { - return (PixelFormat)MakeFourCC(fourcc.c_str()); + return (uint32_t)f; } -inline std::string PixelFormatToFourCC(PixelFormat f) +inline PixelFormat fourcc_str_to_pixel_format(const std::string& fourcc) { - uint32_t v = (uint32_t)f; + return (PixelFormat)str_to_fourcc(fourcc.c_str()); +} - char buf[4] = { (char)((v >> 0) & 0xff), - (char)((v >> 8) & 0xff), - (char)((v >> 16) & 0xff), - (char)((v >> 24) & 0xff), - }; - return std::string(buf, 4); +inline std::string pixel_format_to_fourcc_str(PixelFormat f) +{ + return fourcc_to_str((uint32_t)f); } enum class PixelColorType { @@ -124,8 +138,8 @@ struct PixelFormatInfo { const std::string& v4l2_4cc, PixelColorType color, std::tuple<uint8_t, uint8_t> pixel_align, std::vector<PixelFormatPlaneInfo> planes) - : name(name), drm_fourcc(kms::MakeFourCC(drm_fourcc)), - v4l2_4cc(kms::MakeFourCC(v4l2_4cc)), type(color), + : name(name), drm_fourcc(kms::str_to_fourcc(drm_fourcc)), + v4l2_4cc(kms::str_to_fourcc(v4l2_4cc)), type(color), pixel_align(pixel_align), num_planes(planes.size()), planes(planes) { } diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index cb76f09..e5d06ed 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -17,7 +17,7 @@ namespace kms { DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height, const string& format, vector<int> fds, vector<uint32_t> pitches, vector<uint32_t> offsets, vector<uint64_t> modifiers) - : DmabufFramebuffer(card, width, height, FourCCToPixelFormat(format), fds, pitches, offsets, modifiers) + : DmabufFramebuffer(card, width, height, fourcc_str_to_pixel_format(format), fds, pitches, offsets, modifiers) { } diff --git a/kms++/src/dumbframebuffer.cpp b/kms++/src/dumbframebuffer.cpp index 28039b6..bdc584e 100644 --- a/kms++/src/dumbframebuffer.cpp +++ b/kms++/src/dumbframebuffer.cpp @@ -20,7 +20,7 @@ using namespace std; namespace kms { DumbFramebuffer::DumbFramebuffer(Card& card, uint32_t width, uint32_t height, const string& fourcc) - : DumbFramebuffer(card, width, height, FourCCToPixelFormat(fourcc)) + : DumbFramebuffer(card, width, height, fourcc_str_to_pixel_format(fourcc)) { } diff --git a/kms++/src/omap/omapframebuffer.cpp b/kms++/src/omap/omapframebuffer.cpp index 2efe1ec..35852bf 100644 --- a/kms++/src/omap/omapframebuffer.cpp +++ b/kms++/src/omap/omapframebuffer.cpp @@ -26,7 +26,7 @@ using namespace std; namespace kms { OmapFramebuffer::OmapFramebuffer(OmapCard& card, uint32_t width, uint32_t height, const string& fourcc, Flags flags) - : OmapFramebuffer(card, width, height, FourCCToPixelFormat(fourcc), flags) + : OmapFramebuffer(card, width, height, fourcc_str_to_pixel_format(fourcc), flags) { } diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp index ae8aebf..8bf0f65 100644 --- a/py/pykms/pykmsbase.cpp +++ b/py/pykms/pykmsbase.cpp @@ -253,8 +253,8 @@ void init_pykmsbase(py::module& m) .value("RGBA1010102", PixelFormat::RGBA1010102) .value("BGRA1010102", PixelFormat::BGRA1010102); - m.def("fourcc_to_pixelformat", &FourCCToPixelFormat); - m.def("pixelformat_to_fourcc", &PixelFormatToFourCC); + m.def("fourcc_to_pixelformat", &fourcc_str_to_pixel_format); + m.def("pixelformat_to_fourcc", &pixel_format_to_fourcc_str); py::enum_<SyncPolarity>(m, "SyncPolarity") .value("Undefined", SyncPolarity::Undefined) diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp index c573c2e..919b50f 100644 --- a/utils/kmsprint.cpp +++ b/utils/kmsprint.cpp @@ -111,7 +111,7 @@ static string format_plane(Plane& p) (uint32_t)p.get_prop_value("CRTC_H")); } - string fmts = join<PixelFormat>(p.get_formats(), " ", [](PixelFormat fmt) { return PixelFormatToFourCC(fmt); }); + string fmts = join<PixelFormat>(p.get_formats(), " ", [](PixelFormat fmt) { return pixel_format_to_fourcc_str(fmt); }); str += fmt::format(" ({})", fmts); @@ -122,7 +122,7 @@ static string format_fb(Framebuffer& fb) { return fmt::format("FB {} {}x{} {}", fb.id(), fb.width(), fb.height(), - PixelFormatToFourCC(fb.format())); + pixel_format_to_fourcc_str(fb.format())); } static string format_property(const Property* prop, uint64_t val) diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index de6957d..7c733da 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp @@ -361,7 +361,7 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane if (sm[2].matched) h = stoul(sm[2]); if (sm[3].matched) - format = FourCCToPixelFormat(sm[3]); + format = fourcc_str_to_pixel_format(sm[3]); } vector<Framebuffer*> v; @@ -747,7 +747,7 @@ static void print_outputs(const vector<OutputInfo>& outputs) if (!o.legacy_fbs.empty()) { auto fb = o.legacy_fbs[0]; - fmt::print(" Fb {} {}x{}-{}\n", fb->id(), fb->width(), fb->height(), PixelFormatToFourCC(fb->format())); + fmt::print(" Fb {} {}x{}-{}\n", fb->id(), fb->width(), fb->height(), pixel_format_to_fourcc_str(fb->format())); } for (unsigned j = 0; j < o.planes.size(); ++j) { @@ -760,7 +760,7 @@ static void print_outputs(const vector<OutputInfo>& outputs) fmt::print("\n"); fmt::print(" Fb {} {}x{}-{}\n", fb->id(), fb->width(), fb->height(), - PixelFormatToFourCC(fb->format())); + pixel_format_to_fourcc_str(fb->format())); if (s_print_crc) fmt::print(" CRC16 {}\n", fb_crc(fb).c_str()); } diff --git a/utils/kmsview.cpp b/utils/kmsview.cpp index c2654b0..437d3a6 100644 --- a/utils/kmsview.cpp +++ b/utils/kmsview.cpp @@ -71,7 +71,7 @@ int main(int argc, char** argv) uint32_t h = stoi(params[2]); string modestr = params[3]; - auto pixfmt = FourCCToPixelFormat(modestr); + auto pixfmt = fourcc_str_to_pixel_format(modestr); ifstream is(filename, ifstream::binary); |
