[libcamera-devel] [PATCH v2 3/3] libcamera: pipeline: raspberrypi: Update sensor's V4L2_CID_NOTIFY_GAINS control
David Plowman
david.plowman at raspberrypi.com
Wed Jan 5 09:55:53 CET 2022
If the sensor exposes the V4L2_CID_NOTIFY_GAINS control, assume it
means the sensor wants to be told the latest colour gains.
Signed-off-by: David Plowman <david.plowman at raspberrypi.com>
---
.../pipeline/raspberrypi/raspberrypi.cpp | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index b5c687da..0d4b5a57 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -1495,6 +1495,32 @@ void RPiCameraData::statsMetadataComplete(uint32_t bufferId, const ControlList &
Request *request = requestQueue_.front();
request->metadata().merge(controls);
+ /*
+ * If the sensor has the V4L2_CID_NOTIFY_GAIN control then it wants
+ * to be notified of the latest colour gains.
+ */
+ auto it = sensor_->controls().find(V4L2_CID_NOTIFY_GAINS);
+ if (it != sensor_->controls().end()) {
+ if (controls.contains(libcamera::controls::ColourGains)) {
+ libcamera::Span<const float> colourGains = controls.get(libcamera::controls::ColourGains);
+ /*
+ * This control is a linear gain value where the default is
+ * defined to correspond to a gain of 1. The order of the gains
+ * is always B, Gb, Gr, R.
+ */
+ int unity = it->second.def().get<int32_t>();
+ ControlList ctrls(sensor_->controls());
+ int32_t gains[4] = { static_cast<int32_t>(colourGains[1] * unity),
+ unity, unity,
+ static_cast<int32_t>(colourGains[0] * unity) };
+ ControlValue c(Span<const uint8_t>{ reinterpret_cast<uint8_t *>(gains),
+ sizeof(gains) });
+ ctrls.set(V4L2_CID_NOTIFY_GAINS, c);
+
+ sensor_->setControls(&ctrls);
+ }
+ }
+
state_ = State::IpaComplete;
handleState();
}
--
2.30.2
More information about the libcamera-devel
mailing list