{"id":22207,"url":"https://patchwork.libcamera.org/api/patches/22207/?format=json","web_url":"https://patchwork.libcamera.org/patch/22207/","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":"<20241206101344.767170-16-stefan.klug@ideasonboard.com>","date":"2024-12-06T10:13:37","name":"[v3,15/17] pipeline: rkisp1: Fix config validation when dewarper is used","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b40f36f0d6528bf2e28f0b9679dfc656582ca3e6","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":{"id":17,"url":"https://patchwork.libcamera.org/api/users/17/?format=json","username":"epaul","first_name":"Paul","last_name":"Elder","email":"paul.elder@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/22207/mbox/","series":[{"id":4854,"url":"https://patchwork.libcamera.org/api/series/4854/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4854","date":"2024-12-06T10:13:22","name":"rkisp1: Fix aspect ratio and ScalerCrop","version":3,"mbox":"https://patchwork.libcamera.org/series/4854/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22207/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22207/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 23651BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  6 Dec 2024 10:14:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D271866160;\n\tFri,  6 Dec 2024 11:14:33 +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 13DC266160\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Dec 2024 11:14:31 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:3543:aebe:e043:ef86])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B3DC8B2B;\n\tFri,  6 Dec 2024 11:14:01 +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=\"egz94B5O\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1733480041;\n\tbh=SaitqzZTDlM3ZfuQ4qpicIQfI4erfuEpujcKvfB2nmo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=egz94B5OE/6FMcdnKpMgpDIU1YKak+d8tU02rT6kGY6GNQF2M5/NGd5nZOPqt+zwu\n\tSizrfbL4uj51dD0tSh1fKlEGLywen559s1A+wrvcqRG0XFX/ebWdnpaFCwI/FtcUxP\n\tu/2jhGZ8UpXjB4hoODT7yVmvG3sKWBtffEGUY9iA=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"[PATCH v3 15/17] pipeline: rkisp1: Fix config validation when\n\tdewarper is used","Date":"Fri,  6 Dec 2024 11:13:37 +0100","Message-ID":"<20241206101344.767170-16-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>","References":"<20241206101344.767170-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"When the dewarper is used, config->validate() needs to take the\nrestrictions of the dewarper into account. Add the corresponding checks.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nSigned-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(-)","diff":"diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 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+\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+\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","prefixes":["v3","15/17"]}