[2/3] ipa: rkisp1: cproc: Merge identical functions
diff mbox series

Message ID 20240613083533.855791-3-stefan.klug@ideasonboard.com
State Accepted
Commit c2fad17ad083defede63d41b8b698f388f016fff
Headers show
Series
  • ipa: rkisp1: cproc: Small fixes
Related show

Commit Message

Stefan Klug June 13, 2024, 8:33 a.m. UTC
convertContrast() and convertSaturation() are equal. Merge them into
one.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/cproc.cpp | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

Comments

Kieran Bingham June 13, 2024, 8:54 a.m. UTC | #1
Quoting Stefan Klug (2024-06-13 09:33:19)
> convertContrast() and convertSaturation() are equal. Merge them into
> one.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  src/ipa/rkisp1/algorithms/cproc.cpp | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp
> index 955298093fda..9f400a52dd96 100644
> --- a/src/ipa/rkisp1/algorithms/cproc.cpp
> +++ b/src/ipa/rkisp1/algorithms/cproc.cpp
> @@ -44,12 +44,7 @@ int convertBrightness(const float v)
>         return std::clamp<int>(std::lround(v * 128), -128, 127);
>  }
>  
> -int convertContrast(const float v)
> -{
> -       return std::clamp<int>(std::lround(v * 128), 0, 255);
> -}
> -
> -int convertSaturation(const float v)
> +int convertContrastOrSaturation(const float v)
>  {
>         return std::clamp<int>(std::lround(v * 128), 0, 255);
>  }
> @@ -80,8 +75,8 @@ int ColorProcessing::configure([[maybe_unused]] IPAContext &context,
>         auto &cproc = context.activeState.cproc;
>  
>         cproc.brightness = convertBrightness(kDefaultBrightness);
> -       cproc.contrast = convertContrast(kDefaultContrast);
> -       cproc.saturation = convertSaturation(kDefaultSaturation);
> +       cproc.contrast = convertContrastOrSaturation(kDefaultContrast);
> +       cproc.saturation = convertContrastOrSaturation(kDefaultSaturation);
>  
>         return 0;
>  }
> @@ -113,7 +108,7 @@ void ColorProcessing::queueRequest(IPAContext &context,
>  
>         const auto &contrast = controls.get(controls::Contrast);
>         if (contrast) {
> -               int value = convertContrast(*contrast);
> +               int value = convertContrastOrSaturation(*contrast);
>                 if (cproc.contrast != value) {
>                         cproc.contrast = value;
>                         update = true;
> @@ -124,7 +119,7 @@ void ColorProcessing::queueRequest(IPAContext &context,
>  
>         const auto saturation = controls.get(controls::Saturation);
>         if (saturation) {
> -               int value = convertSaturation(*saturation);
> +               int value = convertContrastOrSaturation(*saturation);
>                 if (cproc.saturation != value) {
>                         cproc.saturation = value;
>                         update = true;
> -- 
> 2.43.0
>
Laurent Pinchart June 13, 2024, 11 a.m. UTC | #2
Hi Stefan,

Thank you for the patch.

On Thu, Jun 13, 2024 at 10:33:19AM +0200, Stefan Klug wrote:
> convertContrast() and convertSaturation() are equal. Merge them into
> one.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

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

> ---
>  src/ipa/rkisp1/algorithms/cproc.cpp | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp
> index 955298093fda..9f400a52dd96 100644
> --- a/src/ipa/rkisp1/algorithms/cproc.cpp
> +++ b/src/ipa/rkisp1/algorithms/cproc.cpp
> @@ -44,12 +44,7 @@ int convertBrightness(const float v)
>  	return std::clamp<int>(std::lround(v * 128), -128, 127);
>  }
>  
> -int convertContrast(const float v)
> -{
> -	return std::clamp<int>(std::lround(v * 128), 0, 255);
> -}
> -
> -int convertSaturation(const float v)
> +int convertContrastOrSaturation(const float v)
>  {
>  	return std::clamp<int>(std::lround(v * 128), 0, 255);
>  }
> @@ -80,8 +75,8 @@ int ColorProcessing::configure([[maybe_unused]] IPAContext &context,
>  	auto &cproc = context.activeState.cproc;
>  
>  	cproc.brightness = convertBrightness(kDefaultBrightness);
> -	cproc.contrast = convertContrast(kDefaultContrast);
> -	cproc.saturation = convertSaturation(kDefaultSaturation);
> +	cproc.contrast = convertContrastOrSaturation(kDefaultContrast);
> +	cproc.saturation = convertContrastOrSaturation(kDefaultSaturation);
>  
>  	return 0;
>  }
> @@ -113,7 +108,7 @@ void ColorProcessing::queueRequest(IPAContext &context,
>  
>  	const auto &contrast = controls.get(controls::Contrast);
>  	if (contrast) {
> -		int value = convertContrast(*contrast);
> +		int value = convertContrastOrSaturation(*contrast);
>  		if (cproc.contrast != value) {
>  			cproc.contrast = value;
>  			update = true;
> @@ -124,7 +119,7 @@ void ColorProcessing::queueRequest(IPAContext &context,
>  
>  	const auto saturation = controls.get(controls::Saturation);
>  	if (saturation) {
> -		int value = convertSaturation(*saturation);
> +		int value = convertContrastOrSaturation(*saturation);
>  		if (cproc.saturation != value) {
>  			cproc.saturation = value;
>  			update = true;

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/cproc.cpp b/src/ipa/rkisp1/algorithms/cproc.cpp
index 955298093fda..9f400a52dd96 100644
--- a/src/ipa/rkisp1/algorithms/cproc.cpp
+++ b/src/ipa/rkisp1/algorithms/cproc.cpp
@@ -44,12 +44,7 @@  int convertBrightness(const float v)
 	return std::clamp<int>(std::lround(v * 128), -128, 127);
 }
 
-int convertContrast(const float v)
-{
-	return std::clamp<int>(std::lround(v * 128), 0, 255);
-}
-
-int convertSaturation(const float v)
+int convertContrastOrSaturation(const float v)
 {
 	return std::clamp<int>(std::lround(v * 128), 0, 255);
 }
@@ -80,8 +75,8 @@  int ColorProcessing::configure([[maybe_unused]] IPAContext &context,
 	auto &cproc = context.activeState.cproc;
 
 	cproc.brightness = convertBrightness(kDefaultBrightness);
-	cproc.contrast = convertContrast(kDefaultContrast);
-	cproc.saturation = convertSaturation(kDefaultSaturation);
+	cproc.contrast = convertContrastOrSaturation(kDefaultContrast);
+	cproc.saturation = convertContrastOrSaturation(kDefaultSaturation);
 
 	return 0;
 }
@@ -113,7 +108,7 @@  void ColorProcessing::queueRequest(IPAContext &context,
 
 	const auto &contrast = controls.get(controls::Contrast);
 	if (contrast) {
-		int value = convertContrast(*contrast);
+		int value = convertContrastOrSaturation(*contrast);
 		if (cproc.contrast != value) {
 			cproc.contrast = value;
 			update = true;
@@ -124,7 +119,7 @@  void ColorProcessing::queueRequest(IPAContext &context,
 
 	const auto saturation = controls.get(controls::Saturation);
 	if (saturation) {
-		int value = convertSaturation(*saturation);
+		int value = convertContrastOrSaturation(*saturation);
 		if (cproc.saturation != value) {
 			cproc.saturation = value;
 			update = true;