summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBenoit Parrot <bparrot@ti.com>2018-10-29 12:18:00 -0500
committerTomi Valkeinen <tomi.valkeinen@iki.fi>2018-11-01 16:43:35 +0200
commitaa92646931042ba6fb8ee2b568e9ec5cd2eee4cb (patch)
tree41c71db56bc2d414b00c99b55656269c038ac4e0 /utils
parent4097a83c68b89a70179244da01db0691a6c7c269 (diff)
wbm2m: Add selection/crop support
Add crop/selection parameter support. Signed-off-by: Benoit Parrot <bparrot@ti.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/wbm2m.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/utils/wbm2m.cpp b/utils/wbm2m.cpp
index e08ffb1..b69bb28 100644
--- a/utils/wbm2m.cpp
+++ b/utils/wbm2m.cpp
@@ -2,6 +2,7 @@
#include <poll.h>
#include <unistd.h>
#include <algorithm>
+#include <regex>
#include <fstream>
#include <map>
#include <system_error>
@@ -19,7 +20,8 @@ using namespace kms;
static const char* usage_str =
"Usage: wbm2m [OPTIONS]\n\n"
"Options:\n"
- " -f, --format=4CC Output format"
+ " -f, --format=4CC Output format\n"
+ " -c, --crop=CROP CROP is <x>,<y>-<w>x<h>\n"
" -h, --help Print this help\n"
;
@@ -45,6 +47,21 @@ static void read_frame(DumbFramebuffer* fb, unsigned frame_num)
s_bar_pos_map[fb] = pos;
}
+static void parse_crop(const string& crop_str, uint32_t& c_left, uint32_t& c_top,
+ uint32_t& c_width, uint32_t& c_height)
+{
+ const regex crop_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400
+
+ smatch sm;
+ if (!regex_match(crop_str, sm, crop_re))
+ EXIT("Failed to parse crop option '%s'", crop_str.c_str());
+
+ c_left = stoul(sm[1]);
+ c_top = stoul(sm[2]);
+ c_width = stoul(sm[3]);
+ c_height = stoul(sm[4]);
+}
+
int main(int argc, char** argv)
{
// XXX get from args
@@ -55,13 +72,21 @@ int main(int argc, char** argv)
const uint32_t dst_width = 800;
const uint32_t dst_height = 480;
+ uint32_t c_top, c_left, c_width, c_height;
+
auto dst_fmt = PixelFormat::XRGB8888;
+ bool use_selection = false;
OptionSet optionset = {
Option("f|format=", [&](string s)
{
dst_fmt = FourCCToPixelFormat(s);
}),
+ Option("c|crop=", [&](string s)
+ {
+ parse_crop(s, c_left, c_top, c_width, c_height);
+ use_selection = true;
+ }),
Option("h|help", [&]()
{
puts(usage_str);
@@ -92,6 +117,11 @@ int main(int argc, char** argv)
out->set_format(src_fmt, src_width, src_height);
in->set_format(dst_fmt, dst_width, dst_height);
+ if (use_selection) {
+ out->set_selection(c_left, c_top, c_width, c_height);
+ printf("crop -> %u,%u-%ux%u\n", c_left, c_top, c_width, c_height);
+ }
+
out->set_queue_size(NUM_SRC_BUFS);
in->set_queue_size(NUM_DST_BUFS);