[libcamera-devel,v2,17/20] ipa: rpi: contrast: Allow adaptive contrast enhancement to be disabled
diff mbox series

Message ID 20231013074841.16972-18-naush@raspberrypi.com
State Accepted
Headers show
Series
  • Raspberry Pi: Preliminary PiSP support
Related show

Commit Message

Naushir Patuck Oct. 13, 2023, 7:48 a.m. UTC
From: David Plowman <david.plowman@raspberrypi.com>

The enableCe() function enables or disables adaptive contrast
enhancement and the restoreCe() function sets it back to its normal
state (which is what was read from the tuning file).

In future, algorithms like HDR might want to take over tonemapping
functions, so any dynamic behaviour here would upset them.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/rpi/controller/contrast_algorithm.h |  2 ++
 src/ipa/rpi/controller/rpi/contrast.cpp     | 13 ++++++++++++-
 src/ipa/rpi/controller/rpi/contrast.h       |  3 +++
 3 files changed, 17 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/contrast_algorithm.h b/src/ipa/rpi/controller/contrast_algorithm.h
index ce17a4f949b9..895b36b0a80f 100644
--- a/src/ipa/rpi/controller/contrast_algorithm.h
+++ b/src/ipa/rpi/controller/contrast_algorithm.h
@@ -17,6 +17,8 @@  public:
 	/* A contrast algorithm must provide the following: */
 	virtual void setBrightness(double brightness) = 0;
 	virtual void setContrast(double contrast) = 0;
+	virtual void enableCe(bool enable) = 0;
+	virtual void restoreCe() = 0;
 };
 
 } /* namespace RPiController */
diff --git a/src/ipa/rpi/controller/rpi/contrast.cpp b/src/ipa/rpi/controller/rpi/contrast.cpp
index bee1eadd3657..4e038a021d8a 100644
--- a/src/ipa/rpi/controller/rpi/contrast.cpp
+++ b/src/ipa/rpi/controller/rpi/contrast.cpp
@@ -42,6 +42,7 @@  int Contrast::read(const libcamera::YamlObject &params)
 {
 	// enable adaptive enhancement by default
 	config_.ceEnable = params["ce_enable"].get<int>(1);
+	ceEnable_ = config_.ceEnable;
 	// the point near the bottom of the histogram to move
 	config_.loHistogram = params["lo_histogram"].get<double>(0.01);
 	// where in the range to try and move it to
@@ -65,6 +66,16 @@  void Contrast::setContrast(double contrast)
 	contrast_ = contrast;
 }
 
+void Contrast::enableCe(bool enable)
+{
+	ceEnable_ = enable;
+}
+
+void Contrast::restoreCe()
+{
+	ceEnable_ = config_.ceEnable;
+}
+
 void Contrast::initialise()
 {
 	/*
@@ -150,7 +161,7 @@  void Contrast::process(StatisticsPtr &stats,
 	 * histogram down, and possibly push the end up.
 	 */
 	Pwl gammaCurve = config_.gammaCurve;
-	if (config_.ceEnable) {
+	if (ceEnable_) {
 		if (config_.loMax != 0 || config_.hiMax != 0)
 			gammaCurve = computeStretchCurve(histogram, config_).compose(gammaCurve);
 		/*
diff --git a/src/ipa/rpi/controller/rpi/contrast.h b/src/ipa/rpi/controller/rpi/contrast.h
index 9c81277a0450..59aa70dceeb9 100644
--- a/src/ipa/rpi/controller/rpi/contrast.h
+++ b/src/ipa/rpi/controller/rpi/contrast.h
@@ -37,6 +37,8 @@  public:
 	int read(const libcamera::YamlObject &params) override;
 	void setBrightness(double brightness) override;
 	void setContrast(double contrast) override;
+	void enableCe(bool enable) override;
+	void restoreCe() override;
 	void initialise() override;
 	void prepare(Metadata *imageMetadata) override;
 	void process(StatisticsPtr &stats, Metadata *imageMetadata) override;
@@ -46,6 +48,7 @@  private:
 	double brightness_;
 	double contrast_;
 	ContrastStatus status_;
+	double ceEnable_;
 };
 
 } /* namespace RPiController */