[{"id":26926,"web_url":"https://patchwork.libcamera.org/comment/26926/","msgid":"<20230424054527.GA9864@pendragon.ideasonboard.com>","date":"2023-04-24T05:45:27","subject":"Re: [libcamera-devel] [PATCH v2 2/6] libcamera: imx8-isi: Break out\n\tYUV format selection","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Mon, Mar 13, 2023 at 10:19:40AM +0100, Jacopo Mondi wrote:\n> As per the RAW format selection, the media bus format selection\n> procedure relies on the direct association of PixelFormat and media\n> bus code in the formatsMap_ map.\n> \n> As the ISI can generate YUV and RGB formats from any non-Bayer media\n> bus format, break out the YUV/RGB media bus format selection to a\n> separate function.\n> \n> The newly introduced getYuvMediaBusFormat() tests a list of\n> known-supported media bus formats against the list of media bus\n> formats supported by the sensor and tries to prefer media bus\n> codes with the same encoding as the requested PixelFormat.\n> \n> Use the newly introduced function in\n> ISICameraConfiguration::validateYuv() to make sure the sensor can\n> produce a YUV/RGB media bus format.\n> \n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n> Tested-by: Daniel Scally <dan.scally@ideasonboard.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 76 ++++++++++++++++++++\n>  1 file changed, 76 insertions(+)\n> \n> diff --git a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\n> index ffb96e6284f0..390e82b6947f 100644\n> --- a/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\n> +++ b/src/libcamera/pipeline/imx8-isi/imx8-isi.cpp\n> @@ -60,6 +60,7 @@ public:\n>  \t}\n>  \n>  \tunsigned int getRawMediaBusFormat(PixelFormat *pixelFormat) const;\n> +\tunsigned int getYuvMediaBusFormat(PixelFormat *pixelFormat) const;\n>  \n>  \tstd::unique_ptr<CameraSensor> sensor_;\n>  \tstd::unique_ptr<V4L2Subdevice> csis_;\n> @@ -255,6 +256,65 @@ unsigned int ISICameraData::getRawMediaBusFormat(PixelFormat *pixelFormat) const\n>  \treturn sensorCode;\n>  }\n>  \n> +/*\n> + * Get a YUV/RGB media bus format from which the ISI can produce a processed\n> + * stream, preferring codes with the same colour encoding as the requested\n> + * pixelformat.\n> + *\n> + * If the sensor does not provide any YUV/RGB media bus format the ISI cannot\n> + * generate any processed pixel format as it cannot debayer.\n> + */\n> +unsigned int ISICameraData::getYuvMediaBusFormat(PixelFormat *pixelFormat) const\n> +{\n> +\tstd::vector<unsigned int> mbusCodes = sensor_->mbusCodes();\n> +\n> +\t/*\n> +\t * The ISI can produce YUV/RGB pixel formats from any non-RAW Bayer\n> +\t * media bus formats.\n> +\t *\n> +\t * Keep the list in sync with the mxc_isi_bus_formats[] array in\n> +\t * the ISI driver.\n> +\t */\n> +\tstd::vector<unsigned int> yuvCodes = {\n> +\t\tMEDIA_BUS_FMT_UYVY8_1X16,\n> +\t\tMEDIA_BUS_FMT_YUV8_1X24,\n> +\t\tMEDIA_BUS_FMT_RGB565_1X16,\n> +\t\tMEDIA_BUS_FMT_RGB888_1X24,\n> +\t};\n> +\n> +\tstd::sort(mbusCodes.begin(), mbusCodes.end());\n> +\tstd::sort(yuvCodes.begin(), yuvCodes.end());\n> +\n> +\tstd::vector<unsigned int> supportedCodes;\n> +\tstd::set_intersection(mbusCodes.begin(), mbusCodes.end(),\n> +\t\t\t      yuvCodes.begin(), yuvCodes.end(),\n> +\t\t\t      std::back_inserter(supportedCodes));\n> +\n> +\tif (supportedCodes.empty()) {\n> +\t\tLOG(ISI, Warning) << \"Cannot find a supported YUV/RGB format\";\n> +\t\t*pixelFormat = {};\n\n*pixelFormat is only modified in this error path, and you then ignore is\nin the caller. I would turn the `PixelFormat *pixelFormat` argument into\na `const PixelFormat pixelFormat` to make the API clearer.\n\n> +\n> +\t\treturn 0;\n> +\t}\n> +\n> +\t/* Prefer codes with the same encoding as the requested pixel format. */\n> +\tconst PixelFormatInfo &info = PixelFormatInfo::info(*pixelFormat);\n> +\tfor (unsigned int code : supportedCodes) {\n> +\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingYUV &&\n> +\t\t    (code == MEDIA_BUS_FMT_UYVY8_1X16 ||\n> +\t\t     code == MEDIA_BUS_FMT_YUV8_1X24))\n> +\t\t\treturn code;\n> +\n> +\t\tif (info.colourEncoding == PixelFormatInfo::ColourEncodingRGB &&\n> +\t\t    (code == MEDIA_BUS_FMT_RGB565_1X16 ||\n> +\t\t     code == MEDIA_BUS_FMT_RGB888_1X24))\n> +\t\t\treturn code;\n> +\t}\n> +\n> +\t/* Otherwise return the first found code. */\n> +\treturn supportedCodes[0];\n> +}\n> +\n>  /* -----------------------------------------------------------------------------\n>   * Camera Configuration\n>   */\n> @@ -455,6 +515,22 @@ ISICameraConfiguration::validateYuv(std::set<Stream *> &availableStreams,\n>  {\n>  \tCameraConfiguration::Status status = Valid;\n>  \n> +\tStreamConfiguration &yuvConfig = config_[0];\n> +\tPixelFormat yuvPixelFormat = yuvConfig.pixelFormat;\n> +\n> +\t/*\n> +\t * Make sure the sensor can produce a compatible YUV/RGB media bus\n> +\t * format. If the sensor can only produce RAW Bayer we can only fail\n> +\t * here as we can't adjust to anything but RAW.\n> +\t */\n> +\tunsigned int yuvMediaBusCode = data_->getYuvMediaBusFormat(&yuvPixelFormat);\n> +\tif (!yuvMediaBusCode) {\n> +\t\tLOG(ISI, Error) << \"Cannot adjust pixelformat \"\n> +\t\t\t\t<< yuvConfig.pixelFormat;\n> +\t\treturn Invalid;\n> +\t}\n> +\n> +\t/* Adjust all the other streams. */\n>  \tfor (const auto &[i, cfg] : utils::enumerate(config_)) {\n>  \n>  \t\tLOG(ISI, Debug) << \"Stream \" << i << \": \" << cfg.toString();","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 D5620C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Apr 2023 05:45:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1BBBE627D5;\n\tMon, 24 Apr 2023 07:45:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E16EF61EB1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Apr 2023 07:45:15 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(133-32-181-51.west.xps.vectant.ne.jp [133.32.181.51])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 10B4824E2;\n\tMon, 24 Apr 2023 07:45:04 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1682315117;\n\tbh=xdL9xRTFcThizLnxlGzluZsddOLJji3TOQStFSOmWeY=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=YSu4cC4v8wXm9Xv8cR/Tr3pQwaSShzohqHA0XHui6CkwsL5ZlCN3mIjA11oi9FwNf\n\tN73BOCmK6YLy2MIn7czrAqGMhso2cYXUN8LFCBZ61Hni+4x8f9lo5Uy2EnCu19bjN9\n\tIWfXpzSH/9p9gAL11nvWIWgzcK5gLZ6qxvCN2jFDXOtFmLt6hT9DSJMDwGizKFrL7c\n\tGghBhsYRcDxXHhjNncr3+imXEItKXGYhHwCBbv6VarAOA3AV7gGEmpC4e0GzYZ+X6a\n\tobQTTHJyl/F2PNfAG2wrGBPKuLbk+zbvffdxpwEnu0MGcpKP+9d9XSI4ZV44sQOtUt\n\t78pZiT8SIUyQg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1682315105;\n\tbh=xdL9xRTFcThizLnxlGzluZsddOLJji3TOQStFSOmWeY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=iibWEggoUoNglG8paIzQ7G+UpO09DxtFl4nBXPXCBOIwpFVJO6beFbXUJO3YZhkL7\n\tbeHvFOOE5P93sT6Gz+Aq0QMjGGVHxfmkeizESz1MZVo+TBRojV8KAV0EhGLCzGj61a\n\tXfC6ObmdrJT754ztwe7X8CFiBnEsBM5+hLOQfQ0s="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"iibWEggo\"; dkim-atps=neutral","Date":"Mon, 24 Apr 2023 08:45:27 +0300","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Message-ID":"<20230424054527.GA9864@pendragon.ideasonboard.com>","References":"<20230313091944.9530-1-jacopo.mondi@ideasonboard.com>\n\t<20230313091944.9530-3-jacopo.mondi@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230313091944.9530-3-jacopo.mondi@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v2 2/6] libcamera: imx8-isi: Break out\n\tYUV format 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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]