[{"id":3608,"web_url":"https://patchwork.libcamera.org/comment/3608/","msgid":"<20200203225156.qbwzdz7rklj2lzbq@uno.localdomain>","date":"2020-02-03T22:51:56","subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_videodevice: Add\n\tcrop/selection control.","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Naushir,\n\nOn Mon, Feb 03, 2020 at 04:58:51PM +0000, Naushir Patuck wrote:\n> Add control for cropping/selection on a V4L2 video device through\n> the VIDIOC_S_SELECTION ioctl. This is similar to the existing cropping\n> control available on V4L2 sub-devices.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/libcamera/include/v4l2_videodevice.h |  5 +++\n>  src/libcamera/v4l2_videodevice.cpp       | 48 ++++++++++++++++++++++++\n>  2 files changed, 53 insertions(+)\n>\n> diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h\n> index e4d35ab..d8edfde 100644\n> --- a/src/libcamera/include/v4l2_videodevice.h\n> +++ b/src/libcamera/include/v4l2_videodevice.h\n> @@ -182,6 +182,9 @@ public:\n>  \tint setFormat(V4L2DeviceFormat *format);\n>  \tImageFormats formats();\n>\n> +\tint setCrop(Rectangle *rect);\n> +\tint setCompose(Rectangle *rect);\n> +\n>  \tint exportBuffers(unsigned int count,\n>  \t\t\t  std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n>  \tint importBuffers(unsigned int count);\n> @@ -213,6 +216,8 @@ private:\n>  \tint getFormatSingleplane(V4L2DeviceFormat *format);\n>  \tint setFormatSingleplane(V4L2DeviceFormat *format);\n>\n> +\tint setSelection(unsigned int target, Rectangle *rect);\n> +\n>  \tstd::vector<unsigned int> enumPixelformats();\n>  \tstd::vector<SizeRange> enumSizes(unsigned int pixelFormat);\n>\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 8226773..01d9694 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -1499,6 +1499,54 @@ uint32_t V4L2VideoDevice::toV4L2Fourcc(PixelFormat pixelFormat, bool multiplanar\n>  \treturn 0;\n>  }\n>\n> +/**\n> + * \\brief Set a crop rectangle on the V4L2 video device node\n> + * \\param[inout] rect The rectangle describing the crop target area\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::setCrop(Rectangle *rect)\n> +{\n> +\treturn setSelection(V4L2_SEL_TGT_CROP, rect);\n> +}\n> +\n> +/**\n> + * \\brief Set a compose rectangle on the V4L2 video device node\n> + * \\param[inout] rect The rectangle describing the compose target area\n> + * \\return 0 on success or a negative error code otherwise\n> + */\n> +int V4L2VideoDevice::setCompose(Rectangle *rect)\n> +{\n> +\treturn setSelection(V4L2_SEL_TGT_COMPOSE, rect);\n> +}\n\nSince you have moved the declarations in the header file, you should\nmove these as well.\n\nNo worries, it could be fixed while applying it.\n\nPlease retain the tag I gave on v1\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n(also this can be added when applying the patch, no need to resend).\n\nThanks\n   j\n\n> +\n> +int V4L2VideoDevice::setSelection(unsigned int target, Rectangle *rect)\n> +{\n> +\tstruct v4l2_selection sel = {};\n> +\n> +\tsel.type = bufferType_;\n> +\tsel.target = target;\n> +\tsel.flags = 0;\n> +\n> +\tsel.r.left = rect->x;\n> +\tsel.r.top = rect->y;\n> +\tsel.r.width = rect->w;\n> +\tsel.r.height = rect->h;\n> +\n> +\tint ret = ioctl(VIDIOC_S_SELECTION, &sel);\n> +\tif (ret < 0) {\n> +\t\tLOG(V4L2, Error) << \"Unable to set rectangle \" << target\n> +\t\t\t\t << \": \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\trect->x = sel.r.left;\n> +\trect->y = sel.r.top;\n> +\trect->w = sel.r.width;\n> +\trect->h = sel.r.height;\n> +\n> +\treturn 0;\n> +}\n> +\n>  /**\n>   * \\class V4L2M2MDevice\n>   * \\brief Memory-to-Memory video device\n> --\n> 2.17.1\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A76E60446\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Feb 2020 23:49:22 +0100 (CET)","from uno.localdomain (93-34-114-233.ip49.fastwebnet.it\n\t[93.34.114.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id E484DE0002;\n\tMon,  3 Feb 2020 22:49:21 +0000 (UTC)"],"X-Originating-IP":"93.34.114.233","Date":"Mon, 3 Feb 2020 23:51:56 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200203225156.qbwzdz7rklj2lzbq@uno.localdomain>","References":"<20200203165851.11033-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"64le6u6mcgzi5fsm\"","Content-Disposition":"inline","In-Reply-To":"<20200203165851.11033-1-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH v2] libcamera: v4l2_videodevice: Add\n\tcrop/selection control.","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 03 Feb 2020 22:49:22 -0000"}}]