[libcamera-devel,4/7] ipa: rasberrypi: contrast: Remove unnecessary atomic variables
diff mbox series

Message ID 20210204093457.6879-5-david.plowman@raspberrypi.com
State Accepted
Headers show
Series
  • Raspberry Pi IPA maintenance
Related show

Commit Message

David Plowman Feb. 4, 2021, 9:34 a.m. UTC
SetBrightness() and SetContrast() are only called synchronously so
there is no need for brightness_ and contrast_ to be atomic.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/rpi/contrast.cpp | 9 ++++-----
 src/ipa/raspberrypi/controller/rpi/contrast.hpp | 5 ++---
 2 files changed, 6 insertions(+), 8 deletions(-)

Comments

Laurent Pinchart Feb. 7, 2021, 2:07 p.m. UTC | #1
Hi David,

Thank you for the patch.

On Thu, Feb 04, 2021 at 09:34:54AM +0000, David Plowman wrote:
> SetBrightness() and SetContrast() are only called synchronously so
> there is no need for brightness_ and contrast_ to be atomic.
> 
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/ipa/raspberrypi/controller/rpi/contrast.cpp | 9 ++++-----
>  src/ipa/raspberrypi/controller/rpi/contrast.hpp | 5 ++---
>  2 files changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
> index 05ed139f..2bc43027 100644
> --- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp
> +++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
> @@ -150,7 +150,6 @@ Pwl apply_manual_contrast(Pwl const &gamma_curve, double brightness,
>  void Contrast::Process(StatisticsPtr &stats,
>  		       [[maybe_unused]] Metadata *image_metadata)
>  {
> -	double brightness = brightness_, contrast = contrast_;
>  	Histogram histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS);
>  	// We look at the histogram and adjust the gamma curve in the following
>  	// ways: 1. Adjust the gamma curve so as to pull the start of the
> @@ -165,13 +164,13 @@ void Contrast::Process(StatisticsPtr &stats,
>  	}
>  	// 2. Finally apply any manually selected brightness/contrast
>  	// adjustment.
> -	if (brightness != 0 || contrast != 1.0)
> -		gamma_curve = apply_manual_contrast(gamma_curve, brightness,
> -						    contrast);
> +	if (brightness_ != 0 || contrast_ != 1.0)
> +		gamma_curve = apply_manual_contrast(gamma_curve, brightness_,
> +						    contrast_);
>  	// And fill in the status for output. Use more points towards the bottom
>  	// of the curve.
>  	ContrastStatus status;
> -	fill_in_status(status, brightness, contrast, gamma_curve);
> +	fill_in_status(status, brightness_, contrast_, gamma_curve);
>  	{
>  		std::unique_lock<std::mutex> lock(mutex_);
>  		status_ = status;
> diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp
> index 6836f181..85624539 100644
> --- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp
> @@ -6,7 +6,6 @@
>   */
>  #pragma once
>  
> -#include <atomic>
>  #include <mutex>
>  
>  #include "../contrast_algorithm.hpp"
> @@ -42,8 +41,8 @@ public:
>  
>  private:
>  	ContrastConfig config_;
> -	std::atomic<double> brightness_;
> -	std::atomic<double> contrast_;
> +	double brightness_;
> +	double contrast_;
>  	ContrastStatus status_;
>  	std::mutex mutex_;
>  };

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.cpp b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
index 05ed139f..2bc43027 100644
--- a/src/ipa/raspberrypi/controller/rpi/contrast.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/contrast.cpp
@@ -150,7 +150,6 @@  Pwl apply_manual_contrast(Pwl const &gamma_curve, double brightness,
 void Contrast::Process(StatisticsPtr &stats,
 		       [[maybe_unused]] Metadata *image_metadata)
 {
-	double brightness = brightness_, contrast = contrast_;
 	Histogram histogram(stats->hist[0].g_hist, NUM_HISTOGRAM_BINS);
 	// We look at the histogram and adjust the gamma curve in the following
 	// ways: 1. Adjust the gamma curve so as to pull the start of the
@@ -165,13 +164,13 @@  void Contrast::Process(StatisticsPtr &stats,
 	}
 	// 2. Finally apply any manually selected brightness/contrast
 	// adjustment.
-	if (brightness != 0 || contrast != 1.0)
-		gamma_curve = apply_manual_contrast(gamma_curve, brightness,
-						    contrast);
+	if (brightness_ != 0 || contrast_ != 1.0)
+		gamma_curve = apply_manual_contrast(gamma_curve, brightness_,
+						    contrast_);
 	// And fill in the status for output. Use more points towards the bottom
 	// of the curve.
 	ContrastStatus status;
-	fill_in_status(status, brightness, contrast, gamma_curve);
+	fill_in_status(status, brightness_, contrast_, gamma_curve);
 	{
 		std::unique_lock<std::mutex> lock(mutex_);
 		status_ = status;
diff --git a/src/ipa/raspberrypi/controller/rpi/contrast.hpp b/src/ipa/raspberrypi/controller/rpi/contrast.hpp
index 6836f181..85624539 100644
--- a/src/ipa/raspberrypi/controller/rpi/contrast.hpp
+++ b/src/ipa/raspberrypi/controller/rpi/contrast.hpp
@@ -6,7 +6,6 @@ 
  */
 #pragma once
 
-#include <atomic>
 #include <mutex>
 
 #include "../contrast_algorithm.hpp"
@@ -42,8 +41,8 @@  public:
 
 private:
 	ContrastConfig config_;
-	std::atomic<double> brightness_;
-	std::atomic<double> contrast_;
+	double brightness_;
+	double contrast_;
 	ContrastStatus status_;
 	std::mutex mutex_;
 };