{"id":3522,"url":"https://patchwork.libcamera.org/api/1.1/patches/3522/?format=json","web_url":"https://patchwork.libcamera.org/patch/3522/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200424215304.558317-5-jacopo@jmondi.org>","date":"2020-04-24T21:52:55","name":"[libcamera-devel,v3,04/13] libcamera: v4l2_subdevice: Implement get selection","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"bc694bbe4e951270938c80c779bd7725a1589c37","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3522/mbox/","series":[{"id":822,"url":"https://patchwork.libcamera.org/api/1.1/series/822/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=822","date":"2020-04-24T21:52:51","name":"libcamera: Add CameraSensorInfo","version":3,"mbox":"https://patchwork.libcamera.org/series/822/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3522/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3522/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 92119603FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Apr 2020 23:50:07 +0200 (CEST)","from uno.homenet.telecomitalia.it\n\t(host240-55-dynamic.3-87-r.retail.telecomitalia.it [87.3.55.240])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9D33D60004;\n\tFri, 24 Apr 2020 21:50:06 +0000 (UTC)"],"X-Originating-IP":"87.3.55.240","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 24 Apr 2020 23:52:55 +0200","Message-Id":"<20200424215304.558317-5-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.26.1","In-Reply-To":"<20200424215304.558317-1-jacopo@jmondi.org>","References":"<20200424215304.558317-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 04/13] libcamera: v4l2_subdevice:\n\tImplement get selection","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":"Fri, 24 Apr 2020 21:50:07 -0000"},"content":"Implement get selection for the V4L2Subdevice class to support\nretrieving three targets: the subdevice native size, the analog crop and\nthe active pixel area.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_subdevice.h |  6 ++\n src/libcamera/v4l2_subdevice.cpp       | 92 ++++++++++++++++++++++++++\n 2 files changed, 98 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_subdevice.h b/src/libcamera/include/v4l2_subdevice.h\nindex 4a04eadfb1f9..763ffadb61fb 100644\n--- a/src/libcamera/include/v4l2_subdevice.h\n+++ b/src/libcamera/include/v4l2_subdevice.h\n@@ -46,6 +46,10 @@ public:\n \n \tconst MediaEntity *entity() const { return entity_; }\n \n+\tint getNativeSize(unsigned int pad, Size *size);\n+\tint getActiveArea(unsigned int pad, Rectangle *rect);\n+\tint getCropRectangle(unsigned int pad, Rectangle *rect);\n+\n \tint setCrop(unsigned int pad, Rectangle *rect);\n \tint setCompose(unsigned int pad, Rectangle *rect);\n \n@@ -67,6 +71,8 @@ private:\n \tstd::vector<SizeRange> enumPadSizes(unsigned int pad,\n \t\t\t\t\t    unsigned int code);\n \n+\tint getSelection(unsigned int pad, unsigned int target,\n+\t\t\t Rectangle *rect);\n \tint setSelection(unsigned int pad, unsigned int target,\n \t\t\t Rectangle *rect);\n \ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 5a479a96b795..4dcf8ce48754 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -133,6 +133,68 @@ int V4L2Subdevice::open()\n  * \\return The subdevice's associated media entity.\n  */\n \n+/**\n+ * \\brief Get the sub-device native size\n+ * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n+ * \\param[out] size The sub-device native area size\n+ *\n+ * Retrieve the size of the sub-device native area.\n+ * If the sub-device represent an image sensor, the native area describes\n+ * the pixel array dimensions, including inactive and calibration pixels.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -ENOTTY The native size information is not available\n+ */\n+int V4L2Subdevice::getNativeSize(unsigned int pad, Size *size)\n+{\n+\tRectangle rect = {};\n+\tint ret = getSelection(pad, V4L2_SEL_TGT_NATIVE_SIZE, &rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tsize->width = rect.width;\n+\tsize->height = rect.height;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Get the active area rectangle\n+ * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n+ * \\param[out] rect The rectangle describing the sub-device active area\n+ *\n+ * Retrieve the rectangle describing the sub-device active area.\n+ * If the sub-device represent an image sensor, the active area describes\n+ * the pixel array active portion.\n+ *\n+ * The returned \\a rect 'x' and 'y' fields represent the displacement from the\n+ * native size rectangle top-left corner.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -ENOTTY The active areas size information is not available\n+ */\n+int V4L2Subdevice::getActiveArea(unsigned int pad, Rectangle *rect)\n+{\n+\treturn getSelection(pad, V4L2_SEL_TGT_CROP_DEFAULT, rect);\n+}\n+\n+/**\n+ * \\brief Get the crop rectangle\n+ * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n+ * \\param[out] rect The rectangle describing the cropped area rectangle\n+ *\n+ * Retrieve the rectangle representing the cropped area. If the sub-device\n+ * represents an image sensor, the cropped area describes the pixel array\n+ * portion from which the final image is produced from.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -ENOTTY The crop rectangle size information is not available\n+ */\n+int V4L2Subdevice::getCropRectangle(unsigned int pad, Rectangle *rect)\n+{\n+\treturn getSelection(pad, V4L2_SEL_TGT_CROP, rect);\n+}\n+\n /**\n  * \\brief Set a crop rectangle on one of the V4L2 subdevice pads\n  * \\param[in] pad The 0-indexed pad number the rectangle is to be applied to\n@@ -343,6 +405,36 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,\n \treturn sizes;\n }\n \n+int V4L2Subdevice::getSelection(unsigned int pad, unsigned int target,\n+\t\t\t\tRectangle *rect)\n+{\n+\tstruct v4l2_subdev_selection sel = {};\n+\n+\tsel.which = V4L2_SUBDEV_FORMAT_ACTIVE;\n+\tsel.pad = pad;\n+\tsel.target = target;\n+\tsel.flags = 0;\n+\n+\tint ret = ioctl(VIDIOC_SUBDEV_G_SELECTION, &sel);\n+\tif (ret < 0 && ret != -ENOTTY) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"Unable to get rectangle \" << target << \" on pad \"\n+\t\t\t<< pad << \": \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\tif (ret == -ENOTTY) {\n+\t\tLOG(V4L2, Debug) << \"Selection API not available\";\n+\t\treturn ret;\n+\t}\n+\n+\trect->x = sel.r.left;\n+\trect->y = sel.r.top;\n+\trect->width = sel.r.width;\n+\trect->height = sel.r.height;\n+\n+\treturn 0;\n+}\n+\n int V4L2Subdevice::setSelection(unsigned int pad, unsigned int target,\n \t\t\t\tRectangle *rect)\n {\n","prefixes":["libcamera-devel","v3","04/13"]}