From patchwork Thu Apr 3 15:49:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23129 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 48C0DC327D for ; Thu, 3 Apr 2025 15:50:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 07E0D68AB0; Thu, 3 Apr 2025 17:50:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="O5xNAHxn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CDC3268AAA for ; Thu, 3 Apr 2025 17:50:13 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F04CC1624; Thu, 3 Apr 2025 17:48:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743695300; bh=0EBIs75tGHiJIMtf4sqRcoFq8xrksXXMdoCdOFfqdYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O5xNAHxnxIhvJNNLOPmiLWp0FTlsA/fTAl/FvUbcpFL0TcR8W+u6T4oLgrzvNdN78 5fEJnPNZwuZMcym8oispdND8kFYFiwLJuIN3LjAqPEvWu+endpUXCFAffpAqOxZf2j E9Omv0aeTNLnyq2prRmpvpD26nlQs0P6LiIo9Pmc= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Kieran Bingham Subject: [PATCH v3 13/16] libipa: awb: Make result of gainsFromColourTemp optional 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In the grey world AWB case, if no colour gains are contained in the tuning file, the colour gains get reset to 1 when the colour temperature is set manually. This is unexpected and undesirable. Allow the gainsFromColourTemp() function to return a std::nullopt to handle that case. While at it, remove an unnecessary import from rkisp1/algorithms/awb.h. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v2: - Added this patch Changes in v3: - Added #include to libipa/awb.h - Removed stray include from rkisp1/awb.h - Reordered colour temperature assignment for better clarity --- src/ipa/libipa/awb.cpp | 2 +- src/ipa/libipa/awb.h | 3 ++- src/ipa/libipa/awb_bayes.cpp | 4 ++-- src/ipa/libipa/awb_bayes.h | 2 +- src/ipa/libipa/awb_grey.cpp | 6 +++--- src/ipa/libipa/awb_grey.h | 2 +- src/ipa/rkisp1/algorithms/awb.cpp | 18 ++++++++++++------ src/ipa/rkisp1/algorithms/awb.h | 2 -- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/ipa/libipa/awb.cpp b/src/ipa/libipa/awb.cpp index 925fac232709..214bac8b56a6 100644 --- a/src/ipa/libipa/awb.cpp +++ b/src/ipa/libipa/awb.cpp @@ -114,7 +114,7 @@ namespace ipa { * does not take any statistics into account. It is used to compute the colour * gains when the user manually specifies a colour temperature. * - * \return The colour gains + * \return The colour gains or std::nullopt if the conversion is not possible */ /** diff --git a/src/ipa/libipa/awb.h b/src/ipa/libipa/awb.h index 4bab7a451ce5..f4a86038635f 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -39,7 +40,7 @@ public: virtual int init(const YamlObject &tuningData) = 0; virtual AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) = 0; - virtual RGB gainsFromColourTemperature(double colourTemperature) = 0; + virtual std::optional> gainsFromColourTemperature(double colourTemperature) = 0; const ControlInfoMap::Map &controls() const { diff --git a/src/ipa/libipa/awb_bayes.cpp b/src/ipa/libipa/awb_bayes.cpp index d1d0eaf0e68f..d2bcbd83d7f8 100644 --- a/src/ipa/libipa/awb_bayes.cpp +++ b/src/ipa/libipa/awb_bayes.cpp @@ -270,7 +270,7 @@ void AwbBayes::handleControls(const ControlList &controls) } } -RGB AwbBayes::gainsFromColourTemperature(double colourTemperature) +std::optional> AwbBayes::gainsFromColourTemperature(double colourTemperature) { /* * \todo In the RaspberryPi code, the ct curve was interpolated in @@ -278,7 +278,7 @@ RGB AwbBayes::gainsFromColourTemperature(double colourTemperature) * intuitive, as the gains are in linear space. But I can't prove it. */ const auto &gains = colourGainCurve_.getInterpolated(colourTemperature); - return { { gains[0], 1.0, gains[1] } }; + return RGB{ { gains[0], 1.0, gains[1] } }; } AwbResult AwbBayes::calculateAwb(const AwbStats &stats, unsigned int lux) diff --git a/src/ipa/libipa/awb_bayes.h b/src/ipa/libipa/awb_bayes.h index bb933038d6d2..47ef3cce4d58 100644 --- a/src/ipa/libipa/awb_bayes.h +++ b/src/ipa/libipa/awb_bayes.h @@ -27,7 +27,7 @@ public: int init(const YamlObject &tuningData) override; AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) override; - RGB gainsFromColourTemperature(double temperatureK) override; + std::optional> gainsFromColourTemperature(double temperatureK) override; void handleControls(const ControlList &controls) override; private: diff --git a/src/ipa/libipa/awb_grey.cpp b/src/ipa/libipa/awb_grey.cpp index d3d2132b8869..d252edb2b6c6 100644 --- a/src/ipa/libipa/awb_grey.cpp +++ b/src/ipa/libipa/awb_grey.cpp @@ -98,15 +98,15 @@ AwbResult AwbGrey::calculateAwb(const AwbStats &stats, [[maybe_unused]] unsigned * \return The colour gains if a colour temperature curve is available, * [1, 1, 1] otherwise. */ -RGB AwbGrey::gainsFromColourTemperature(double colourTemperature) +std::optional> AwbGrey::gainsFromColourTemperature(double colourTemperature) { if (!colourGainCurve_) { LOG(Awb, Error) << "No gains defined"; - return RGB({ 1.0, 1.0, 1.0 }); + return std::nullopt; } auto gains = colourGainCurve_->getInterpolated(colourTemperature); - return { { gains[0], 1.0, gains[1] } }; + return RGB{ { gains[0], 1.0, gains[1] } }; } } /* namespace ipa */ diff --git a/src/ipa/libipa/awb_grey.h b/src/ipa/libipa/awb_grey.h index 7ec7bfa5da9a..f82a368d11cc 100644 --- a/src/ipa/libipa/awb_grey.h +++ b/src/ipa/libipa/awb_grey.h @@ -25,7 +25,7 @@ public: int init(const YamlObject &tuningData) override; AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) override; - RGB gainsFromColourTemperature(double colourTemperature) override; + std::optional> gainsFromColourTemperature(double colourTemperature) override; private: std::optional>> colourGainCurve_; diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 0795b8e5b1e1..f5415a0bb99d 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -125,8 +125,12 @@ int Awb::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) { context.activeState.awb.manual.gains = RGB{ 1.0 }; - context.activeState.awb.automatic.gains = - awbAlgo_->gainsFromColourTemperature(kDefaultColourTemperature); + auto gains = awbAlgo_->gainsFromColourTemperature(kDefaultColourTemperature); + if (gains) + context.activeState.awb.automatic.gains = *gains; + else + context.activeState.awb.automatic.gains = RGB{ 1.0 }; + context.activeState.awb.autoEnabled = true; context.activeState.awb.manual.temperatureK = kDefaultColourTemperature; context.activeState.awb.automatic.temperatureK = kDefaultColourTemperature; @@ -183,11 +187,13 @@ void Awb::queueRequest(IPAContext &context, */ update = true; } else if (colourTemperature) { - const auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature); - awb.manual.gains.r() = gains.r(); - awb.manual.gains.b() = gains.b(); awb.manual.temperatureK = *colourTemperature; - update = true; + const auto &gains = awbAlgo_->gainsFromColourTemperature(*colourTemperature); + if (gains) { + awb.manual.gains.r() = gains->r(); + awb.manual.gains.b() = gains->b(); + update = true; + } } if (update) diff --git a/src/ipa/rkisp1/algorithms/awb.h b/src/ipa/rkisp1/algorithms/awb.h index 7e6c3862e699..02651cc732bf 100644 --- a/src/ipa/rkisp1/algorithms/awb.h +++ b/src/ipa/rkisp1/algorithms/awb.h @@ -7,8 +7,6 @@ #pragma once -#include - #include "libcamera/internal/vector.h" #include "libipa/awb.h"