From d08ecb56e9779d5190bc6423a1cad596756881ef Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 5 Feb 2025 12:13:36 +0200 Subject: PixelFormats: Switch to non-fourcc PixelFormat enum Signed-off-by: Tomi Valkeinen --- kms++/src/pixelformats.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'kms++/src/pixelformats.cpp') diff --git a/kms++/src/pixelformats.cpp b/kms++/src/pixelformats.cpp index 8e3a120..cdd742c 100644 --- a/kms++/src/pixelformats.cpp +++ b/kms++/src/pixelformats.cpp @@ -235,6 +235,30 @@ const struct PixelFormatInfo& get_pixel_format_info(PixelFormat format) return format_info_array.at(format); } +PixelFormat fourcc_to_pixel_format(uint32_t fourcc) +{ + for (const auto& [fmt, pfi] : format_info_array) { + if (pfi.drm_fourcc == fourcc) + return fmt; + } + + throw invalid_argument("FourCC not supported"); +} + +uint32_t pixel_format_to_fourcc(PixelFormat f) +{ + return format_info_array.at(f).drm_fourcc; +} + +PixelFormat fourcc_str_to_pixel_format(const std::string& fourcc) +{ + return fourcc_to_pixel_format(str_to_fourcc(fourcc)); +} + +std::string pixel_format_to_fourcc_str(PixelFormat f) +{ + return fourcc_to_str(format_info_array.at(f).drm_fourcc); +} static constexpr uint32_t _div_round_up(uint32_t a, uint32_t b) { -- cgit v1.2.3