{"id":18384,"url":"https://patchwork.libcamera.org/api/1.1/patches/18384/?format=json","web_url":"https://patchwork.libcamera.org/patch/18384/","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":"<20230313091944.9530-2-jacopo.mondi@ideasonboard.com>","date":"2023-03-13T09:19:39","name":"[libcamera-devel,v2,1/6] libcamera: imx8-isi: Break out RAW format selection","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"3187bca86c6943d9f90e039173b30b9542db147d","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/18384/mbox/","series":[{"id":3803,"url":"https://patchwork.libcamera.org/api/1.1/series/3803/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3803","date":"2023-03-13T09:19:38","name":"libcamera: imx8-isi: Remove pixelformat-2-media-bus map","version":2,"mbox":"https://patchwork.libcamera.org/series/3803/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18384/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18384/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 EE6F8C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 13 Mar 2023 09:20:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A17462710;\n\tMon, 13 Mar 2023 10:20:04 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 48C59626B2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 13 Mar 2023 10:20:02 +0100 (CET)","from uno.homenet.telecomitalia.it\n\t(host-79-33-55-183.retail.telecomitalia.it [79.33.55.183])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 62F3E8CC;\n\tMon, 13 Mar 2023 10:20:01 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1678699204;\n\tbh=dEH2tY6MGiTWeiifQ9gHQ0FCPbwnK1BxHd+7Oyw+XvY=;\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=OFJPy9+wWbybNiUn77B171WMAFjqAmm1o8FPbeXZSwy1xNiL5GmZ7atV8Q7eqj+ZX\n\t6kPYqu3A5nvpM6VM5193jFPnQJZSwR/PkVMhIuqr2pTNP5cn9F/CiE8wn87Lw+ghab\n\t6XHCeoSLvI7eVVfbgQoaO+0C/1Yz/GDVzCDM16aZIF2xH52fYVQ2EQvlXeqn07J6z9\n\t0JIzdTsd/h0XDUjvGhNuKT/o8NrhBuiiX+EDyWCDtoaKxvdeIKTIG4E+OQ+ZD/knpu\n\tfdnXDOW3M1hHM+drC1XGKAGrGyGpVNgi2POg/MiGX6cYIud6N1QpZPTLR97L6CyxzX\n\tNi1/waO1uxwFQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1678699202;\n\tbh=dEH2tY6MGiTWeiifQ9gHQ0FCPbwnK1BxHd+7Oyw+XvY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qDgqmQgtJ02Sy+MUKIwqx1hNG8o17QdKPzhAfUqIXXhE+b8Ocab5jpY8ZSzqv98Jx\n\tANcprLchiXuN71/MuNIdGA3osu85en431hykPPxcnuVZsxP3NXx6S58d3j8gl31WNN\n\tQy7MDxwbN+KGSOjpyCIm0LwufV036bGxkT0seT8Y="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qDgqmQgt\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 13 Mar 2023 10:19:39 +0100","Message-Id":"<20230313091944.9530-2-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.39.0","In-Reply-To":"<20230313091944.9530-1-jacopo.mondi@ideasonboard.com>","References":"<20230313091944.9530-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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 | 130 +++++++++++++------\n 1 file changed, 90 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..ffb96e6284f0 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,85 @@ 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};\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 +392,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","v2","1/6"]}