{"id":22990,"url":"https://patchwork.libcamera.org/api/1.1/patches/22990/?format=json","web_url":"https://patchwork.libcamera.org/patch/22990/","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":"<20250319161152.63625-13-stefan.klug@ideasonboard.com>","date":"2025-03-19T16:11:17","name":"[v2,12/17] libipa: awb: Make result of gainsFromColourTemp optional","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9728cd9acc9651ab05d1fa75ee1dadc3ac53584f","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/22990/mbox/","series":[{"id":5071,"url":"https://patchwork.libcamera.org/api/1.1/series/5071/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5071","date":"2025-03-19T16:11:05","name":"Some rkisp1 awb improvements","version":2,"mbox":"https://patchwork.libcamera.org/series/5071/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/22990/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/22990/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 9005AC32FE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 Mar 2025 16:12:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 43F4568962;\n\tWed, 19 Mar 2025 17:12:34 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AC7E6896E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Mar 2025 17:12:32 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:760:e5ca:4814:99c7])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 521888FA;\n\tWed, 19 Mar 2025 17:10:49 +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=\"CSwOuKgB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1742400649;\n\tbh=sNWizC2Z4QwnejZ9TRAllyVdNWR0kF74gIlyotl2gH0=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CSwOuKgBAgJ+nxvLO1/8JdShflBg7K5XI6E+TVz1jATYdubwZhjbrsOXHJAXpvGXW\n\tk4m497ff8BF6eRbPvMRiirLYFT9JFmJ1KiZbV37+3OdzQ+gtuUxAR0M0n3UBkJ26eH\n\ti5++588fkPBWllVm7hhZ3qrKLIcou1drsXt45xTg=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v2 12/17] libipa: awb: Make result of gainsFromColourTemp\n\toptional","Date":"Wed, 19 Mar 2025 17:11:17 +0100","Message-ID":"<20250319161152.63625-13-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20250319161152.63625-1-stefan.klug@ideasonboard.com>","References":"<20250319161152.63625-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 color 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\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Added this patch\n---\n src/ipa/libipa/awb.cpp            |  2 +-\n src/ipa/libipa/awb.h              |  2 +-\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 | 16 +++++++++++-----\n 7 files changed, 20 insertions(+), 14 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..789a1d534f9a 100644\n--- a/src/ipa/libipa/awb.h\n+++ b/src/ipa/libipa/awb.h\n@@ -39,7 +39,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 5e067e50cd52..58b8370d2c61 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@@ -184,10 +188,12 @@ void Awb::queueRequest(IPAContext &context,\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\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\tawb.manual.temperatureK = *colourTemperature;\n-\t\tupdate = true;\n \t}\n \n \tif (update)\n","prefixes":["v2","12/17"]}