{"id":1863,"url":"https://patchwork.libcamera.org/api/1.1/patches/1863/?format=json","web_url":"https://patchwork.libcamera.org/patch/1863/","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":"<20190827095008.11405-8-jacopo@jmondi.org>","date":"2019-08-27T09:50:07","name":"[libcamera-devel,v2,7/7] libcamera: camera_sensor: Retrieve sensor sizes","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"cfbfbaadc6039bf5918fcd05819153bc302d1a70","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/1863/mbox/","series":[{"id":468,"url":"https://patchwork.libcamera.org/api/1.1/series/468/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=468","date":"2019-08-27T09:50:00","name":"libcamera: camera_sensor: Collect camera location and sizes","version":2,"mbox":"https://patchwork.libcamera.org/series/468/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1863/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1863/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BB6A160C1E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 27 Aug 2019 11:48:49 +0200 (CEST)","from uno.homenet.telecomitalia.it (unknown [87.18.63.98])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 0EB59100008;\n\tTue, 27 Aug 2019 09:48:48 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 27 Aug 2019 11:50:07 +0200","Message-Id":"<20190827095008.11405-8-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.23.0","In-Reply-To":"<20190827095008.11405-1-jacopo@jmondi.org>","References":"<20190827095008.11405-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 7/7] libcamera: camera_sensor: Retrieve\n\tsensor sizes","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Tue, 27 Aug 2019 09:48:49 -0000"},"content":"Retrieve the camera sensor pixel array sizes and the active pixel area\nusing the V4L2Subdevice selection API.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/geometry.h          |  1 +\n src/libcamera/camera_sensor.cpp       | 51 +++++++++++++++++++++++++++\n src/libcamera/geometry.cpp            | 24 +++++++++++++\n src/libcamera/include/camera_sensor.h |  4 +++\n 4 files changed, 80 insertions(+)","diff":"diff --git a/include/libcamera/geometry.h b/include/libcamera/geometry.h\nindex 52f4d010de76..b91fcfa1dd17 100644\n--- a/include/libcamera/geometry.h\n+++ b/include/libcamera/geometry.h\n@@ -42,6 +42,7 @@ struct Size {\n \tunsigned int height;\n \n \tconst std::string toString() const;\n+\tbool contains(const Rectangle &rectangle) const;\n };\n \n bool operator==(const Size &lhs, const Size &rhs);\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex fc7fdcdcaf5b..b6ccaae0930b 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -128,6 +128,28 @@ int CameraSensor::init()\n \t}\n \trotation_ = value;\n \n+\t/*\n+\t * Retrieve and store the sensor pixel array size and active area\n+\t * rectangle.\n+\t */\n+\tRectangle rect;\n+\tret = subdev_->getSelection(0, V4L2_SEL_TGT_NATIVE_SIZE, &rect);\n+\tif (ret)\n+\t\treturn ret;\n+\tpixelArray_.width = rect.w;\n+\tpixelArray_.height = rect.h;\n+\n+\tret = subdev_->getSelection(0, V4L2_SEL_TGT_CROP_BOUNDS, &rect);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (!pixelArray_.contains(rect)) {\n+\t\tLOG(CameraSensor, Error)\n+\t\t\t<< \"Invalid camera sensor pixel array dimension\";\n+\t\treturn -EINVAL;\n+\t}\n+\tactiveArea_ = rect;\n+\n \t/* Enumerate and cache media bus codes and sizes. */\n \tconst ImageFormats formats = subdev_->formats(0);\n \tif (formats.isEmpty()) {\n@@ -192,6 +214,35 @@ const Size &CameraSensor::resolution() const\n \treturn sizes_.back();\n }\n \n+/**\n+ * \\fn CameraSensor::pixelArray()\n+ * \\brief Retrieve the camera sensor pixel array dimension\n+ * \\return The number of horizontal and vertical pixel units installed on the\n+ * camera sensor\n+ *\n+ * The returned pixel array size is the number of pixels units physically\n+ * installed on the sensor, including non-active ones, such as pixels used\n+ * for calibration or testing.\n+ */\n+\n+/**\n+ * \\fn CameraSensor::activeArea()\n+ * \\brief Retrieve the active pixels area\n+ * \\return A rectangle describing the active pixel area\n+ *\n+ * The returned rectangle is contained in the larger pixel array area,\n+ * returned by the CameraSensor::pixelArray() operation.\n+ *\n+ * \\todo This operation collides with CameraSensor::resolution() as they\n+ * both reports the same information (bugs in the driver code apart).\n+ * Also, for some sensors, the maximum available resolution might depend on\n+ * the image size ratio (ie the maximumx resolution for images in 4:3 format\n+ * is different from the maximum available resolution for 16:9 format). This\n+ * has to be sorted out as well.\n+ *\n+ * \\sa Size::contains()\n+ */\n+\n /**\n  * \\brief Retrieve the best sensor format for a desired output\n  * \\param[in] mbusCodes The list of acceptable media bus codes\ndiff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp\nindex 32b0faeadc63..9b60768a57a7 100644\n--- a/src/libcamera/geometry.cpp\n+++ b/src/libcamera/geometry.cpp\n@@ -116,6 +116,30 @@ const std::string Size::toString() const\n \treturn std::to_string(width) + \"x\" + std::to_string(height);\n }\n \n+/**\n+ * \\fn Size::contains()\n+ * \\param rectangle The rectangle to verify\n+ * \\return True if \\a rectangle is contained in the area represented by this\n+ * Size, false otherwise\n+ *\n+ * Return true if \\a rectangle is completely contained in the area represented\n+ * by the width and height of this Size, with its top left corner assumed to be\n+ * at coordinates (0, 0). The rectangle 'x' and 'y' fields represent the\n+ * horizontal and vertical positive displacement from the Size top left corner,\n+ * from where the rectangle's horizontal and vertical sizes are calculated.\n+ */\n+bool Size::contains(const Rectangle &rectangle) const\n+{\n+\tif (rectangle.x < 0 || rectangle.y < 0)\n+\t\treturn false;\n+\n+\tif (rectangle.x + rectangle.w > width ||\n+\t    rectangle.y + rectangle.h > height)\n+\t\treturn false;\n+\n+\treturn true;\n+}\n+\n /**\n  * \\brief Compare sizes for equality\n  * \\return True if the two sizes are equal, false otherwise\ndiff --git a/src/libcamera/include/camera_sensor.h b/src/libcamera/include/camera_sensor.h\nindex 32d39127b275..abf5344cf9d8 100644\n--- a/src/libcamera/include/camera_sensor.h\n+++ b/src/libcamera/include/camera_sensor.h\n@@ -38,6 +38,8 @@ public:\n \tconst std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }\n \tconst std::vector<Size> &sizes() const { return sizes_; }\n \tconst Size &resolution() const;\n+\tconst Size pixelArray() const { return pixelArray_; }\n+\tconst Rectangle activeArea() const { return activeArea_; }\n \n \tV4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,\n \t\t\t\t      const Size &size) const;\n@@ -59,6 +61,8 @@ private:\n \n \tCameraLocation location_;\n \tunsigned int rotation_;\n+\tSize pixelArray_;\n+\tRectangle activeArea_;\n };\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v2","7/7"]}