Patch Detail
Show a patch.
GET /api/patches/18567/?format=api
{ "id": 18567, "url": "https://patchwork.libcamera.org/api/patches/18567/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18567/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230427144740.64075-2-jacopo.mondi@ideasonboard.com>", "date": "2023-04-27T14:47:35", "name": "[libcamera-devel,v3,1/6] libcamera: imx8-isi: Break out RAW format selection", "commit_ref": "87fed432533aacd290acee62f03c63b98aae98b1", "pull_url": null, "state": "accepted", "archived": false, "hash": "4b5ff2f1ddd1e89b071570775826e1424bedd0f2", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18567/mbox/", "series": [ { "id": 3852, "url": "https://patchwork.libcamera.org/api/series/3852/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3852", "date": "2023-04-27T14:47:34", "name": "libcamera: imx8-isi: Remove pixelformat-2-media-bus map", "version": 3, "mbox": "https://patchwork.libcamera.org/series/3852/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18567/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18567/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 32C2FC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 27 Apr 2023 14:48:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E3F9C627E0;\n\tThu, 27 Apr 2023 16:48:02 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 32DB9627B7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Apr 2023 16:47:59 +0200 (CEST)", "from uno.lan (unknown\n\t[IPv6:2001:b07:5d2e:52c9:1cf0:b3bc:c785:4625])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D9F799B9;\n\tThu, 27 Apr 2023 16:47:46 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1682606883;\n\tbh=Uq7XFoRhifKgykyoAb0pMfw/VQClvd12/+V26Jmb+NQ=;\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=1FXEW/WxqW2Irsq/UaTZ/ZMl3biG0cweYDTIy7HQ7nFCkynZeqP/5LnVcriIU7/Kt\n\t0/Bi604d4CKpgVTj6ixNdOmIYBX2jxDNqb2aPFo8LSNsCXkHoeNjj493h4L7bGEjRZ\n\tyqD1/eJuYBjInrZiBOCkqqQ0tI2Df3h+0//PzJ5F6Xjls3c17NOo9ERMd5W6n0+kya\n\tR5843CCx340tsJzuQH8+Bq2b5x+ovHfjMbno8Bb9a0zdrSYL7vOChW16BBN3xtq4+8\n\tXw9rx5Sf6MoW+PjdaN7dvTPq0F7mtIb4euRZh5yIQlqoknpeaPKzZNFZhrH7+uL+73\n\tWAUXx5KCRiRcw==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1682606867;\n\tbh=Uq7XFoRhifKgykyoAb0pMfw/VQClvd12/+V26Jmb+NQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=E328rq9cwE/EkYSL0ytg5WoEJZ6ueDApVcQpGIiPCK9me0gNsLye9wuZxws62g3E7\n\tIhWvGmu+Ozd4ixujacN/RJevMDarCI2igiJYQNiNzZpeK/p4y3fBqvrrPZRS6LkmME\n\t8a4uACtGwmBGvK/Im0RjjQ9Wxq4D4GbNc+2bneqI=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"E328rq9c\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 27 Apr 2023 16:47:35 +0200", "Message-Id": "<20230427144740.64075-2-jacopo.mondi@ideasonboard.com>", "X-Mailer": "git-send-email 2.40.0", "In-Reply-To": "<20230427144740.64075-1-jacopo.mondi@ideasonboard.com>", "References": "<20230427144740.64075-1-jacopo.mondi@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 1/6] libcamera: imx8-isi: Break out RAW\n\tformat 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>", "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": "The current implementation of the ISI pipeline handler handles\ntranslation of PixelFormat to media bus formats from the sensor\nthrough a centralized map.\n\nAs the criteria to select the correct media bus code depends on if the\noutput PixelFormat is a RAW Bayer format or not, start by splitting\nthe RAW media bus code procedure selection out by adding a function\nfor such purpose to the ISICameraData class.\n\nAdd the function to the ISICameraData and not to the\nISICameraConfiguration because:\n- The sensor is a property of CameraData\n- The same function will be re-used by the ISIPipelineHandler\n during CameraConfiguration generation.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\nTested-by: Daniel Scally <dan.scally@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 134 +++++++++++++------\n 1 file changed, 94 insertions(+), 40 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\nindex 0c67e35dde73..d124f1cc96d3 100644\n--- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\n+++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\n@@ -59,6 +59,8 @@ public:\n \t\treturn stream - &*streams_.begin();\n \t}\n \n+\tunsigned int getRawMediaBusFormat(PixelFormat *pixelFormat) const;\n+\n \tstd::unique_ptr<CameraSensor> sensor_;\n \tstd::unique_ptr<V4L2Subdevice> csis_;\n \n@@ -174,6 +176,89 @@ int ISICameraData::init()\n \treturn 0;\n }\n \n+/*\n+ * Get a RAW Bayer media bus format compatible with the requested pixelFormat.\n+ *\n+ * If the requested pixelFormat cannot be produced by the sensor adjust it to\n+ * the one corresponding to the media bus format with the largest bit-depth.\n+ */\n+unsigned int ISICameraData::getRawMediaBusFormat(PixelFormat *pixelFormat) const\n+{\n+\tstd::vector<unsigned int> mbusCodes = sensor_->mbusCodes();\n+\n+\tstatic const std::map<PixelFormat, unsigned int> rawFormats = {\n+\t\t{ formats::SBGGR8, MEDIA_BUS_FMT_SBGGR8_1X8 },\n+\t\t{ formats::SGBRG8, MEDIA_BUS_FMT_SGBRG8_1X8 },\n+\t\t{ formats::SGRBG8, MEDIA_BUS_FMT_SGRBG8_1X8 },\n+\t\t{ formats::SRGGB8, MEDIA_BUS_FMT_SRGGB8_1X8 },\n+\t\t{ formats::SBGGR10, MEDIA_BUS_FMT_SBGGR10_1X10 },\n+\t\t{ formats::SGBRG10, MEDIA_BUS_FMT_SGBRG10_1X10 },\n+\t\t{ formats::SGRBG10, MEDIA_BUS_FMT_SGRBG10_1X10 },\n+\t\t{ formats::SRGGB10, MEDIA_BUS_FMT_SRGGB10_1X10 },\n+\t\t{ formats::SBGGR12, MEDIA_BUS_FMT_SBGGR12_1X12 },\n+\t\t{ formats::SGBRG12, MEDIA_BUS_FMT_SGBRG12_1X12 },\n+\t\t{ formats::SGRBG12, MEDIA_BUS_FMT_SGRBG12_1X12 },\n+\t\t{ formats::SRGGB12, MEDIA_BUS_FMT_SRGGB12_1X12 },\n+\t\t{ formats::SBGGR14, MEDIA_BUS_FMT_SBGGR14_1X14 },\n+\t\t{ formats::SGBRG14, MEDIA_BUS_FMT_SGBRG14_1X14 },\n+\t\t{ formats::SGRBG14, MEDIA_BUS_FMT_SGRBG14_1X14 },\n+\t\t{ formats::SRGGB14, MEDIA_BUS_FMT_SRGGB14_1X14 },\n+\t};\n+\n+\t/*\n+\t * Make sure the requested PixelFormat is supported in the above\n+\t * map and the sensor can produce the compatible mbus code.\n+\t */\n+\tauto it = rawFormats.find(*pixelFormat);\n+\tif (it != rawFormats.end() &&\n+\t std::count(mbusCodes.begin(), mbusCodes.end(), it->second))\n+\t\treturn it->second;\n+\n+\tif (it == rawFormats.end())\n+\t\tLOG(ISI, Warning) << pixelFormat\n+\t\t\t\t << \" not supported in ISI formats map.\";\n+\n+\t/*\n+\t * The desired pixel format cannot be produced. Adjust it to the one\n+\t * corresponding to the raw media bus format with the largest bit-depth\n+\t * the sensor provides.\n+\t */\n+\tunsigned int sensorCode = 0;\n+\tunsigned int maxDepth = 0;\n+\t*pixelFormat = {};\n+\n+\tfor (unsigned int code : mbusCodes) {\n+\t\t/* Make sure the media bus format is RAW Bayer. */\n+\t\tconst BayerFormat &bayerFormat = BayerFormat::fromMbusCode(code);\n+\t\tif (!bayerFormat.isValid())\n+\t\t\tcontinue;\n+\n+\t\t/* Make sure the media format is supported. */\n+\t\tit = std::find_if(rawFormats.begin(), rawFormats.end(),\n+\t\t\t\t [code](auto &rawFormat) {\n+\t\t\t\t\t return rawFormat.second == code;\n+\t\t\t\t });\n+\n+\t\tif (it == rawFormats.end()) {\n+\t\t\tLOG(ISI, Warning) << bayerFormat\n+\t\t\t\t\t << \" not supported in ISI formats map.\";\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* Pick the one with the largest bit depth. */\n+\t\tif (bayerFormat.bitDepth > maxDepth) {\n+\t\t\tmaxDepth = bayerFormat.bitDepth;\n+\t\t\t*pixelFormat = it->first;\n+\t\t\tsensorCode = code;\n+\t\t}\n+\t}\n+\n+\tif (!pixelFormat->isValid())\n+\t\tLOG(ISI, Error) << \"Cannot find a supported RAW format\";\n+\n+\treturn sensorCode;\n+}\n+\n /* -----------------------------------------------------------------------------\n * Camera Configuration\n */\n@@ -311,50 +396,19 @@ ISICameraConfiguration::validateRaw(std::set<Stream *> &availableStreams,\n \t */\n \tstd::vector<unsigned int> mbusCodes = data_->sensor_->mbusCodes();\n \tStreamConfiguration &rawConfig = config_[0];\n+\tPixelFormat rawFormat = rawConfig.pixelFormat;\n \n-\tbool supported = false;\n-\tauto it = formatsMap_.find(rawConfig.pixelFormat);\n-\tif (it != formatsMap_.end()) {\n-\t\tunsigned int mbusCode = it->second.sensorCode;\n-\n-\t\tif (std::count(mbusCodes.begin(), mbusCodes.end(), mbusCode))\n-\t\t\tsupported = true;\n+\tunsigned int sensorCode = data_->getRawMediaBusFormat(&rawFormat);\n+\tif (!sensorCode) {\n+\t\tLOG(ISI, Error) << \"Cannot adjust RAW pixelformat \"\n+\t\t\t\t<< rawConfig.pixelFormat;\n+\t\treturn Invalid;\n \t}\n \n-\tif (!supported) {\n-\t\t/*\n-\t\t * Adjust to the first mbus code supported by both the\n-\t\t * sensor and the pipeline.\n-\t\t */\n-\t\tconst FormatMap::value_type *pipeConfig = nullptr;\n-\t\tfor (unsigned int code : mbusCodes) {\n-\t\t\tconst BayerFormat &bayerFormat = BayerFormat::fromMbusCode(code);\n-\t\t\tif (!bayerFormat.isValid())\n-\t\t\t\tcontinue;\n-\n-\t\t\tauto fmt = std::find_if(ISICameraConfiguration::formatsMap_.begin(),\n-\t\t\t\t\t\tISICameraConfiguration::formatsMap_.end(),\n-\t\t\t\t\t\t[code](const auto &isiFormat) {\n-\t\t\t\t\t\t\tconst auto &pipe = isiFormat.second;\n-\t\t\t\t\t\t\treturn pipe.sensorCode == code;\n-\t\t\t\t\t\t});\n-\n-\t\t\tif (fmt == ISICameraConfiguration::formatsMap_.end())\n-\t\t\t\tcontinue;\n-\n-\t\t\tpipeConfig = &(*fmt);\n-\t\t\tbreak;\n-\t\t}\n-\n-\t\tif (!pipeConfig) {\n-\t\t\tLOG(ISI, Error) << \"Cannot adjust RAW format \"\n-\t\t\t\t\t<< rawConfig.pixelFormat;\n-\t\t\treturn Invalid;\n-\t\t}\n-\n-\t\trawConfig.pixelFormat = pipeConfig->first;\n+\tif (rawFormat != rawConfig.pixelFormat) {\n \t\tLOG(ISI, Debug) << \"RAW pixelformat adjusted to \"\n-\t\t\t\t<< pipeConfig->first;\n+\t\t\t\t<< rawFormat;\n+\t\trawConfig.pixelFormat = rawFormat;\n \t\tstatus = Adjusted;\n \t}\n \n", "prefixes": [ "libcamera-devel", "v3", "1/6" ] }