From 846e7d999a15ce0c3784a790cd5c249ba7aaa5c6 Mon Sep 17 00:00:00 2001 From: David Plowman Date: Thu, 18 Jun 2020 12:12:36 +0100 Subject: libcamera: ipa: raspberrypi: Recalculate camera exposure/gain when camera mode changes This commit causes the AGC to recalculate its camera exposure/gain values when the camera mode changes. For example it's possible that the exposure profile could be changed by the application so the division between exposure time and analogue gain may be different. The other underlying reason (and which this commit accomplishes too) is that the sensor's line timing may change in a new mode, and because V4L2 drivers store a number of exposure _lines_, the resulting _time_ will "change under our feet". So we have to go through the process of recalculating the correct number of lines and writing this back to the sensor with every mode switch, regardless of anything else. Signed-off-by: David Plowman Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/ipa/raspberrypi/controller/rpi/agc.cpp | 12 ++++++++++++ src/ipa/raspberrypi/controller/rpi/agc.hpp | 1 + 2 files changed, 13 insertions(+) (limited to 'src/ipa/raspberrypi/controller') diff --git a/src/ipa/raspberrypi/controller/rpi/agc.cpp b/src/ipa/raspberrypi/controller/rpi/agc.cpp index a4742872..c02b5ece 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.cpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.cpp @@ -221,6 +221,18 @@ void Agc::SetConstraintMode(std::string const &constraint_mode_name) constraint_mode_name_ = constraint_mode_name; } +void Agc::SwitchMode(CameraMode const &camera_mode, Metadata *metadata) +{ + // On a mode switch, it's possible the exposure profile could change, + // so we run through the dividing up of exposure/gain again and + // write the results into the metadata we've been given. + if (status_.total_exposure_value) { + housekeepConfig(); + divvyupExposure(); + writeAndFinish(metadata, false); + } +} + void Agc::Prepare(Metadata *image_metadata) { AgcStatus status; diff --git a/src/ipa/raspberrypi/controller/rpi/agc.hpp b/src/ipa/raspberrypi/controller/rpi/agc.hpp index dbcefba6..9a7e89c1 100644 --- a/src/ipa/raspberrypi/controller/rpi/agc.hpp +++ b/src/ipa/raspberrypi/controller/rpi/agc.hpp @@ -75,6 +75,7 @@ public: void SetMeteringMode(std::string const &metering_mode_name) override; void SetExposureMode(std::string const &exposure_mode_name) override; void SetConstraintMode(std::string const &contraint_mode_name) override; + void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override; void Prepare(Metadata *image_metadata) override; void Process(StatisticsPtr &stats, Metadata *image_metadata) override; -- cgit v1.2.1