Patch Detail
Show a patch.
GET /api/1.1/patches/18557/?format=api
{ "id": 18557, "url": "https://patchwork.libcamera.org/api/1.1/patches/18557/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18557/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230426131057.21550-10-naush@raspberrypi.com>", "date": "2023-04-26T13:10:53", "name": "[libcamera-devel,09/13] ipa: raspberrypi: agc: Move weights out of AGC", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "147694391131f001ae09d3b4dfa2d3931e3f651b", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18557/mbox/", "series": [ { "id": 3847, "url": "https://patchwork.libcamera.org/api/1.1/series/3847/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3847", "date": "2023-04-26T13:10:44", "name": "Raspberry Pi: Code refactoring", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3847/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18557/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18557/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 BE6D4BDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 26 Apr 2023 13:13:40 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8B4C6627DF;\n\tWed, 26 Apr 2023 15:13:40 +0200 (CEST)", "from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com\n\t[IPv6:2a00:1450:4864:20::32f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F440627D4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Apr 2023 15:13:38 +0200 (CEST)", "by mail-wm1-x32f.google.com with SMTP id\n\t5b1f17b1804b1-3f19a80a330so30979845e9.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 26 Apr 2023 06:13:38 -0700 (PDT)", "from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tk5-20020adff5c5000000b002f103ca90cdsm15780949wrp.101.2023.04.26.06.13.37\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 26 Apr 2023 06:13:37 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1682514820;\n\tbh=zMnuCMQzW5A9CsO1NyiO6bJ4PVWkLOb/UvsOjK0kGek=;\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=JCScAaSAHwnm+FgW0wCkJRUY8NIipGeSvcpc9sQ6eAWVasYszw3c0tvOHs79DD5wW\n\t+gCTQIoraPNos4xh6uVhnTnmG2R2MvgSqTSLrMdrxudRh2aQAlI1mB+VIfdfvwep2w\n\t6hxfRJqav28WjX1MD8M0bS+s+KVL9tynuDoNufAFZ0zNh+czBNQHZ/mfBWmu8P3mJl\n\tWsi412yR/hakDQqGW4ujishEoAVPUCUTyk+TUnrW3o6NZLci2aSBqSbHdLkoafCoi6\n\t86C/zU6KwF29sa0PNe2lQaqf3Gwbys1SSgC1VCAAMWFObOEs5/2v+n7JKYZ42A+pgb\n\tqVvsaPl4HgF8Q==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1682514818; x=1685106818;\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=vY50V2GR0AO2EgoMd7bJCL30YLCQYhdChGBDbVstcds=;\n\tb=c5P0ORXUdV2ZBfFNa18U+wWn5j7SKFMLBjEKDxuzwgOUHYTrS7HvnDPGgZP/EEPi9s\n\t41HNpFXBX3a9rnYe2joLCAYGhVyFYFP/vB1eU+D3jX74UU+IYq9o0U0/wTDYGS6t4h/Z\n\tf2s0YDq41hfePl2t4tG55BlBEM/blTDgSKMjYc4S9jQJvdRrd2kQ5up4fQK57iX/oQjw\n\tbFyCSm4L7otZgGLIoaZqENWFNFX1vAnofVfo3FuaR9TlE18NkyLm0K8z3mcuusI6GyeT\n\tSnxiUlKXYN61fDtT2PUxi6/fRKuvKe9gRXCh1tFmlGxT/gcz5kpP43egEnBtKVSbos6n\n\tt+qA==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"c5P0ORXU\"; dkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1682514818; x=1685106818;\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=vY50V2GR0AO2EgoMd7bJCL30YLCQYhdChGBDbVstcds=;\n\tb=kBD9tQZX291Bq394ah3gD7gqv3L38BzwFF7O4vapI4eMMhKN7kat5cyZZwC+GMgDE7\n\tehD2KDGBP7W/2z2vv5+rbGG/h5B+X7YvFu+zemfeyc73z12f1oz9v42xG9seIlQjSuuN\n\t5z7cVaash+24Qpl3fkMpZ5PCNsaf3+KM10///eal7AIaQF9OMWKyr54BoTO2dsgppSOG\n\tscDTKFaD38nsrbHaKYT/IMcKOg5qGhcqmSD3hn64JnlwDTX5Qc7ukSXIL90lg00rPR7v\n\t1bqV/ejKk6qEbj1MmDHHqWr4dkj0Ju4X/BHD67U7JI+92vWwXOKQKa/hBieIJJERZywq\n\tBRlQ==", "X-Gm-Message-State": "AAQBX9c9y52atWIShVJgKrU8ZJhL7lwYk14GuA4iQlmiDzDM87PSi9eQ\n\txqHk35kW66kitaUNp3dHhSdL6+7DSrBLY3OMKSXSrQ==", "X-Google-Smtp-Source": "AKy350bXDvIGNYrqRVxDWIjARAuxsBchkgMfn7p46JGzsjaVVWv5Amf+qMbdXAsPKxmiezDk5S73Fw==", "X-Received": "by 2002:a7b:cb96:0:b0:3f0:5519:9049 with SMTP id\n\tm22-20020a7bcb96000000b003f055199049mr13944098wmi.8.1682514817672; \n\tWed, 26 Apr 2023 06:13:37 -0700 (PDT)", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 26 Apr 2023 14:10:53 +0100", "Message-Id": "<20230426131057.21550-10-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.34.1", "In-Reply-To": "<20230426131057.21550-1-naush@raspberrypi.com>", "References": "<20230426131057.21550-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 09/13] ipa: raspberrypi: agc: Move weights\n\tout of AGC", "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": "From: David Plowman <david.plowman@raspberrypi.com>\n\nThe region weights for the the AGC zones were previously handled by the\nAGC algorithm. Now it's the IPA (vc4.cpp) that applies them directly\nto the statistics that we pass to the AGC.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/controller/agc_algorithm.h | 3 +++\n src/ipa/rpi/controller/rpi/agc.cpp | 27 +++++++++++++++++---------\n src/ipa/rpi/controller/rpi/agc.h | 1 +\n src/ipa/rpi/vc4/vc4.cpp | 26 ++++++++++++++++++-------\n 4 files changed, 41 insertions(+), 16 deletions(-)", "diff": "diff --git a/src/ipa/rpi/controller/agc_algorithm.h b/src/ipa/rpi/controller/agc_algorithm.h\nindex 36e6c11058ee..b6949daa7135 100644\n--- a/src/ipa/rpi/controller/agc_algorithm.h\n+++ b/src/ipa/rpi/controller/agc_algorithm.h\n@@ -6,6 +6,8 @@\n */\n #pragma once\n \n+#include <vector>\n+\n #include <libcamera/base/utils.h>\n \n #include \"algorithm.h\"\n@@ -18,6 +20,7 @@ public:\n \tAgcAlgorithm(Controller *controller) : Algorithm(controller) {}\n \t/* An AGC algorithm must provide the following: */\n \tvirtual unsigned int getConvergenceFrames() const = 0;\n+\tvirtual std::vector<double> const &getWeights() const = 0;\n \tvirtual void setEv(double ev) = 0;\n \tvirtual void setFlickerPeriod(libcamera::utils::Duration flickerPeriod) = 0;\n \tvirtual void setFixedShutter(libcamera::utils::Duration fixedShutter) = 0;\ndiff --git a/src/ipa/rpi/controller/rpi/agc.cpp b/src/ipa/rpi/controller/rpi/agc.cpp\nindex e6fb7b8dbeb3..e79c82e2e65b 100644\n--- a/src/ipa/rpi/controller/rpi/agc.cpp\n+++ b/src/ipa/rpi/controller/rpi/agc.cpp\n@@ -292,6 +292,18 @@ unsigned int Agc::getConvergenceFrames() const\n \t\treturn config_.convergenceFrames;\n }\n \n+std::vector<double> const &Agc::getWeights() const\n+{\n+\t/*\n+\t * In case someone calls setMeteringMode and then this before the\n+\t * algorithm has run and updated the meteringMode_ pointer.\n+\t */\n+\tauto it = config_.meteringModes.find(meteringModeName_);\n+\tif (it == config_.meteringModes.end())\n+\t\treturn meteringMode_->weights;\n+\treturn it->second.weights;\n+}\n+\n void Agc::setEv(double ev)\n {\n \tev_ = ev;\n@@ -595,19 +607,16 @@ static double computeInitialY(StatisticsPtr &stats, AwbStatus const &awb,\n \tASSERT(weights.size() == stats->agcRegions.numRegions());\n \n \t/*\n-\t * Note how the calculation below means that equal weights give you\n-\t * \"average\" metering (i.e. all pixels equally important).\n+\t * Note that the weights are applied by the IPA to the statistics directly,\n+\t * before they are given to us here.\n \t */\n \tdouble rSum = 0, gSum = 0, bSum = 0, pixelSum = 0;\n \tfor (unsigned int i = 0; i < stats->agcRegions.numRegions(); i++) {\n \t\tauto ®ion = stats->agcRegions.get(i);\n-\t\tdouble rAcc = std::min<double>(region.val.rSum * gain, (maxVal - 1) * region.counted);\n-\t\tdouble gAcc = std::min<double>(region.val.gSum * gain, (maxVal - 1) * region.counted);\n-\t\tdouble bAcc = std::min<double>(region.val.bSum * gain, (maxVal - 1) * region.counted);\n-\t\trSum += rAcc * weights[i];\n-\t\tgSum += gAcc * weights[i];\n-\t\tbSum += bAcc * weights[i];\n-\t\tpixelSum += region.counted * weights[i];\n+\t\trSum += std::min<double>(region.val.rSum * gain, (maxVal - 1) * region.counted);\n+\t\tgSum += std::min<double>(region.val.gSum * gain, (maxVal - 1) * region.counted);\n+\t\tbSum += std::min<double>(region.val.bSum * gain, (maxVal - 1) * region.counted);\n+\t\tpixelSum += region.counted;\n \t}\n \tif (pixelSum == 0.0) {\n \t\tLOG(RPiAgc, Warning) << \"computeInitialY: pixelSum is zero\";\ndiff --git a/src/ipa/rpi/controller/rpi/agc.h b/src/ipa/rpi/controller/rpi/agc.h\nindex 4e5f272fac78..939f97295a02 100644\n--- a/src/ipa/rpi/controller/rpi/agc.h\n+++ b/src/ipa/rpi/controller/rpi/agc.h\n@@ -69,6 +69,7 @@ public:\n \tchar const *name() const override;\n \tint read(const libcamera::YamlObject ¶ms) override;\n \tunsigned int getConvergenceFrames() const override;\n+\tstd::vector<double> const &getWeights() const override;\n \tvoid setEv(double ev) override;\n \tvoid setFlickerPeriod(libcamera::utils::Duration flickerPeriod) override;\n \tvoid setMaxShutter(libcamera::utils::Duration maxShutter) override;\ndiff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp\nindex 0d929cda6c4a..0e022c2aeed3 100644\n--- a/src/ipa/rpi/vc4/vc4.cpp\n+++ b/src/ipa/rpi/vc4/vc4.cpp\n@@ -211,13 +211,25 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span<uint8_t> mem)\n \t\t\t\t\t\tstats->awb_stats[i].counted,\n \t\t\t\t\t\tstats->awb_stats[i].notcounted });\n \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-\t\t\t\t\t\t stats->agc_stats[i].b_sum << scale },\n-\t\t\t\t\t\tstats->agc_stats[i].counted,\n-\t\t\t\t\t\tstats->awb_stats[i].notcounted });\n+\tRPiController::AgcAlgorithm *agc = dynamic_cast<RPiController::AgcAlgorithm *>(\n+\t\tcontroller_.getAlgorithm(\"agc\"));\n+\tif (!agc) {\n+\t\tLOG(IPARPI, Debug) << \"No AGC algorithm - not copying statistics\";\n+\t\tstatistics->agcRegions.init(0);\n+\t} else {\n+\t\tstatistics->agcRegions.init(hw.agcRegions);\n+\t\tconst std::vector<double> &weights = agc->getWeights();\n+\t\tfor (i = 0; i < statistics->agcRegions.numRegions(); i++) {\n+\t\t\tuint64_t rSum = (stats->agc_stats[i].r_sum << scale) * weights[i];\n+\t\t\tuint64_t gSum = (stats->agc_stats[i].g_sum << scale) * weights[i];\n+\t\t\tuint64_t bSum = (stats->agc_stats[i].b_sum << scale) * weights[i];\n+\t\t\tuint32_t counted = stats->agc_stats[i].counted * weights[i];\n+\t\t\tuint32_t notcounted = stats->agc_stats[i].notcounted * weights[i];\n+\t\t\tstatistics->agcRegions.set(i, { { rSum, gSum, bSum },\n+\t\t\t\t\t\t\tcounted,\n+\t\t\t\t\t\t\tnotcounted });\n+\t\t}\n+\t}\n \n \tstatistics->focusRegions.init(hw.focusRegions);\n \tfor (i = 0; i < statistics->focusRegions.numRegions(); i++)\n", "prefixes": [ "libcamera-devel", "09/13" ] }