<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Thank you for your work.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 5 Jan 2022 at 15:55, 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">If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it<br>
means the sensor wants to be told the latest colour gains.<br>
<br>
We store whether the control exists and if so its default value, to<br>
save us checking for it on every frame.<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>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">
---<br>
 .../pipeline/raspberrypi/raspberrypi.cpp      | 31 +++++++++++++++++++<br>
 1 file changed, 31 insertions(+)<br>
<br>
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
index b5c687da..4adef952 100644<br>
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp<br>
@@ -264,6 +264,12 @@ public:<br>
<br>
        unsigned int dropFrameCount_;<br>
<br>
+       /*<br>
+        * If set, this stores the value that represets a gain of one for<br>
+        * the V4L2_CID_NOTIFY_GAINS control.<br>
+        */<br>
+       std::optional<int32_t> notifyGainsUnity_;<br>
+<br>
 private:<br>
        void checkRequestCompleted();<br>
        void fillRequestMetadata(const ControlList &bufferControls,<br>
@@ -1191,6 +1197,15 @@ int PipelineHandlerRPi::registerCamera(MediaDevice *unicam, MediaDevice *isp)<br>
        /* Initialize the camera properties. */<br>
        data->properties_ = data->sensor_->properties();<br>
<br>
+       /*<br>
+        * The V4L2_CID_NOTIFY_GAINS control, if present, is used to inform the<br>
+        * sensor of the colour gains. It is defined to be a linear gain where<br>
+        * the default value represents a gain of exactly one.<br>
+        */<br>
+       auto it = data->sensor_->controls().find(V4L2_CID_NOTIFY_GAINS);<br>
+       if (it != data->sensor_->controls().end())<br>
+               data->notifyGainsUnity_ = it->second.def().get<int32_t>();<br>
+<br>
        /*<br>
         * Set a default value for the ScalerCropMaximum property to show<br>
         * that we support its use, however, initialise it to zero because<br>
@@ -1495,6 +1510,22 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &<br>
        Request *request = requestQueue_.front();<br>
        request->metadata().merge(controls);<br>
<br>
+       /*<br>
+        * Inform the sensor of the latest colour gains if it has the<br>
+        * V4L2_CID_NOTIFY_GAINS control (which means notifyGainsUnity_ is set).<br>
+        */<br>
+       if (notifyGainsUnity_ && controls.contains(libcamera::controls::ColourGains)) {<br>
+               libcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);<br>
+               /* The control wants linear gains in the order B, Gb, Gr, R. */<br>
+               ControlList ctrls(sensor_->controls());<br>
+               std::array<int32_t, 4> gains = { static_cast<int32_t>(colourGains[1] * *notifyGainsUnity_),<br>
+                                                *notifyGainsUnity_, *notifyGainsUnity_,<br>
+                                                static_cast<int32_t>(colourGains[0] * *notifyGainsUnity_) };<br>
+               ctrls.set(V4L2_CID_NOTIFY_GAINS, Span<const int32_t>{ gains });<br>
+<br>
+               sensor_->setControls(&ctrls);<br>
+       }<br>
+<br>
        state_ = State::IpaComplete;<br>
        handleState();<br>
 }<br>
-- <br>
2.30.2<br>
<br>
</blockquote></div></div>