From aa92646931042ba6fb8ee2b568e9ec5cd2eee4cb Mon Sep 17 00:00:00 2001 From: Benoit Parrot Date: Mon, 29 Oct 2018 12:18:00 -0500 Subject: wbm2m: Add selection/crop support Add crop/selection parameter support. Signed-off-by: Benoit Parrot --- utils/wbm2m.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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 #include #include +#include #include #include #include @@ -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\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); -- cgit v1.2.3