From c13258a74fd7345828fce8fab117247e3f61e6e5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 29 Jun 2010 12:09:35 +0200 Subject: V4L2 subdev crop support Extend the V4L2 media bus format syntax to support an optional crop rectangle. If specified, the crop rectangle is set on the subdev pad. Signed-off-by: Laurent Pinchart --- subdev.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'subdev.c') diff --git a/subdev.c b/subdev.c index c35b5b4..ac14324 100644 --- a/subdev.c +++ b/subdev.c @@ -133,3 +133,48 @@ int v4l2_subdev_set_format(struct media_entity *entity, return 0; } +int v4l2_subdev_get_crop(struct media_entity *entity, struct v4l2_rect *rect, + unsigned int pad, enum v4l2_subdev_format which) +{ + struct v4l2_subdev_pad_crop crop; + int ret; + + ret = v4l2_subdev_open(entity); + if (ret < 0) + return ret; + + memset(&crop, 0, sizeof(crop)); + crop.pad = pad; + crop.which = which; + + ret = ioctl(entity->fd, VIDIOC_SUBDEV_G_CROP, &crop); + if (ret < 0) + return -errno; + + *rect = crop.rect; + return 0; +} + +int v4l2_subdev_set_crop(struct media_entity *entity, struct v4l2_rect *rect, + unsigned int pad, enum v4l2_subdev_format which) +{ + struct v4l2_subdev_pad_crop crop; + int ret; + + ret = v4l2_subdev_open(entity); + if (ret < 0) + return ret; + + memset(&crop, 0, sizeof(crop)); + crop.pad = pad; + crop.which = which; + crop.rect = *rect; + + ret = ioctl(entity->fd, VIDIOC_SUBDEV_S_CROP, &crop); + if (ret < 0) + return -errno; + + *rect = crop.rect; + return 0; +} + -- cgit v1.2.3