{"id":19067,"url":"https://patchwork.libcamera.org/api/1.1/patches/19067/?format=json","web_url":"https://patchwork.libcamera.org/patch/19067/","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":"<20230921165550.50956-4-jacopo.mondi@ideasonboard.com>","date":"2023-09-21T16:55:40","name":"[libcamera-devel,v5,03/13] libcamera: camera_sensor: Support SensorConfiguration","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3e9eb4c0df9b17acf8d0bfe59f01fcad4b069416","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/1.1/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19067/mbox/","series":[{"id":4034,"url":"https://patchwork.libcamera.org/api/1.1/series/4034/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4034","date":"2023-09-21T16:55:37","name":"libcamera: Introduce SensorConfiguration","version":5,"mbox":"https://patchwork.libcamera.org/series/4034/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19067/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19067/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 4B1AEBE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 21 Sep 2023 16:56:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 21FDF62950;\n\tThu, 21 Sep 2023 18:56:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A1EB628D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 21 Sep 2023 18:56:03 +0200 (CEST)","from uno.lan (93-46-82-201.ip106.fastwebnet.it [93.46.82.201])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6967C2F6C;\n\tThu, 21 Sep 2023 18:54:25 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1695315367;\n\tbh=NPHplOidD9/bicVixBB26kVaoSilg+Le877fl+rVAf4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=kjCK6mADB+zUsrv2SC98IeEP4heDjoaX+14asCJ0o6IRtSG+drdWutk2tsvUEJ7dh\n\tqFEVx58XasoPPqUQWWugS/1jofiu+1gNVF/EuQb6ZlH4qJAbZ1w3O9x5q768VB0sHm\n\t3OIJx0fUkFsB5Ima0NcCeOzKjbDJmYd8+NvTc5AQtWBDPThoiV57D/0Yxi3FSqicWH\n\t32a+l1pPg8wXtMlv4nAEOL8/98tOLUnSAIUHTtvy+aHMZGc5cDN+bJ1QWiwtmgGVNm\n\tZrxHFkGLHIgjYB09q5/d4DHsN08WODv5VkWmlO8z1Fq4f2dYjomBjEs9TLzu1Sf+gg\n\tPeEqdFOeGkYxw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1695315265;\n\tbh=NPHplOidD9/bicVixBB26kVaoSilg+Le877fl+rVAf4=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Gw87q2qG4BeIA1t6JwuI7Mtiyi0keHv/UlrKAPoe7nEdXI2elRvJjd+gyxnb0nKwx\n\twPCfVyfv0Swgzw6+JTZw+omt2YgNuhNJCNRdwNa0M6pY/4OIdt77CsphE3ccWX1Kxg\n\tle/Fn5vhB5g+9BUaBOHucfFiSLJvmAAYfdClFLdE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Gw87q2qG\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 21 Sep 2023 18:55:40 +0200","Message-ID":"<20230921165550.50956-4-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.42.0","In-Reply-To":"<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>","References":"<20230921165550.50956-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 03/13] libcamera: camera_sensor:\n\tSupport SensorConfiguration","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>","From":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a class function to the CameraSensor class to apply a full\nconfiguration to the sensor.\n\nThe configuration shall be fully populated and shall apply without\nmodifications to the sensor.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n include/libcamera/internal/camera_sensor.h |  5 ++\n src/libcamera/camera_sensor.cpp            | 86 ++++++++++++++++++++++\n 2 files changed, 91 insertions(+)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 02c77ab037da..06791c3c6425 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -29,6 +29,7 @@ namespace libcamera {\n class BayerFormat;\n class CameraLens;\n class MediaEntity;\n+class SensorConfiguration;\n \n struct CameraSensorProperties;\n \n@@ -58,6 +59,10 @@ public:\n \t\t      Transform transform = Transform::Identity);\n \tint tryFormat(V4L2SubdeviceFormat *format) const;\n \n+\tint applyConfiguration(const SensorConfiguration &config,\n+\t\t\t       Transform transform = Transform::Identity,\n+\t\t\t       V4L2SubdeviceFormat *sensorFormat = nullptr);\n+\n \tconst ControlInfoMap &controls() const;\n \tControlList getControls(const std::vector<uint32_t> &ids);\n \tint setControls(ControlList *ctrls);\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex f3a5aa37149f..323081d25ce7 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -15,6 +15,7 @@\n #include <math.h>\n #include <string.h>\n \n+#include <libcamera/camera.h>\n #include <libcamera/property_ids.h>\n \n #include <libcamera/base/utils.h>\n@@ -822,6 +823,91 @@ int CameraSensor::tryFormat(V4L2SubdeviceFormat *format) const\n \t\t\t\t  V4L2Subdevice::Whence::TryFormat);\n }\n \n+/**\n+ * \\brief Apply a sensor configuration to the camera sensor\n+ * \\param[in] config The sensor configuration\n+ * \\param[in] transform The transform to be applied on the sensor.\n+ * Defaults to Identity\n+ * \\param[out] sensorFormat Optional output parameter where the format\n+ * actually applied to the sensor is returned to the caller\n+ *\n+ * Apply to the camera sensor the configuration \\a config.\n+ *\n+ * \\todo The configuration shall be fully populated and if any of the fields\n+ * specified cannot be applied exactly, an error code is returned.\n+ *\n+ * \\return 0 if \\a config unpopulated or is applied correctly to the camera\n+ * sensor, a negative error code otherwise\n+ */\n+int CameraSensor::applyConfiguration(const SensorConfiguration &config,\n+\t\t\t\t     Transform transform,\n+\t\t\t\t     V4L2SubdeviceFormat *sensorFormat)\n+{\n+\tif (!config.valid()) {\n+\t\tLOG(CameraSensor, Error) << \"Invalid sensor configuration\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tstd::vector<unsigned int> filteredCodes;\n+\tstd::copy_if(mbusCodes_.begin(), mbusCodes_.end(),\n+\t\t     std::back_inserter(filteredCodes),\n+\t\t     [&config](unsigned int mbusCode) {\n+\t\t\t     BayerFormat bayer = BayerFormat::fromMbusCode(mbusCode);\n+\t\t\t     if (bayer.bitDepth == config.bitDepth)\n+\t\t\t\t     return true;\n+\t\t\t     return false;\n+\t\t     });\n+\tif (filteredCodes.empty()) {\n+\t\tLOG(CameraSensor, Error)\n+\t\t\t<< \"Cannot find any format with bit depth \"\n+\t\t\t<< config.bitDepth;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\t/*\n+\t * Compute the sensor's data frame size by applying the cropping\n+\t * rectangle, subsampling and output crop to the sensor's pixel array\n+\t * size.\n+\t *\n+\t * \\todo The actual size computation is for now ignored and only the\n+\t * output size is considered. This implies that resolutions obtained\n+\t * with two different cropping/subsampling will look identical and\n+\t * only the first found one will be considered.\n+\t */\n+\tV4L2SubdeviceFormat subdevFormat = {};\n+\tfor (unsigned int code : filteredCodes) {\n+\t\tfor (const Size &size : sizes(code)) {\n+\t\t\tif (size.width != config.outputSize.width ||\n+\t\t\t    size.height != config.outputSize.height)\n+\t\t\t\tcontinue;\n+\n+\t\t\tsubdevFormat.mbus_code = code;\n+\t\t\tsubdevFormat.size = size;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (!subdevFormat.mbus_code) {\n+\t\tLOG(CameraSensor, Error) << \"Invalid output size in sensor configuration\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tint ret = setFormat(&subdevFormat, transform);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\t/*\n+\t * Return to the caller the format actually applied to the sensor.\n+\t * This is relevant if transform has changed the bayer pattern order.\n+\t */\n+\tif (sensorFormat)\n+\t\t*sensorFormat = subdevFormat;\n+\n+\t/* \\todo Handle AnalogCrop. Most sensors do not support set_selection */\n+\t/* \\todo Handle scaling in the digital domain. */\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\brief Retrieve the supported V4L2 controls and their information\n  *\n","prefixes":["libcamera-devel","v5","03/13"]}