summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2025-03-28 11:00:09 +0200
committerTomi Valkeinen <tomi.valkeinen@ideasonboard.com>2025-03-28 11:00:09 +0200
commit9f7fd01b5d5bd064723888d3df1b4964da4946be (patch)
tree05c6ade0ad7c3b48a78aa33a7e09ee2f15beb936
parent9673348fffea7490a85b4a15882e3ec41b62dc29 (diff)
kmstest: Support format names in addition to fourcc
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
-rw-r--r--kms++/inc/kms++/pixelformats.h2
-rw-r--r--kms++/src/pixelformats.cpp10
-rw-r--r--utils/kmstest.cpp13
3 files changed, 21 insertions, 4 deletions
diff --git a/kms++/inc/kms++/pixelformats.h b/kms++/inc/kms++/pixelformats.h
index e866d84..c4dd07f 100644
--- a/kms++/inc/kms++/pixelformats.h
+++ b/kms++/inc/kms++/pixelformats.h
@@ -115,6 +115,8 @@ uint32_t pixel_format_to_fourcc(PixelFormat f);
PixelFormat fourcc_str_to_pixel_format(const std::string& fourcc);
std::string pixel_format_to_fourcc_str(PixelFormat f);
+PixelFormat find_pixel_format_by_name(const std::string& name);
+
enum class PixelColorType {
Undefined,
RGB,
diff --git a/kms++/src/pixelformats.cpp b/kms++/src/pixelformats.cpp
index 559aa38..847c8a6 100644
--- a/kms++/src/pixelformats.cpp
+++ b/kms++/src/pixelformats.cpp
@@ -992,6 +992,16 @@ std::string pixel_format_to_fourcc_str(PixelFormat f)
return fourcc_to_str(format_info_array.at(f).drm_fourcc);
}
+PixelFormat find_pixel_format_by_name(const std::string& name)
+{
+ for (const auto& [fmt, pfi] : format_info_array) {
+ if (pfi.name == name)
+ return fmt;
+ }
+
+ throw invalid_argument("Unsupported pixelformat");
+}
+
static constexpr uint32_t _div_round_up(uint32_t a, uint32_t b)
{
return (a + b - 1) / b;
diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp
index 0a8ca22..c6cf129 100644
--- a/utils/kmstest.cpp
+++ b/utils/kmstest.cpp
@@ -351,7 +351,7 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane
// 400x400-NV12
const regex fb_re("(?:(\\d+)x(\\d+))?" // 400x400
"(?:-)?" // -
- "(\\w\\w\\w\\w)?"); // NV12
+ "(\\w+)?"); // NV12
smatch sm;
if (!regex_match(fb_str, sm, fb_re))
@@ -361,8 +361,13 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane
w = stoul(sm[1]);
if (sm[2].matched)
h = stoul(sm[2]);
- if (sm[3].matched)
- format = fourcc_str_to_pixel_format(sm[3]);
+ if (sm[3].matched) {
+ try {
+ format = find_pixel_format_by_name(sm[3]);
+ } catch (const invalid_argument& e) {
+ format = fourcc_str_to_pixel_format(sm[3]);
+ }
+ }
}
vector<Framebuffer*> v;
@@ -400,7 +405,7 @@ static const char* usage_str =
" or\n"
" [<crtc>:]<pclk>,<hact>/<hfp>/<hsw>/<hbp>/<hsp>,<vact>/<vfp>/<vsw>/<vbp>/<vsp>[,i]\n"
" -p, --plane=PLANE PLANE is [<plane>:][<x>,<y>-]<w>x<h>\n"
- " -f, --fb=FB FB is [<w>x<h>][-][<4cc>]\n"
+ " -f, --fb=FB FB is [<w>x<h>][-][<fmtname>|<4cc>]\n"
" -v, --view=VIEW VIEW is <x>,<y>-<w>x<h>\n"
" -P, --property=PROP=VAL Set PROP to VAL in the previous DRM object\n"
" --dmt Search for the given mode from DMT tables\n"