<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thank you for your patch.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 7 Dec 2020 at 18:02, David Plowman <<a href="mailto:david.plowman@raspberrypi.com">david.plowman@raspberrypi.com</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">When the AWB is started from "cold" with fixed colour gains, we try to<br>
estimate the colour temperature this corresponds to (if a calibrated<br>
CT curve was supplied). When fixed colour gains are set after the AWB<br>
has been running, we leave the CT estimate alone, as the one we have<br>
is probably sensible.<br>
<br>
This estimated colour is passed out in the metadata for other<br>
algorithms - notably ALSC - to use.<br>
<br>
Signed-off-by: David Plowman <<a href="mailto:david.plowman@raspberrypi.com" target="_blank">david.plowman@raspberrypi.com</a>><br>
---<br>
 src/ipa/raspberrypi/controller/rpi/alsc.cpp |  6 +++++-<br>
 src/ipa/raspberrypi/controller/rpi/awb.cpp  | 14 ++++++++++++++<br>
 src/ipa/raspberrypi/controller/rpi/awb.hpp  |  1 +<br>
 3 files changed, 20 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/alsc.cpp b/src/ipa/raspberrypi/controller/rpi/alsc.cpp<br>
index 183a0c95..c354c985 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/alsc.cpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/alsc.cpp<br>
@@ -146,6 +146,7 @@ void Alsc::Read(boost::property_tree::ptree const &params)<br>
        config_.threshold = params.get<double>("threshold", 1e-3);<br>
 }<br>
<br>
+static double get_ct(Metadata *metadata, double default_ct);<br>
 static void get_cal_table(double ct,<br>
                          std::vector<AlscCalibration> const &calibrations,<br>
                          double cal_table[XY]);<br>
@@ -210,6 +211,9 @@ void Alsc::SwitchMode(CameraMode const &camera_mode,<br>
        // change.<br>
        bool reset_tables = first_time_ || compare_modes(camera_mode_, camera_mode);<br>
<br>
+       // Believe the colour temperature from the AWB, if there is one.<br>
+       ct_ = get_ct(metadata, ct_);<br>
+<br>
        // Ensure the other thread isn't running while we do this.<br>
        waitForAysncThread();<br>
<br>
@@ -254,7 +258,7 @@ void Alsc::fetchAsyncResults()<br>
        memcpy(sync_results_, async_results_, sizeof(sync_results_));<br>
 }<br>
<br>
-static double get_ct(Metadata *metadata, double default_ct)<br>
+double get_ct(Metadata *metadata, double default_ct)<br>
 {<br>
        AwbStatus awb_status;<br>
        awb_status.temperature_K = default_ct; // in case nothing found<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
index 6b359ac5..2266c07b 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp<br>
@@ -19,6 +19,9 @@ using namespace RPiController;<br>
<br>
 const double Awb::RGB::INVALID = -1.0;<br>
<br>
+// todo - the locking in this algorithm needs some tidying up as has been done<br>
+// elsewhere (ALSC and AGC).<br>
+<br>
 void AwbMode::Read(boost::property_tree::ptree const &params)<br>
 {<br>
        ct_lo = params.get<double>("lo");<br>
@@ -121,6 +124,7 @@ Awb::Awb(Controller *controller)<br>
        async_abort_ = async_start_ = async_started_ = async_finished_ = false;<br>
        mode_ = nullptr;<br>
        manual_r_ = manual_b_ = 0.0;<br>
+       first_switch_mode_ = true;<br>
        async_thread_ = std::thread(std::bind(&Awb::asyncFunc, this));<br>
 }<br>
<br>
@@ -201,9 +205,19 @@ void Awb::SwitchMode([[maybe_unused]] CameraMode const &camera_mode,<br>
                prev_sync_results_.gain_r = manual_r_;<br>
                prev_sync_results_.gain_g = 1.0;<br>
                prev_sync_results_.gain_b = manual_b_;<br>
+               // If we're starting up for the first time, try and<br>
+               // "dead reckon" the corresponding colour temperature.<br>
+               if (first_switch_mode_ && config_.bayes) {<br>
+                       Pwl ct_r_inverse = std::move(config_.ct_r.Inverse());<br>
+                       Pwl ct_b_inverse = std::move(config_.ct_b.Inverse());<br></blockquote><div><br></div><div>Not a review comment just for my curiosity - will std::move do anything here?  Would C++ Return Value Optimisation ensure that we don't make any extra copies without the std::move?</div><div><br></div><div>Reviewed-by: Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>></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">
+                       double ct_r = ct_r_inverse.Eval(ct_r_inverse.Domain().Clip(1 / manual_r_));<br>
+                       double ct_b = ct_b_inverse.Eval(ct_b_inverse.Domain().Clip(1 / manual_b_));<br>
+                       prev_sync_results_.temperature_K = (ct_r + ct_b) / 2;<br>
+               }<br>
                sync_results_ = prev_sync_results_;<br>
        }<br>
        metadata->Set("awb.status", prev_sync_results_);<br>
+       first_switch_mode_ = false;<br>
 }<br>
<br>
 void Awb::fetchAsyncResults()<br>
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp<br>
index d86b9598..8525af32 100644<br>
--- a/src/ipa/raspberrypi/controller/rpi/awb.hpp<br>
+++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp<br>
@@ -159,6 +159,7 @@ private:<br>
        double manual_r_;<br>
        // manual b setting<br>
        double manual_b_;<br>
+       bool first_switch_mode_; // 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.20.1<br>
<br>
_______________________________________________<br>
libcamera-devel mailing list<br>
<a href="mailto:libcamera-devel@lists.libcamera.org" target="_blank">libcamera-devel@lists.libcamera.org</a><br>
<a href="https://lists.libcamera.org/listinfo/libcamera-devel" rel="noreferrer" target="_blank">https://lists.libcamera.org/listinfo/libcamera-devel</a><br>
</blockquote></div></div>