{"id":18218,"url":"https://patchwork.libcamera.org/api/patches/18218/?format=json","web_url":"https://patchwork.libcamera.org/patch/18218/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20230129135830.27490-2-jacopo.mondi@ideasonboard.com>","date":"2023-01-29T13:58:26","name":"[libcamera-devel,1/5] libcamera: imx8-isi: Break-out RAW format selection","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0fbbbd8fe246e3ee6bc59f2bc78073193190d5e1","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18218/mbox/","series":[{"id":3730,"url":"https://patchwork.libcamera.org/api/series/3730/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3730","date":"2023-01-29T13:58:25","name":"libcamera: imx8-isi: Remove pixelformat-2-media-bus map","version":1,"mbox":"https://patchwork.libcamera.org/series/3730/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18218/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18218/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 229A8BEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 29 Jan 2023 13:58:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1C6E4625ED;\n\tSun, 29 Jan 2023 14:58:49 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6E736625DF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 29 Jan 2023 14:58:47 +0100 (CET)","from uno.localdomain (mob-5-90-54-203.net.vodafone.it\n\t[5.90.54.203])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D7F85449;\n\tSun, 29 Jan 2023 14:58:46 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1675000729;\n\tbh=06ltF8tTHvFGkTpBne/Paq2U5AafJ01ZSkNfzn5Gpfk=;\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=Q+3lbIr84B6pwyyy3x5aUUjXm8YtSGO4JibpEdMbeWSfHxvHpD8Yh9HW/J6Rfsytk\n\tQr3U3ZBI/2qS2YNDge0lT6HbokB1Nk7DbCYlXhk2B0a7YKuaaJqpz8s2x2AzWT+n4q\n\tmKebhYSmpyCRQUSiEE3gs24VJKH6QR8XyYyEm4M+oraNhzS25q/IFllN6+g2QlFwLA\n\tALayQSlXJhIJkJwyEbFVHDZdg9PTVaAJUfrGW7aWhOf5eg5vSrZUafdSsBBvpD02Oi\n\tO8yAUGKIGjGuRz8UfSehIve3N0dvgwTsG+DGrakXG4Ct3jlQ845Tn+/jBXWj2f6ekc\n\tYAiDqjqcJXPXw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1675000727;\n\tbh=06ltF8tTHvFGkTpBne/Paq2U5AafJ01ZSkNfzn5Gpfk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=BDToUNpERdWjN8q6g0Uy6ROKMhblXQ6NnkCcBV9Y4/XE3p89Pat7nZp63wahxEt6R\n\tX1NRu0IPsaCDfHBAIxOKbT3hBeR+LAFDDvYaWUAQ6jVOMyoKVrTKwnNFZaxi2LZFYc\n\tppINjlpxmPyKXYZBoClhkuOwi2GGGSLARoXad/Wg="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"BDToUNpE\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Sun, 29 Jan 2023 14:58:26 +0100","Message-Id":"<20230129135830.27490-2-jacopo.mondi@ideasonboard.com>","X-Mailer":"git-send-email 2.39.0","In-Reply-To":"<20230129135830.27490-1-jacopo.mondi@ideasonboard.com>","References":"<20230129135830.27490-1-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 1/5] 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 depend 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 method\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>\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..72bc310d80ec 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+\tconst 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","1/5"]}