[{"id":32783,"web_url":"https://patchwork.libcamera.org/comment/32783/","msgid":"<wqsbsvsi5ulx2ydo3vyu3m3o4b6ibggbqykynd6kno3ojitcjw@wpboacefh57m>","date":"2024-12-16T18:35:41","subject":"Re: [PATCH v4 18/20] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Stefan\n\nOn Mon, Dec 16, 2024 at 04:40:58PM +0100, Stefan Klug wrote:\n> When the dewarper is used, config->validate() needs to take the\n> restrictions of the dewarper into account. Add the corresponding checks.\n>\n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n>\n> ---\n>\n> Changes in v4:\n> - Small fixes in comments\n> - Collected tags\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 46 +++++++++++++++++++++---\n>  1 file changed, 41 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 55b839e76d06..432a01694913 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -497,6 +497,7 @@ bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)\n>\n>  CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n>  {\n> +\tconst PipelineHandlerRkISP1 *pipe = data_->pipe();\n>  \tconst CameraSensor *sensor = data_->sensor_.get();\n>  \tunsigned int pathCount = data_->selfPath_ ? 2 : 1;\n>  \tStatus status;\n> @@ -553,6 +554,18 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n>  \t\t}\n>  \t}\n>\n> +\tbool useDewarper = false;\n> +\tif (pipe->dewarper_) {\n> +\t\t/*\n> +\t\t * Platforms with dewarper support, such as i.MX8MP, support\n> +\t\t * only a single stream. We can inspect config_[0] only here.\n> +\t\t */\n> +\t\tbool isRaw = PixelFormatInfo::info(config_[0].pixelFormat).colourEncoding ==\n> +\t\t\t     PixelFormatInfo::ColourEncodingRAW;\n> +\t\tif (!isRaw)\n> +\t\t\tuseDewarper = true;\n> +\t}\n> +\n>  \t/*\n>  \t * If there are more than one stream in the configuration figure out the\n>  \t * order to evaluate the streams. The first stream has the highest\n> @@ -565,12 +578,31 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n>  \tif (config_.size() == 2 && fitsAllPaths(config_[0]))\n>  \t\tstd::reverse(order.begin(), order.end());\n>\n> +\t/*\n> +\t * Validate the configuration against the desired path and, if the\n> +\t * platform supports it, the dewarper.\n> +\t */\n>  \tauto validateConfig = [&](StreamConfiguration &cfg, RkISP1Path *path,\n>  \t\t\t\t  Stream *stream, Status expectedStatus) {\n>  \t\tStreamConfiguration tryCfg = cfg;\n> -\t\tif (path->validate(sensor, sensorConfig, &tryCfg) != expectedStatus)\n> +\n> +\t\tStatus ret = path->validate(sensor, sensorConfig, &tryCfg);\n> +\t\tif (ret == Invalid)\n> +\t\t\treturn false;\n> +\n> +\t\tif (!useDewarper &&\n> +\t\t    (expectedStatus == Valid && ret == Adjusted))\n>  \t\t\treturn false;\n>\n> +\t\tif (useDewarper) {\n> +\t\t\tbool adjusted;\n> +\n> +\t\t\tpipe->dewarper_->validateOutput(&tryCfg, &adjusted,\n> +\t\t\t\t\t\t\tConverter::Alignment::Down);\n> +\t\t\tif (expectedStatus == Valid && adjusted)\n> +\t\t\t\treturn false;\n> +\t\t}\n> +\n>  \t\tcfg = tryCfg;\n>  \t\tcfg.setStream(stream);\n>  \t\treturn true;\n> @@ -820,6 +852,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \tconst PixelFormat &streamFormat = config->at(0).pixelFormat;\n>  \tconst PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);\n>  \tisRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n> +\tuseDewarper_ = dewarper_ && !isRaw_;\n\nThis should probably be moved to\n pipeline: rkisp1: Enable the dewarper unconditionally\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nThanks\n  j\n\n>\n>  \t/* YUYV8_2X8 is required on the ISP source path pad for YUV output. */\n>  \tif (!isRaw_)\n> @@ -832,8 +865,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \tif (media_->hwRevision() == RKISP1_V_IMX8MP) {\n>  \t\t/* imx8mp has only a single path. */\n>  \t\tconst auto &cfg = config->at(0);\n> -\t\tSize ispCrop = format.size.boundedToAspectRatio(cfg.size)\n> -\t\t\t\t\t  .alignedUpTo(2, 2);\n> +\t\tSize ispCrop = format.size.boundedToAspectRatio(cfg.size);\n> +\t\tif (useDewarper_)\n> +\t\t\tispCrop = dewarper_->adjustInputSize(cfg.pixelFormat,\n> +\t\t\t\t\t\t\t     ispCrop);\n> +\t\telse\n> +\t\t\tispCrop.alignUpTo(2, 2);\n> +\n>  \t\toutputCrop = ispCrop.centeredTo(Rectangle(format.size).center());\n>  \t\tformat.size = ispCrop;\n>  \t}\n> @@ -875,8 +913,6 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \t\t\t\tif (ret)\n>  \t\t\t\t\treturn ret;\n>\n> -\t\t\t\tuseDewarper_ = true;\n> -\n>  \t\t\t\t/*\n>  \t\t\t\t * Calculate the crop rectangle of the data\n>  \t\t\t\t * flowing into the dewarper in sensor\n> --\n> 2.43.0\n>","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 2F587C326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 18:35:47 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 65D0667FA4;\n\tMon, 16 Dec 2024 19:35:46 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0046267F93\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 19:35:44 +0100 (CET)","from ideasonboard.com (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A830160;\n\tMon, 16 Dec 2024 19:35:08 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"CVw2d+ZP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734374108;\n\tbh=N3UbFyzyiGzIIT2vVbojpRICidyswGbbUMC+ieMt01E=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=CVw2d+ZPCnTH1vGsVmy9VgikrPMQSA+mNqBvnfWPS6Xa8edTGevQDr2NefjuUm6Yq\n\tdo1kUTcK8hTuCZzNjmxxnoTdHJQtLhA3Nm4B7q/aoghwXp7nnrKpaXI8zqYGluB8DA\n\tmmXQmRbPtYWZA8O1Ko+0A9BzAXz8FSbgRO+Dq6Uo=","Date":"Mon, 16 Dec 2024 19:35:41 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v4 18/20] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","Message-ID":"<wqsbsvsi5ulx2ydo3vyu3m3o4b6ibggbqykynd6kno3ojitcjw@wpboacefh57m>","References":"<20241216154124.203650-1-stefan.klug@ideasonboard.com>\n\t<20241216154124.203650-19-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241216154124.203650-19-stefan.klug@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":32789,"web_url":"https://patchwork.libcamera.org/comment/32789/","msgid":"<ze6ss3bsbz4py3ooqtbzbvimcohy6so5zwsvwxdabkkgv6mp2b@u6hzjv4qzo7w>","date":"2024-12-16T20:34:26","subject":"Re: [PATCH v4 18/20] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the review. \n\nOn Mon, Dec 16, 2024 at 07:35:41PM +0100, Jacopo Mondi wrote:\n> Hi Stefan\n> \n> On Mon, Dec 16, 2024 at 04:40:58PM +0100, Stefan Klug wrote:\n> > When the dewarper is used, config->validate() needs to take the\n> > restrictions of the dewarper into account. Add the corresponding checks.\n> >\n> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> > Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> > Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> >\n> > ---\n> >\n> > Changes in v4:\n> > - Small fixes in comments\n> > - Collected tags\n> > ---\n> >  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 46 +++++++++++++++++++++---\n> >  1 file changed, 41 insertions(+), 5 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > index 55b839e76d06..432a01694913 100644\n> > --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > @@ -497,6 +497,7 @@ bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg)\n> >\n> >  CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n> >  {\n> > +\tconst PipelineHandlerRkISP1 *pipe = data_->pipe();\n> >  \tconst CameraSensor *sensor = data_->sensor_.get();\n> >  \tunsigned int pathCount = data_->selfPath_ ? 2 : 1;\n> >  \tStatus status;\n> > @@ -553,6 +554,18 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n> >  \t\t}\n> >  \t}\n> >\n> > +\tbool useDewarper = false;\n> > +\tif (pipe->dewarper_) {\n> > +\t\t/*\n> > +\t\t * Platforms with dewarper support, such as i.MX8MP, support\n> > +\t\t * only a single stream. We can inspect config_[0] only here.\n> > +\t\t */\n> > +\t\tbool isRaw = PixelFormatInfo::info(config_[0].pixelFormat).colourEncoding ==\n> > +\t\t\t     PixelFormatInfo::ColourEncodingRAW;\n> > +\t\tif (!isRaw)\n> > +\t\t\tuseDewarper = true;\n> > +\t}\n> > +\n> >  \t/*\n> >  \t * If there are more than one stream in the configuration figure out the\n> >  \t * order to evaluate the streams. The first stream has the highest\n> > @@ -565,12 +578,31 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n> >  \tif (config_.size() == 2 && fitsAllPaths(config_[0]))\n> >  \t\tstd::reverse(order.begin(), order.end());\n> >\n> > +\t/*\n> > +\t * Validate the configuration against the desired path and, if the\n> > +\t * platform supports it, the dewarper.\n> > +\t */\n> >  \tauto validateConfig = [&](StreamConfiguration &cfg, RkISP1Path *path,\n> >  \t\t\t\t  Stream *stream, Status expectedStatus) {\n> >  \t\tStreamConfiguration tryCfg = cfg;\n> > -\t\tif (path->validate(sensor, sensorConfig, &tryCfg) != expectedStatus)\n> > +\n> > +\t\tStatus ret = path->validate(sensor, sensorConfig, &tryCfg);\n> > +\t\tif (ret == Invalid)\n> > +\t\t\treturn false;\n> > +\n> > +\t\tif (!useDewarper &&\n> > +\t\t    (expectedStatus == Valid && ret == Adjusted))\n> >  \t\t\treturn false;\n> >\n> > +\t\tif (useDewarper) {\n> > +\t\t\tbool adjusted;\n> > +\n> > +\t\t\tpipe->dewarper_->validateOutput(&tryCfg, &adjusted,\n> > +\t\t\t\t\t\t\tConverter::Alignment::Down);\n> > +\t\t\tif (expectedStatus == Valid && adjusted)\n> > +\t\t\t\treturn false;\n> > +\t\t}\n> > +\n> >  \t\tcfg = tryCfg;\n> >  \t\tcfg.setStream(stream);\n> >  \t\treturn true;\n> > @@ -820,6 +852,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n> >  \tconst PixelFormat &streamFormat = config->at(0).pixelFormat;\n> >  \tconst PixelFormatInfo &info = PixelFormatInfo::info(streamFormat);\n> >  \tisRaw_ = info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;\n> > +\tuseDewarper_ = dewarper_ && !isRaw_;\n> \n> This should probably be moved to\n>  pipeline: rkisp1: Enable the dewarper unconditionally\n\nAs mentioned on patch 15/20 you didn't like it in that patch (which\nmakes sense), so I moved it here where it's actually needed.\n\n> \n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Thanks\n>   j\n\nThank you.\n\nStefan\n\n> \n> >\n> >  \t/* YUYV8_2X8 is required on the ISP source path pad for YUV output. */\n> >  \tif (!isRaw_)\n> > @@ -832,8 +865,13 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n> >  \tif (media_->hwRevision() == RKISP1_V_IMX8MP) {\n> >  \t\t/* imx8mp has only a single path. */\n> >  \t\tconst auto &cfg = config->at(0);\n> > -\t\tSize ispCrop = format.size.boundedToAspectRatio(cfg.size)\n> > -\t\t\t\t\t  .alignedUpTo(2, 2);\n> > +\t\tSize ispCrop = format.size.boundedToAspectRatio(cfg.size);\n> > +\t\tif (useDewarper_)\n> > +\t\t\tispCrop = dewarper_->adjustInputSize(cfg.pixelFormat,\n> > +\t\t\t\t\t\t\t     ispCrop);\n> > +\t\telse\n> > +\t\t\tispCrop.alignUpTo(2, 2);\n> > +\n> >  \t\toutputCrop = ispCrop.centeredTo(Rectangle(format.size).center());\n> >  \t\tformat.size = ispCrop;\n> >  \t}\n> > @@ -875,8 +913,6 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n> >  \t\t\t\tif (ret)\n> >  \t\t\t\t\treturn ret;\n> >\n> > -\t\t\t\tuseDewarper_ = true;\n> > -\n> >  \t\t\t\t/*\n> >  \t\t\t\t * Calculate the crop rectangle of the data\n> >  \t\t\t\t * flowing into the dewarper in sensor\n> > --\n> > 2.43.0\n> >","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 174FDC326C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 16 Dec 2024 20:34:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F24167FB3;\n\tMon, 16 Dec 2024 21:34:30 +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 3EEF467FAB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Dec 2024 21:34:29 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:15e9:bfc7:2fd9:3f8a])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36DF0675;\n\tMon, 16 Dec 2024 21:33:52 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"khJMkwC4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734381232;\n\tbh=ShUtE0z3w82s53hDEgH9ww6pgZPipF/5smPIjh2Z2nY=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=khJMkwC4rZeYkq/XUaZ2ViU9SyotLoC3fj6wpk42WZ9oOiiNsdnzFjRP75JZGXXLK\n\tpb5S1znIBLanyheh/ZbpATZdK+7x3B/YbZmDjWeIbhGRKgGDlpPTZKYODzzDR8yD0s\n\tuAI6lUONhsDh8I5j2KkQ9aEvCS6VsgAN3bk0zw2g=","Date":"Mon, 16 Dec 2024 21:34:26 +0100","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v4 18/20] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","Message-ID":"<ze6ss3bsbz4py3ooqtbzbvimcohy6so5zwsvwxdabkkgv6mp2b@u6hzjv4qzo7w>","References":"<20241216154124.203650-1-stefan.klug@ideasonboard.com>\n\t<20241216154124.203650-19-stefan.klug@ideasonboard.com>\n\t<wqsbsvsi5ulx2ydo3vyu3m3o4b6ibggbqykynd6kno3ojitcjw@wpboacefh57m>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<wqsbsvsi5ulx2ydo3vyu3m3o4b6ibggbqykynd6kno3ojitcjw@wpboacefh57m>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]