Patch Detail
Show a patch.
GET /api/1.1/patches/23129/?format=api
{ "id": 23129, "url": "https://patchwork.libcamera.org/api/1.1/patches/23129/?format=api", "web_url": "https://patchwork.libcamera.org/patch/23129/", "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": "<20250403154925.382973-14-stefan.klug@ideasonboard.com>", "date": "2025-04-03T15:49:18", "name": "[v3,13/16] libipa: awb: Make result of gainsFromColourTemp optional", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "2ca6250b9e438a9ce57aff52bdf46105ce23f692", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/1.1/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/23129/mbox/", "series": [ { "id": 5111, "url": "https://patchwork.libcamera.org/api/1.1/series/5111/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5111", "date": "2025-04-03T15:49:05", "name": "Some rkisp1 awb improvements", "version": 3, "mbox": "https://patchwork.libcamera.org/series/5111/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/23129/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/23129/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 48C0DC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 3 Apr 2025 15:50:15 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 07E0D68AB0;\n\tThu, 3 Apr 2025 17:50:15 +0200 (CEST)", "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 CDC3268AAA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 3 Apr 2025 17:50:13 +0200 (CEST)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F04CC1624;\n\tThu, 3 Apr 2025 17:48:19 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"O5xNAHxn\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743695300;\n\tbh=0EBIs75tGHiJIMtf4sqRcoFq8xrksXXMdoCdOFfqdYk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=O5xNAHxnxIhvJNNLOPmiLWp0FTlsA/fTAl/FvUbcpFL0TcR8W+u6T4oLgrzvNdN78\n\t5fEJnPNZwuZMcym8oispdND8kFYFiwLJuIN3LjAqPEvWu+endpUXCFAffpAqOxZf2j\n\tE9Omv0aeTNLnyq2prRmpvpD26nlQs0P6LiIo9Pmc=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>", "Subject": "[PATCH v3 13/16] libipa: awb: Make result of gainsFromColourTemp\n\toptional", "Date": "Thu, 3 Apr 2025 17:49:18 +0200", "Message-ID": "<20250403154925.382973-14-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.43.0", "In-Reply-To": "<20250403154925.382973-1-stefan.klug@ideasonboard.com>", "References": "<20250403154925.382973-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": "In the grey world AWB case, if no colour gains are contained in the\ntuning file, the colour gains get reset to 1 when the colour temperature\nis set manually. This is unexpected and undesirable. Allow the\ngainsFromColourTemp() function to return a std::nullopt to handle that\ncase.\n\nWhile at it, remove an unnecessary import from rkisp1/algorithms/awb.h.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Added this patch\n\nChanges in v3:\n- Added #include <optional> to libipa/awb.h\n- Removed stray include from rkisp1/awb.h\n- Reordered colour temperature assignment for better clarity\n---\n src/ipa/libipa/awb.cpp | 2 +-\n src/ipa/libipa/awb.h | 3 ++-\n src/ipa/libipa/awb_bayes.cpp | 4 ++--\n src/ipa/libipa/awb_bayes.h | 2 +-\n src/ipa/libipa/awb_grey.cpp | 6 +++---\n src/ipa/libipa/awb_grey.h | 2 +-\n src/ipa/rkisp1/algorithms/awb.cpp | 18 ++++++++++++------\n src/ipa/rkisp1/algorithms/awb.h | 2 --\n 8 files changed, 22 insertions(+), 17 deletions(-)", "diff": "diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp\nindex 925fac232709..214bac8b56a6 100644\n--- a/src/ipa/libipa/awb.cpp\n+++ b/src/ipa/libipa/awb.cpp\n@@ -114,7 +114,7 @@ namespace ipa {\n * does not take any statistics into account. It is used to compute the colour\n * gains when the user manually specifies a colour temperature.\n *\n- * \\return The colour gains\n+ * \\return The colour gains or std::nullopt if the conversion is not possible\n */\n \n /**\ndiff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h\nindex 4bab7a451ce5..f4a86038635f 100644\n--- a/src/ipa/libipa/awb.h\n+++ b/src/ipa/libipa/awb.h\n@@ -8,6 +8,7 @@\n #pragma once\n \n #include <map>\n+#include <optional>\n \n #include <libcamera/control_ids.h>\n #include <libcamera/controls.h>\n@@ -39,7 +40,7 @@ public:\n \n \tvirtual int init(const YamlObject &tuningData) = 0;\n \tvirtual AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) = 0;\n-\tvirtual RGB<double> gainsFromColourTemperature(double colourTemperature) = 0;\n+\tvirtual std::optional<RGB<double>> gainsFromColourTemperature(double colourTemperature) = 0;\n \n \tconst ControlInfoMap::Map &controls() const\n \t{\ndiff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp\nindex d1d0eaf0e68f..d2bcbd83d7f8 100644\n--- a/src/ipa/libipa/awb_bayes.cpp\n+++ b/src/ipa/libipa/awb_bayes.cpp\n@@ -270,7 +270,7 @@ void AwbBayes::handleControls(const ControlList &controls)\n \t}\n }\n \n-RGB<double> AwbBayes::gainsFromColourTemperature(double colourTemperature)\n+std::optional<RGB<double>> AwbBayes::gainsFromColourTemperature(double colourTemperature)\n {\n \t/*\n \t * \\todo In the RaspberryPi code, the ct curve was interpolated in\n@@ -278,7 +278,7 @@ RGB<double> AwbBayes::gainsFromColourTemperature(double colourTemperature)\n \t * intuitive, as the gains are in linear space. But I can't prove it.\n \t */\n \tconst auto &gains = colourGainCurve_.getInterpolated(colourTemperature);\n-\treturn { { gains[0], 1.0, gains[1] } };\n+\treturn RGB<double>{ { gains[0], 1.0, gains[1] } };\n }\n \n AwbResult AwbBayes::calculateAwb(const AwbStats &stats, unsigned int lux)\ndiff --git a/src/ipa/libipa/awb_bayes.h b/src/ipa/libipa/awb_bayes.h\nindex bb933038d6d2..47ef3cce4d58 100644\n--- a/src/ipa/libipa/awb_bayes.h\n+++ b/src/ipa/libipa/awb_bayes.h\n@@ -27,7 +27,7 @@ public:\n \n \tint init(const YamlObject &tuningData) override;\n \tAwbResult calculateAwb(const AwbStats &stats, unsigned int lux) override;\n-\tRGB<double> gainsFromColourTemperature(double temperatureK) override;\n+\tstd::optional<RGB<double>> gainsFromColourTemperature(double temperatureK) override;\n \tvoid handleControls(const ControlList &controls) override;\n \n private:\ndiff --git a/src/ipa/libipa/awb_grey.cpp b/src/ipa/libipa/awb_grey.cpp\nindex d3d2132b8869..d252edb2b6c6 100644\n--- a/src/ipa/libipa/awb_grey.cpp\n+++ b/src/ipa/libipa/awb_grey.cpp\n@@ -98,15 +98,15 @@ AwbResult AwbGrey::calculateAwb(const AwbStats &stats, [[maybe_unused]] unsigned\n * \\return The colour gains if a colour temperature curve is available,\n * [1, 1, 1] otherwise.\n */\n-RGB<double> AwbGrey::gainsFromColourTemperature(double colourTemperature)\n+std::optional<RGB<double>> AwbGrey::gainsFromColourTemperature(double colourTemperature)\n {\n \tif (!colourGainCurve_) {\n \t\tLOG(Awb, Error) << \"No gains defined\";\n-\t\treturn RGB<double>({ 1.0, 1.0, 1.0 });\n+\t\treturn std::nullopt;\n \t}\n \n \tauto gains = colourGainCurve_->getInterpolated(colourTemperature);\n-\treturn { { gains[0], 1.0, gains[1] } };\n+\treturn RGB<double>{ { gains[0], 1.0, gains[1] } };\n }\n \n } /* namespace ipa */\ndiff --git a/src/ipa/libipa/awb_grey.h b/src/ipa/libipa/awb_grey.h\nindex 7ec7bfa5da9a..f82a368d11cc 100644\n--- a/src/ipa/libipa/awb_grey.h\n+++ b/src/ipa/libipa/awb_grey.h\n@@ -25,7 +25,7 @@ public:\n \n \tint init(const YamlObject &tuningData) override;\n \tAwbResult calculateAwb(const AwbStats &stats, unsigned int lux) override;\n-\tRGB<double> gainsFromColourTemperature(double colourTemperature) override;\n+\tstd::optional<RGB<double>> gainsFromColourTemperature(double colourTemperature) override;\n \n private:\n \tstd::optional<Interpolator<Vector<double, 2>>> colourGainCurve_;\ndiff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp\nindex 0795b8e5b1e1..f5415a0bb99d 100644\n--- a/src/ipa/rkisp1/algorithms/awb.cpp\n+++ b/src/ipa/rkisp1/algorithms/awb.cpp\n@@ -125,8 +125,12 @@ int Awb::configure(IPAContext &context,\n \t\t const IPACameraSensorInfo &configInfo)\n {\n \tcontext.activeState.awb.manual.gains = RGB<double>{ 1.0 };\n-\tcontext.activeState.awb.automatic.gains =\n-\t\tawbAlgo_->gainsFromColourTemperature(kDefaultColourTemperature);\n+\tauto gains = awbAlgo_->gainsFromColourTemperature(kDefaultColourTemperature);\n+\tif (gains)\n+\t\tcontext.activeState.awb.automatic.gains = *gains;\n+\telse\n+\t\tcontext.activeState.awb.automatic.gains = RGB<double>{ 1.0 };\n+\n \tcontext.activeState.awb.autoEnabled = true;\n \tcontext.activeState.awb.manual.temperatureK = kDefaultColourTemperature;\n \tcontext.activeState.awb.automatic.temperatureK = kDefaultColourTemperature;\n@@ -183,11 +187,13 @@ void Awb::queueRequest(IPAContext &context,\n \t\t */\n \t\tupdate = true;\n \t} else if (colourTemperature) {\n-\t\tconst auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature);\n-\t\tawb.manual.gains.r() = gains.r();\n-\t\tawb.manual.gains.b() = gains.b();\n \t\tawb.manual.temperatureK = *colourTemperature;\n-\t\tupdate = true;\n+\t\tconst auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature);\n+\t\tif (gains) {\n+\t\t\tawb.manual.gains.r() = gains->r();\n+\t\t\tawb.manual.gains.b() = gains->b();\n+\t\t\tupdate = true;\n+\t\t}\n \t}\n \n \tif (update)\ndiff --git a/src/ipa/rkisp1/algorithms/awb.h b/src/ipa/rkisp1/algorithms/awb.h\nindex 7e6c3862e699..02651cc732bf 100644\n--- a/src/ipa/rkisp1/algorithms/awb.h\n+++ b/src/ipa/rkisp1/algorithms/awb.h\n@@ -7,8 +7,6 @@\n \n #pragma once\n \n-#include <optional>\n-\n #include \"libcamera/internal/vector.h\"\n \n #include \"libipa/awb.h\"\n", "prefixes": [ "v3", "13/16" ] }