summaryrefslogtreecommitdiff
path: root/snapshot.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-02-28 15:40:19 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-04-16 23:50:06 +0200
commit8dfa847f666396f7fdfe3f9b6518ed3917003e7f (patch)
treecb65d5cc8dd68eb749dcd1d0d72881f1f8108d71 /snapshot.c
parent1941a76b7e0ea7f2e25d5c54717a05d0ebb7ed1c (diff)
snapshot: Add -c/--crop argument to specify crop rectangle
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'snapshot.c')
-rw-r--r--snapshot.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/snapshot.c b/snapshot.c
index 10e1c15..1ca2169 100644
--- a/snapshot.c
+++ b/snapshot.c
@@ -198,10 +198,42 @@ static unsigned int parse_format(const char *name)
return 0;
}
+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("-c, --crop (x,y)/wxh Set the snapshot capture crop\n");
printf("-f, --format fmt Snapshot format\n");
printf("-h, --help Show this help screen\n");
printf("-i, --interval n Capture a snapshot every n frames\n");
@@ -209,6 +241,7 @@ static void usage(const char *argv0)
}
static struct option opts[] = {
+ { "crop", 1, 0, 'c' },
{ "format", 1, 0, 'f' },
{ "help", 0, 0, 'h' },
{ "interval", 1, 0, 'i' },
@@ -221,17 +254,26 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
enum v4l2_mbus_pixelcode snap_code = V4L2_MBUS_FMT_SGRBG10_1X10;
struct v4l2_mbus_framefmt view_format;
struct v4l2_mbus_framefmt snap_format;
+ struct v4l2_rect snap_crop;
struct v4l2_buffers_pool *pool = NULL;
struct omap3_isp_device *isp = NULL;
struct omap3_isp_operations ops;
struct timespec start, end;
int exit_code = EXIT_FAILURE;
+ bool do_crop = false;
float fps;
int ret;
int c;
- while ((c = getopt_long(argc, argv, "f:hi:S", opts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "c:f:hi:S", opts, NULL)) != -1) {
switch (c) {
+ case 'c':
+ if (parse_crop(optarg, &snap_crop)) {
+ printf("invalid crop rectangle %s.\n", optarg);
+ return 1;
+ }
+ do_crop = true;
+ break;
case 'f':
snap_code = parse_format(optarg);
if (snap_code == 0) {
@@ -299,7 +341,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
snap_format.width = SNAPSHOT_WIDTH;
snap_format.height = SNAPSHOT_HEIGHT;
- ret = omap3_isp_snapshot_setup(isp, NULL, &snap_format);
+ ret = omap3_isp_snapshot_setup(isp, do_crop ? &snap_crop : NULL, &snap_format);
if (ret < 0) {
printf("error: unable to setup pipeline\n");
goto cleanup;