{"id":13897,"url":"https://patchwork.libcamera.org/api/1.1/patches/13897/?format=json","web_url":"https://patchwork.libcamera.org/patch/13897/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210923081625.60276-7-jeanmichel.hautbois@ideasonboard.com>","date":"2021-09-23T08:16:19","name":"[libcamera-devel,06/12] ipa: ipu3: Change limits and split loops in calculateBdsGrid()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"476792d715e8e2f90969706f5cf38d3053c3d5da","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/1.1/people/75/?format=json","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/13897/mbox/","series":[{"id":2548,"url":"https://patchwork.libcamera.org/api/1.1/series/2548/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2548","date":"2021-09-23T08:16:13","name":"Improve ImgU statistics usage","version":1,"mbox":"https://patchwork.libcamera.org/series/2548/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/13897/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/13897/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 2EB7BBF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Sep 2021 08:16:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E056A69192;\n\tThu, 23 Sep 2021 10:16:41 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7BFD86918A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Sep 2021 10:16:31 +0200 (CEST)","from tatooine.ideasonboard.com (unknown\n\t[IPv6:2a01:e0a:169:7140:392e:dcd2:2bf6:d61c])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B08745E;\n\tThu, 23 Sep 2021 10:16:31 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"YVtMax2w\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1632384991;\n\tbh=rBn5Htj5mFaJ/l98t4TJrQ/5QZ3p5ctqQO2EF+pPqJA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=YVtMax2wviwkwbHO0HeqvxiatjHja9ZoEkcdHZR5kjou3gc0ZbFzoXjGY+xf/GTti\n\t6vJYORXQJCZ39vpTQbYjUUMsWxMz+M3zu7hznGfXaVbER4Hd+Fz28E+ljZYvu43Uvv\n\tg9TL9WJ8dVKaxongxDMSAK8r1obKkdWlWX09yqnk=","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 23 Sep 2021 10:16:19 +0200","Message-Id":"<20210923081625.60276-7-jeanmichel.hautbois@ideasonboard.com>","X-Mailer":"git-send-email 2.30.2","In-Reply-To":"<20210923081625.60276-1-jeanmichel.hautbois@ideasonboard.com>","References":"<20210923081625.60276-1-jeanmichel.hautbois@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 06/12] ipa: ipu3: Change limits and split\n\tloops in calculateBdsGrid()","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":"The loops over the width and height of the image when calculating the\nBDS grid parameters are imbricated, but they're actually independent.\nSplit them to reduce the complexity.\n\nWhile at it, change the limits with the known limitations for the grid\nsize.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n---\n src/ipa/ipu3/ipu3.cpp | 66 ++++++++++++++++++++++++++-----------------\n 1 file changed, 40 insertions(+), 26 deletions(-)","diff":"diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex b97aff80..06d9bcb8 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -136,8 +136,18 @@\n  * <linux/intel-ipu3.h> struct ipu3_uapi_gamma_corr_lut for further details.\n  */\n \n+/* Minimum width of a cell of the grid */\n+static constexpr uint32_t kMinCellWidthPerSet = 16;\n+/* Maximum width of a cell of the grid */\n static constexpr uint32_t kMaxCellWidthPerSet = 80;\n+/* Minimum height of a cell of the grid */\n+static constexpr uint32_t kMinCellHeightPerSet = 16;\n+/* Minimum height of a cell of the grid */\n static constexpr uint32_t kMaxCellHeightPerSet = 60;\n+/* Minimum log2 of the width of each cell in pixels of the grid */\n+static constexpr uint32_t kMinCellSizeLog2 = 3;\n+/* Maximum log2 of the width of each cell in pixels of the grid */\n+static constexpr uint32_t kMaxCellSizeLog2 = 6;\n \n namespace libcamera {\n \n@@ -285,41 +295,45 @@ int IPAIPU3::start()\n  * Its input is the BDS output size calculated in the ImgU.\n  * It is limited for now to the simplest method: find the lesser error\n  * with the width/height and respective log2 width/height of the cells.\n- *\n- * \\todo The frame is divided into cells which can be 8x8 => 128x128.\n- * As a smaller cell improves the algorithm precision, adapting the\n- * x_start and y_start parameters of the grid would provoke a loss of\n- * some pixels but would also result in more accurate algorithms.\n  */\n void IPAIPU3::calculateBdsGrid(const Size &bdsOutputSize)\n {\n-\tuint32_t minError = std::numeric_limits<uint32_t>::max();\n \tSize best;\n \tSize bestLog2;\n+\tuint32_t shift;\n \n \t/* Set the BDS output size in the IPAConfiguration structure */\n \tcontext_.configuration.grid.bdsOutputSize = bdsOutputSize;\n \n-\tfor (uint32_t widthShift = 3; widthShift <= 6; ++widthShift) {\n-\t\tuint32_t width = std::min(kMaxCellWidthPerSet,\n-\t\t\t\t\t  bdsOutputSize.width >> widthShift);\n-\t\twidth = width << widthShift;\n-\t\tfor (uint32_t heightShift = 3; heightShift <= 6; ++heightShift) {\n-\t\t\tint32_t height = std::min(kMaxCellHeightPerSet,\n-\t\t\t\t\t\t  bdsOutputSize.height >> heightShift);\n-\t\t\theight = height << heightShift;\n-\t\t\tuint32_t error  = std::abs(static_cast<int>(width - bdsOutputSize.width))\n-\t\t\t\t\t\t\t+ std::abs(static_cast<int>(height - bdsOutputSize.height));\n-\n-\t\t\tif (error > minError)\n-\t\t\t\tcontinue;\n-\n-\t\t\tminError = error;\n-\t\t\tbest.width = width;\n-\t\t\tbest.height = height;\n-\t\t\tbestLog2.width = widthShift;\n-\t\t\tbestLog2.height = heightShift;\n-\t\t}\n+\tuint32_t minError = std::numeric_limits<uint32_t>::max();\n+\tfor (shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) {\n+\t\tuint32_t width = std::clamp(bdsOutputSize.width >> shift,\n+\t\t\t\t\t    kMinCellWidthPerSet,\n+\t\t\t\t\t    kMaxCellWidthPerSet);\n+\n+\t\twidth = width << shift;\n+\t\tuint32_t error = std::abs(static_cast<int>(width - bdsOutputSize.width));\n+\t\tif (error >= minError)\n+\t\t\tcontinue;\n+\n+\t\tminError = error;\n+\t\tbest.width = width;\n+\t\tbestLog2.width = shift;\n+\t}\n+\n+\tfor (shift = kMinCellSizeLog2; shift <= kMaxCellSizeLog2; ++shift) {\n+\t\tuint32_t height = std::clamp(bdsOutputSize.height >> shift,\n+\t\t\t\t\t     kMinCellHeightPerSet,\n+\t\t\t\t\t     kMaxCellHeightPerSet);\n+\n+\t\theight = height << shift;\n+\t\tuint32_t error = std::abs(static_cast<int>(height - bdsOutputSize.height));\n+\t\tif (error >= minError)\n+\t\t\tcontinue;\n+\n+\t\tminError = error;\n+\t\tbest.height = height;\n+\t\tbestLog2.height = shift;\n \t}\n \n \tstruct ipu3_uapi_grid_config &bdsGrid = context_.configuration.grid.bdsGrid;\n","prefixes":["libcamera-devel","06/12"]}