{"id":18471,"url":"https://patchwork.libcamera.org/api/1.1/patches/18471/?format=json","web_url":"https://patchwork.libcamera.org/patch/18471/","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":"<20230327122030.11756-3-naush@raspberrypi.com>","date":"2023-03-27T12:20:22","name":"[libcamera-devel,v2,02/10] ipa: raspberrypi: Add hardware configuration to the controller","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"befe13d32c3bf5c74eb6d2e41193af6a2715c6c1","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18471/mbox/","series":[{"id":3819,"url":"https://patchwork.libcamera.org/api/1.1/series/3819/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3819","date":"2023-03-27T12:20:20","name":"Raspberry Pi: Generalised algorithms","version":2,"mbox":"https://patchwork.libcamera.org/series/3819/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18471/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18471/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 598D2BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Mar 2023 12:20:46 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 156B662744;\n\tMon, 27 Mar 2023 14:20:46 +0200 (CEST)","from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com\n\t[IPv6:2607:f8b0:4864:20::d2b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C000862740\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 14:20:43 +0200 (CEST)","by mail-io1-xd2b.google.com with SMTP id k17so3803090iob.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Mar 2023 05:20:43 -0700 (PDT)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tr7-20020a5edb47000000b00758ff97aaedsm3239026iop.16.2023.03.27.05.20.41\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 27 Mar 2023 05:20:41 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1679919646;\n\tbh=p8bjwYcPHre60o2C+WXibtxyErkFZE3S7agTpN+m80M=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=1J16qOH79mlFamkgG4cpg/m8nNvWo6/HTZfHK/mOAbYTBrYb0NkajKFPdPGwajZaG\n\tl98GvRG+AsiEpixn51SdO4FtoWTktT2Q00IFBRVHo2bRU+8aNNyr92z6e7jb7f8Cjs\n\tyvCOXUD018anwfsSppMcdBpR04xaX9prmtiRegQtiH7icrZOKYIhKtnHJqlMJV4nXh\n\tZoTqhILwavN6NhuCow4kSiOUdL+6df80+5WS59kgFrbQcUSFxzFQTKH/pUyH0+uDaU\n\tCBwiVheTKa1Mws51SXd/aHthR/DjlDrGjhysqDLaP6wtOnCZIR8JWiKrzKXc2LNFKZ\n\tI8fCTx+Z1OROg==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1679919642;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=budr3U+RGAt0DckKXPoFcDC9ZFRMq47CvRp3MWMf5AA=;\n\tb=KxeYuUtzVgyF6J1Lo9lIyxmxSfYKUCGQh05EG7Qf16CjEkKTt5iVNlxcFl52S/w/Qy\n\t8QL51NdGQD/Ra6U6PSU/3tkACYH3RO86rmgpWYtvaT/OkNJPC80UN2NpKpNBwN0OlQp6\n\tmbOVqGTx5I4Q9pO7/p9kOPy+RKHlQg8A3G7PMw/gafLDoNznoYfB3SR9lj+P2bNvjxMl\n\tD7Y5cXNHNe4b4EXYjWJqtK9PiqyhwGm7GTRxdmgzkjSkj77M7j7lWznsmCEQx25tQQM/\n\trx7JZlU1PLMg7Dl7eI4472MLfn2adk5zN6HXuBt6Jc4ar6DJb2fcgLh9SeH833Cz4n0G\n\t3Zbg=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"KxeYuUtz\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1679919642;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=budr3U+RGAt0DckKXPoFcDC9ZFRMq47CvRp3MWMf5AA=;\n\tb=r5iWsgPERR2fSGKg3I9C+M9vV14g+5Qxvwcftd5oW3EM59d11XKev2G3vuXhL8KTjw\n\t5ZO0Twey/XSvUz+IDvoAlSuvqfsrXY9P+X+7q5d9bWVj4c7XpG+OIa8FElqVgMq1UTaC\n\tZusWXDHrRM74g/7EVzUH7Cm/siKQVD0REWNQafGa5P6aYWT+8AN0TdqiwntEEqT+qNku\n\tLvSnjOzvRtqtHRdThUNp4QxaeXpOeRi0CPosDqwInAIVIymMOQKse7cEAgscpdfThjiB\n\t3pZWAYjYk9zRnu1yaVxX4aC8MX5j05SEwDYLQ0FZZeFO9QeRdIJAQHwjKSySbm2dqwhO\n\t3wog==","X-Gm-Message-State":"AO0yUKVrM96pLcb3dqPkFAmlAyRxKI9cWnMNtp9CvLWce90vcIhbpViX\n\thS5knarksy1aCxKHbMbgRE62/ypZSSJtth3hP3Fpsw==","X-Google-Smtp-Source":"AK7set8O3NSZzJMD7ctnUOuif0Ol+ZZxLCGhZxijB5a9GZkwVFLc7qSJTamFgHw+fdHAm8rYhHARtQ==","X-Received":"by 2002:a6b:e50f:0:b0:758:10a7:6813 with SMTP id\n\ty15-20020a6be50f000000b0075810a76813mr8803664ioc.16.1679919642083; \n\tMon, 27 Mar 2023 05:20:42 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 27 Mar 2023 13:20:22 +0100","Message-Id":"<20230327122030.11756-3-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20230327122030.11756-1-naush@raspberrypi.com>","References":"<20230327122030.11756-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 02/10] ipa: raspberrypi: Add hardware\n\tconfiguration to the controller","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":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a new Controller::HardwareConfig structure that captures the\nhardware statistics grid/histogram sizes and pipeline widths. This\nensures there is a single centralised places for these parameters.\n\nAdd a getHardwareConfig() helper function to retrieve these values for a\ngiven hardware target.\n\nUpdate the statistics populating routine in the IPA to use the values\nfrom this structure instead of the hardcoded numbers.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/algorithm.h    |  4 +++\n src/ipa/raspberrypi/controller/controller.cpp | 31 +++++++++++++++++++\n src/ipa/raspberrypi/controller/controller.h   | 11 +++++++\n src/ipa/raspberrypi/raspberrypi.cpp           | 21 +++++--------\n 4 files changed, 54 insertions(+), 13 deletions(-)","diff":"diff --git a/src/ipa/raspberrypi/controller/algorithm.h b/src/ipa/raspberrypi/controller/algorithm.h\nindex 7c22fbe4945c..4aa814ebbebd 100644\n--- a/src/ipa/raspberrypi/controller/algorithm.h\n+++ b/src/ipa/raspberrypi/controller/algorithm.h\n@@ -45,6 +45,10 @@ public:\n \t{\n \t\treturn controller_->getTarget();\n \t}\n+\tconst Controller::HardwareConfig &getHardwareConfig() const\n+\t{\n+\t\treturn controller_->getHardwareConfig();\n+\t}\n \n private:\n \tController *controller_;\ndiff --git a/src/ipa/raspberrypi/controller/controller.cpp b/src/ipa/raspberrypi/controller/controller.cpp\nindex a6250ee140b0..fa1721130783 100644\n--- a/src/ipa/raspberrypi/controller/controller.cpp\n+++ b/src/ipa/raspberrypi/controller/controller.cpp\n@@ -20,6 +20,25 @@ using namespace libcamera;\n \n LOG_DEFINE_CATEGORY(RPiController)\n \n+static const std::map<std::string, Controller::HardwareConfig> HardwareConfigMap = {\n+\t{\n+\t\t\"bcm2835\",\n+\t\t{\n+\t\t\t/*\n+\t\t\t * There are only ever 15 AGC regions computed by the firmware\n+\t\t\t * due to zoning, but the HW defines AGC_REGIONS == 16!\n+\t\t\t */\n+\t\t\t.agcRegions = { 15 , 1 },\n+\t\t\t.agcZoneWeights = { 15 , 1 },\n+\t\t\t.awbRegions = { 16, 12 },\n+\t\t\t.focusRegions = { 4, 3 },\n+\t\t\t.numHistogramBins = 128,\n+\t\t\t.numGammaPoints = 33,\n+\t\t\t.pipelineWidth = 13\n+\t\t}\n+\t},\n+};\n+\n Controller::Controller()\n \t: switchModeCalled_(false)\n {\n@@ -148,3 +167,15 @@ const std::string &Controller::getTarget() const\n {\n \treturn target_;\n }\n+\n+const Controller::HardwareConfig &Controller::getHardwareConfig() const\n+{\n+\tauto cfg = HardwareConfigMap.find(getTarget());\n+\n+\t/*\n+\t * This really should not happen, the IPA ought to validate the target\n+\t * on initialisation.\n+\t */\n+\tASSERT(cfg != HardwareConfigMap.end());\n+\treturn cfg->second;\n+}\ndiff --git a/src/ipa/raspberrypi/controller/controller.h b/src/ipa/raspberrypi/controller/controller.h\nindex 24e02903d438..c6af5cd6c7d4 100644\n--- a/src/ipa/raspberrypi/controller/controller.h\n+++ b/src/ipa/raspberrypi/controller/controller.h\n@@ -37,6 +37,16 @@ typedef std::unique_ptr<Algorithm> AlgorithmPtr;\n class Controller\n {\n public:\n+\tstruct HardwareConfig {\n+\t\tlibcamera::Size agcRegions;\n+\t\tlibcamera::Size agcZoneWeights;\n+\t\tlibcamera::Size awbRegions;\n+\t\tlibcamera::Size focusRegions;\n+\t\tunsigned int numHistogramBins;\n+\t\tunsigned int numGammaPoints;\n+\t\tunsigned int pipelineWidth;\n+\t};\n+\n \tController();\n \t~Controller();\n \tint read(char const *filename);\n@@ -47,6 +57,7 @@ public:\n \tMetadata &getGlobalMetadata();\n \tAlgorithm *getAlgorithm(std::string const &name) const;\n \tconst std::string &getTarget() const;\n+\tconst HardwareConfig &getHardwareConfig() const;\n \n protected:\n \tint createAlgorithm(const std::string &name, const libcamera::YamlObject &params);\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 86359538cf67..b64cb96e2dde 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -1392,20 +1392,19 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n {\n \tusing namespace RPiController;\n \n+\tconst Controller::HardwareConfig &hw = controller_.getHardwareConfig();\n \tunsigned int i;\n \tStatisticsPtr statistics =\n \t\tstd::make_unique<Statistics>(Statistics::AgcStatsPos::PreWb, Statistics::ColourStatsPos::PostLsc);\n \n \t/* RGB histograms are not used, so do not populate them. */\n-\tstatistics->yHist = RPiController::Histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS);\n+\tstatistics->yHist = RPiController::Histogram(stats->hist[0].g_hist,\n+\t\t\t\t\t\t     hw.numHistogramBins);\n \n-\t/*\n-\t * All region sums are based on a 13-bit pipeline bit-depth. Normalise\n-\t * this to 16-bits for the AGC/AWB/ALSC algorithms.\n-\t */\n-\tconstexpr unsigned int scale = Statistics::NormalisationFactorPow2 - 13;\n+\t/* All region sums are based on a 16-bit normalised pipeline bit-depth. */\n+\tunsigned int scale = Statistics::NormalisationFactorPow2 - hw.pipelineWidth;\n \n-\tstatistics->awbRegions.init({ DEFAULT_AWB_REGIONS_X, DEFAULT_AWB_REGIONS_Y });\n+\tstatistics->awbRegions.init(hw.awbRegions);\n \tfor (i = 0; i < statistics->awbRegions.numRegions(); i++)\n \t\tstatistics->awbRegions.set(i, { { stats->awb_stats[i].r_sum << scale,\n \t\t\t\t\t\t  stats->awb_stats[i].g_sum << scale,\n@@ -1413,11 +1412,7 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n \t\t\t\t\t\tstats->awb_stats[i].counted,\n \t\t\t\t\t\tstats->awb_stats[i].notcounted });\n \n-\t/*\n-\t * There are only ever 15 regions computed by the firmware due to zoning,\n-\t * but the HW defines AGC_REGIONS == 16!\n-\t */\n-\tstatistics->agcRegions.init(15);\n+\tstatistics->agcRegions.init(hw.agcRegions);\n \tfor (i = 0; i < statistics->agcRegions.numRegions(); i++)\n \t\tstatistics->agcRegions.set(i, { { stats->agc_stats[i].r_sum << scale,\n \t\t\t\t\t\t  stats->agc_stats[i].g_sum << scale,\n@@ -1425,7 +1420,7 @@ RPiController::StatisticsPtr IPARPi::fillStatistics(bcm2835_isp_stats *stats) co\n \t\t\t\t\t\tstats->agc_stats[i].counted,\n \t\t\t\t\t\tstats->awb_stats[i].notcounted });\n \n-\tstatistics->focusRegions.init({ 4, 3 });\n+\tstatistics->focusRegions.init(hw.focusRegions);\n \tfor (i = 0; i < statistics->focusRegions.numRegions(); i++)\n \t\tstatistics->focusRegions.set(i, { stats->focus_stats[i].contrast_val[1][1] / 1000,\n \t\t\t\t\t\t  stats->focus_stats[i].contrast_val_num[1][1],\n","prefixes":["libcamera-devel","v2","02/10"]}