diff options
| -rw-r--r-- | snapshot.c | 46 | 
1 files changed, 44 insertions, 2 deletions
| @@ -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; | 
