summaryrefslogtreecommitdiff
path: root/kms++/src
diff options
context:
space:
mode:
Diffstat (limited to 'kms++/src')
-rw-r--r--kms++/src/pixelformats.cpp24
-rw-r--r--kms++/src/plane.cpp6
2 files changed, 29 insertions, 1 deletions
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)
{
diff --git a/kms++/src/plane.cpp b/kms++/src/plane.cpp
index 93b3479..7a4f26d 100644
--- a/kms++/src/plane.cpp
+++ b/kms++/src/plane.cpp
@@ -96,7 +96,11 @@ vector<PixelFormat> Plane::get_formats() const
vector<PixelFormat> r;
for (unsigned i = 0; i < p->count_formats; ++i)
- r.push_back(fourcc_to_pixel_format(p->formats[i]));
+ try {
+ r.push_back(fourcc_to_pixel_format(p->formats[i]));
+ } catch (const std::invalid_argument&) {
+ // skip formats that are not supported
+ }
return r;
}