[{"id":32702,"web_url":"https://patchwork.libcamera.org/comment/32702/","msgid":"<Z1rTQ_1EjSOGWF0B@pyrite.rasen.tech>","date":"2024-12-12T12:12:51","subject":"Re: [PATCH v3 15/17] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"On Fri, Dec 06, 2024 at 11:13:37AM +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> ---\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 c582e164670c..2baff6da7cb7 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 a\n\ns/ a / only a /\n\n> +\t\t * 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\ns/the dewarper/use the dewarper/\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\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>  \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 975F1BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 12 Dec 2024 12:13:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D795967ED4;\n\tThu, 12 Dec 2024 13:13:09 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2310567EC7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 12 Dec 2024 13:13:08 +0100 (CET)","from pyrite.rasen.tech (unknown\n\t[IPv6:2404:7a81:160:2100:39eb:989c:b016:217b])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 36206316;\n\tThu, 12 Dec 2024 13:12:32 +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=\"Me2POVuU\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1734005554;\n\tbh=ly1wHauSp2Y4LkkA+a2YDyP3ktK0lTcEiwOLnlvMd8E=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Me2POVuU1Z9QfSjmg/9xGcnE/eYabdoYGuzRe9VMOV0UGlS9Bpbo4gTgecMDQFK6w\n\towIXFs+IkaA/c8BhhBDtIRoRlGUMDekWM8qFDdAFFACfGdRFeY7Zqul4LkXrFHnxuM\n\tTYCscWBQNNRKTPc04rd7K0e72nBsHsrkDpZrY4Jc=","Date":"Thu, 12 Dec 2024 21:12:51 +0900","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"Re: [PATCH v3 15/17] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","Message-ID":"<Z1rTQ_1EjSOGWF0B@pyrite.rasen.tech>","References":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>\n\t<20241206101344.767170-16-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20241206101344.767170-16-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>"}}]