diff options
author | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-04-03 17:49:18 +0200 |
---|---|---|
committer | Stefan Klug <stefan.klug@ideasonboard.com> | 2025-05-20 11:20:08 +0200 |
commit | c699d26573ebc3a6275d697a9032aedd9d19f974 (patch) | |
tree | df7c5d0588cbbcc212318f32d5d9784a883bc040 | |
parent | 66e9604684ebc09ee848ecf7738beb329bd40c22 (diff) |
libipa: awb: Make result of gainsFromColourTemp optional
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 <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
-rw-r--r-- | src/ipa/libipa/awb.cpp | 2 | ||||
-rw-r--r-- | src/ipa/libipa/awb.h | 3 | ||||
-rw-r--r-- | src/ipa/libipa/awb_bayes.cpp | 4 | ||||
-rw-r--r-- | src/ipa/libipa/awb_bayes.h | 2 | ||||
-rw-r--r-- | src/ipa/libipa/awb_grey.cpp | 6 | ||||
-rw-r--r-- | src/ipa/libipa/awb_grey.h | 2 | ||||
-rw-r--r-- | src/ipa/rkisp1/algorithms/awb.cpp | 18 | ||||
-rw-r--r-- | 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 925fac23..214bac8b 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 4bab7a45..f4a86038 100644 --- a/src/ipa/libipa/awb.h +++ b/src/ipa/libipa/awb.h @@ -8,6 +8,7 @@ #pragma once #include <map> +#include <optional> #include <libcamera/control_ids.h> #include <libcamera/controls.h> @@ -39,7 +40,7 @@ public: virtual int init(const YamlObject &tuningData) = 0; virtual AwbResult calculateAwb(const AwbStats &stats, unsigned int lux) = 0; - virtual RGB<double> gainsFromColourTemperature(double colourTemperature) = 0; + virtual std::optional<RGB<double>> 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 d1d0eaf0..d2bcbd83 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<double> AwbBayes::gainsFromColourTemperature(double colourTemperature) +std::optional<RGB<double>> AwbBayes::gainsFromColourTemperature(double colourTemperature) { /* * \todo In the RaspberryPi code, the ct curve was interpolated in @@ -278,7 +278,7 @@ RGB<double> 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<double>{ { 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 bb933038..47ef3cce 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<double> gainsFromColourTemperature(double temperatureK) override; + std::optional<RGB<double>> 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 d3d2132b..d252edb2 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<double> AwbGrey::gainsFromColourTemperature(double colourTemperature) +std::optional<RGB<double>> AwbGrey::gainsFromColourTemperature(double colourTemperature) { if (!colourGainCurve_) { LOG(Awb, Error) << "No gains defined"; - return RGB<double>({ 1.0, 1.0, 1.0 }); + return std::nullopt; } auto gains = colourGainCurve_->getInterpolated(colourTemperature); - return { { gains[0], 1.0, gains[1] } }; + return RGB<double>{ { 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 7ec7bfa5..f82a368d 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<double> gainsFromColourTemperature(double colourTemperature) override; + std::optional<RGB<double>> gainsFromColourTemperature(double colourTemperature) override; private: std::optional<Interpolator<Vector<double, 2>>> colourGainCurve_; diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp index 8a8fccd5..601de9c4 100644 --- a/src/ipa/rkisp1/algorithms/awb.cpp +++ b/src/ipa/rkisp1/algorithms/awb.cpp @@ -127,8 +127,12 @@ int Awb::configure(IPAContext &context, const IPACameraSensorInfo &configInfo) { context.activeState.awb.manual.gains = RGB<double>{ 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<double>{ 1.0 }; + context.activeState.awb.autoEnabled = true; context.activeState.awb.manual.temperatureK = kDefaultColourTemperature; context.activeState.awb.automatic.temperatureK = kDefaultColourTemperature; @@ -185,11 +189,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 7e6c3862..02651cc7 100644 --- a/src/ipa/rkisp1/algorithms/awb.h +++ b/src/ipa/rkisp1/algorithms/awb.h @@ -7,8 +7,6 @@ #pragma once -#include <optional> - #include "libcamera/internal/vector.h" #include "libipa/awb.h" |