From 73897e4f1125629566a7cef0ecbaf0015d22ec75 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 20 Mar 2014 00:15:42 +0100 Subject: live: Add crop support Signed-off-by: Laurent Pinchart --- live.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/live.c b/live.c index d1785da..6d53b46 100644 --- a/live.c +++ b/live.c @@ -289,7 +289,8 @@ static struct omap3_isp_operations isp_ops = { }; static int viewfinder_init(struct omap3_isp_device *isp, - const struct v4l2_rect *rect) + const struct v4l2_rect *rect, + struct v4l2_rect *crop) { struct v4l2_mbus_framefmt view_format; struct v4l2_buffers_pool *pool; @@ -300,7 +301,7 @@ static int viewfinder_init(struct omap3_isp_device *isp, view_format.width = rect->width; view_format.height = rect->height; - ret = omap3_isp_viewfinder_setup(isp, NULL, &view_format); + ret = omap3_isp_viewfinder_setup(isp, crop, &view_format); if (ret < 0) { printf("error: unable to setup viewfinder\n"); return ret; @@ -761,11 +762,43 @@ static void sigint_handler(int signal __attribute__((__unused__))) events_stop(&events); } +static int parse_crop(const char *p, struct v4l2_rect *crop) +{ + char *end; + + if (*p++ != '(') + return -EINVAL; + + crop->left = strtoul(p, &end, 10); + if (*end != ',') + return -EINVAL; + + p = end + 1; + crop->top = strtoul(p, &end, 10); + if (*end++ != ')') + return -EINVAL; + if (*end != '/') + return -EINVAL; + + p = end + 1; + crop->width = strtoul(p, &end, 10); + if (*end != 'x') + return -EINVAL; + + p = end + 1; + crop->height = strtoul(p, &end, 10); + if (*end != '\0') + return -EINVAL; + + return 0; +} + static void usage(const char *argv0) { printf("Usage: %s [options]\n", argv0); printf("Supported options:\n"); printf("-b, --buffers n Use n display buffers\n"); + printf("-c, --crop (x,y)/wxh Set the sensor crop rectangle\n"); printf("-h, --help Show this help screen\n"); printf("-s, --skip n Skip display of n frames out of n+1\n"); printf(" --aewb param=value Set AEWB algorithm parameter 'param' to 'value'\n"); @@ -793,6 +826,7 @@ static void usage(const char *argv0) static struct option opts[] = { { "aewb", 1, 0, OPT_AEWB_PARAM }, + { "crop", 1, 0, 'c' }, { "disable-aewb", 0, 0, OPT_AEWB_DISABLE }, { "help", 0, 0, 'h' }, { "saturation", 1, 0, OPT_SATURATION }, @@ -806,22 +840,31 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu struct timespec start, end; struct iq_params iq_params; unsigned int buffers = 3; + struct v4l2_rect crop; struct v4l2_rect rect; int exit_code = EXIT_FAILURE; const char *vo_devname; unsigned int colorkey; bool enable_aewb = true; + bool enable_crop = false; float fps; int ret; int c; iq_params_init(&iq_params); - while ((c = getopt_long(argc, argv, "b:hs:z", opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "b:c:hs:z", opts, NULL)) != -1) { switch (c) { case 'b': buffers = atoi(optarg); break; + case 'c': + if (parse_crop(optarg, &crop)) { + printf("invalid crop rectangle %s.\n", optarg); + return 1; + } + enable_crop = true; + break; case 'h': usage(argv[0]); return 0; @@ -894,7 +937,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu goto cleanup; } - ret = viewfinder_init(isp, &rect); + ret = viewfinder_init(isp, &rect, enable_crop ? &crop : NULL); if (ret < 0) goto cleanup; -- cgit v1.2.3