<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thank you for this work.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 27 Oct 2022 at 12:40, David Plowman via libcamera-devel <<a href="mailto:libcamera-devel@lists.libcamera.org">libcamera-devel@lists.libcamera.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Previously we only did this when the system starts (on the first<br>
switch_mode). Now we do it whenever the manual colour gains are<br>
updated. To facilitate this, this R/B vs. colour temperature inverse<br>
functions are stored persistently in the AwbConfig.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br></blockquote><div><br></div><div>It's good to be consistent with this behavior.</div><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/ipa/raspberrypi/controller/rpi/awb.cpp | 24 +++++++++-------------<br>
src/ipa/raspberrypi/controller/rpi/awb.h | 3 ++-<br>
2 files changed, 12 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
index 2b88c3b0..8d8ddf09 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
@@ -104,6 +104,9 @@ int AwbConfig::read(const libcamera::YamlObject ¶ms)<br>
ret = readCtCurve(ctR, ctB, params["ct_curve"]);<br>
if (ret)<br>
return ret;<br>
+ /* We will want the inverse functions of these too. */<br>
+ ctRInverse = ctR.inverse();<br>
+ ctBInverse = ctB.inverse();<br>
}<br>
<br>
if (params.contains("priors")) {<br>
@@ -174,7 +177,6 @@ Awb::Awb(Controller *controller)<br>
asyncAbort_ = asyncStart_ = asyncStarted_ = asyncFinished_ = false;<br>
mode_ = nullptr;<br>
manualR_ = manualB_ = 0.0;<br>
- firstSwitchMode_ = true;<br>
asyncThread_ = std::thread(std::bind(&Awb::asyncFunc, this));<br>
}<br>
<br>
@@ -270,27 +272,21 @@ void Awb::setManualGains(double manualR, double manualB)<br>
syncResults_.gainR = prevSyncResults_.gainR = manualR_;<br>
syncResults_.gainG = prevSyncResults_.gainG = 1.0;<br>
syncResults_.gainB = prevSyncResults_.gainB = manualB_;<br>
+ if (config_.bayes) {<br>
+ /* Also estimate the best corresponding colour temperature from the curves. */<br>
+ double ctR = config_.ctRInverse.eval(config_.ctRInverse.domain().clip(1 / manualR_));<br>
+ double ctB = config_.ctBInverse.eval(config_.ctBInverse.domain().clip(1 / manualB_));<br>
+ prevSyncResults_.temperatureK = (ctR + ctB) / 2;<br>
+ syncResults_.temperatureK = prevSyncResults_.temperatureK;<br>
+ }<br>
}<br>
}<br>
<br>
void Awb::switchMode([[maybe_unused]] CameraMode const &cameraMode,<br>
Metadata *metadata)<br>
{<br>
- /*<br>
- * On the first mode switch we'll have no meaningful colour<br>
- * temperature, so try to dead reckon one if in manual mode.<br>
- */<br>
- if (!isAutoEnabled() && firstSwitchMode_ && config_.bayes) {<br>
- Pwl ctRInverse = config_.ctR.inverse();<br>
- Pwl ctBInverse = config_.ctB.inverse();<br>
- double ctR = ctRInverse.eval(ctRInverse.domain().clip(1 / manualR_));<br>
- double ctB = ctBInverse.eval(ctBInverse.domain().clip(1 / manualB_));<br>
- prevSyncResults_.temperatureK = (ctR + ctB) / 2;<br>
- syncResults_.temperatureK = prevSyncResults_.temperatureK;<br>
- }<br>
/* Let other algorithms know the current white balance values. */<br>
metadata->set("awb.status", prevSyncResults_);<br>
- firstSwitchMode_ = false;<br>
}<br>
<br>
bool Awb::isAutoEnabled() const<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.h b/src/ipa/raspberrypi/controller/rpi/awb.h<br>
index cb4cfd1b..30acd89d 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/awb.h<br>
+++ b/src/ipa/raspberrypi/controller/rpi/awb.h<br>
@@ -42,6 +42,8 @@ struct AwbConfig {<br>
bool fast; /* "fast" mode uses a 16x16 rather than 32x32 grid */<br>
Pwl ctR; /* function maps CT to r (= R/G) */<br>
Pwl ctB; /* function maps CT to b (= B/G) */<br>
+ Pwl ctRInverse; /* inverse of ctR */<br>
+ Pwl ctBInverse; /* inverse of ctB */<br>
/* table of illuminant priors at different lux levels */<br>
std::vector<AwbPrior> priors;<br>
/* AWB "modes" (determines the search range) */<br>
@@ -168,7 +170,6 @@ private:<br>
double manualR_;<br>
/* manual b setting */<br>
double manualB_;<br>
- bool firstSwitchMode_; /* is this the first call to SwitchMode? */<br>
};<br>
<br>
static inline Awb::RGB operator+(Awb::RGB const &a, Awb::RGB const &b)<br>
-- <br>
2.30.2<br>
<br>
</blockquote></div></div>