[v2,24/25] tuning: rkisp1: Add blc module
diff mbox series

Message ID 20240628104828.2928109-25-stefan.klug@ideasonboard.com
State Superseded
Headers show
Series
  • Add ccm calibration to libtuning
Related show

Commit Message

Stefan Klug June 28, 2024, 10:47 a.m. UTC
This module simple copies the values from the tuning images into the
tuning file.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 .../tuning/libtuning/modules/blc/__init__.py  |  5 ++
 utils/tuning/libtuning/modules/blc/blc.py     | 46 +++++++++++++++++++
 utils/tuning/rkisp1.py                        |  4 +-
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 utils/tuning/libtuning/modules/blc/__init__.py
 create mode 100644 utils/tuning/libtuning/modules/blc/blc.py

Comments

Laurent Pinchart June 29, 2024, 1:08 a.m. UTC | #1
Hi Stefan,

Thank you for the patch.

On Fri, Jun 28, 2024 at 12:47:17PM +0200, Stefan Klug wrote:
> This module simple copies the values from the tuning images into the
> tuning file.

As explained in the review of 24/25, I don't think this is correct.

> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  .../tuning/libtuning/modules/blc/__init__.py  |  5 ++
>  utils/tuning/libtuning/modules/blc/blc.py     | 46 +++++++++++++++++++
>  utils/tuning/rkisp1.py                        |  4 +-
>  3 files changed, 54 insertions(+), 1 deletion(-)
>  create mode 100644 utils/tuning/libtuning/modules/blc/__init__.py
>  create mode 100644 utils/tuning/libtuning/modules/blc/blc.py
> 
> diff --git a/utils/tuning/libtuning/modules/blc/__init__.py b/utils/tuning/libtuning/modules/blc/__init__.py
> new file mode 100644
> index 000000000000..33d4936e4cfd
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/blc/__init__.py
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2024, Ideas on Board Oy
> +
> +from .blc import BLC
> diff --git a/utils/tuning/libtuning/modules/blc/blc.py b/utils/tuning/libtuning/modules/blc/blc.py
> new file mode 100644
> index 000000000000..8cfb80e53143
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/blc/blc.py
> @@ -0,0 +1,46 @@
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +# Copyright (C) 2024, Ideas on Board Oy
> +
> +from ..module import Module
> +import logging
> +
> +logger = logging.getLogger(__name__)
> +
> +
> +class BLC(Module):
> +    type = 'blc'
> +    hr_name = 'BLC (Base)'
> +    out_name = 'BlackLevelCorrection'
> +
> +    def __init__(self, debug: list):
> +        super().__init__()
> +
> +        self.debug = debug
> +
> +    def validate_config(self, config: dict) -> bool:
> +        return True
> +
> +    def process(self, config: dict, images: list, outputs: dict) -> dict:
> +        output = {}
> +
> +        blacklevel = None
> +
> +        for img in images:
> +            if blacklevel is None:
> +                if img.blacklevel_16 > 0:
> +                    blacklevel = img.blacklevel_16
> +            else:
> +                if img.blacklevel_16 > 0 and img.blacklevel_16 != blacklevel:
> +                    logger.warnung(f"Blacklevels differ {blacklevel} {img.blacklevel_16}")
> +
> +        if blacklevel:
> +            output['R'] = blacklevel
> +            output['Gr'] = blacklevel
> +            output['Gb'] = blacklevel
> +            output['B'] = blacklevel
> +            output['referenceBitwidth'] = 16
> +            return output
> +
> +        logger.warning("No valid blacklevel found. Skipping blc")
> +        return None
> diff --git a/utils/tuning/rkisp1.py b/utils/tuning/rkisp1.py
> index c5036c65557b..7cf3f2f9fbf1 100755
> --- a/utils/tuning/rkisp1.py
> +++ b/utils/tuning/rkisp1.py
> @@ -14,6 +14,7 @@ from libtuning.parsers import YamlParser
>  from libtuning.generators import YamlOutput
>  from libtuning.modules.lsc import LSCRkISP1
>  from libtuning.modules.agc import AGCRkISP1
> +from libtuning.modules.blc import BLC
>  from libtuning.modules.ccm import CCMRkISP1
>  from libtuning.modules.static import StaticModule
>  
> @@ -27,6 +28,7 @@ gamma_out = StaticModule('GammaOutCorrection', {'gamma': 2.2})
>  tuner = lt.Tuner('RkISP1')
>  tuner.add(AGCRkISP1(debug=[lt.Debug.Plot]))
>  tuner.add(awb)
> +tuner.add(BLC(debug=[lt.Debug.Plot]))
>  tuner.add(CCMRkISP1(debug=[lt.Debug.Plot]))
>  tuner.add(color_processing)
>  tuner.add(filter)
> @@ -53,7 +55,7 @@ tuner.add(LSCRkISP1(
>  
>  tuner.set_input_parser(YamlParser())
>  tuner.set_output_formatter(YamlOutput())
> -tuner.set_output_order([AGCRkISP1, awb, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1])
> +tuner.set_output_order([AGCRkISP1, awb, BLC, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1])
>  
>  if __name__ == '__main__':
>      sys.exit(tuner.run(sys.argv))

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/modules/blc/__init__.py b/utils/tuning/libtuning/modules/blc/__init__.py
new file mode 100644
index 000000000000..33d4936e4cfd
--- /dev/null
+++ b/utils/tuning/libtuning/modules/blc/__init__.py
@@ -0,0 +1,5 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2024, Ideas on Board Oy
+
+from .blc import BLC
diff --git a/utils/tuning/libtuning/modules/blc/blc.py b/utils/tuning/libtuning/modules/blc/blc.py
new file mode 100644
index 000000000000..8cfb80e53143
--- /dev/null
+++ b/utils/tuning/libtuning/modules/blc/blc.py
@@ -0,0 +1,46 @@ 
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (C) 2024, Ideas on Board Oy
+
+from ..module import Module
+import logging
+
+logger = logging.getLogger(__name__)
+
+
+class BLC(Module):
+    type = 'blc'
+    hr_name = 'BLC (Base)'
+    out_name = 'BlackLevelCorrection'
+
+    def __init__(self, debug: list):
+        super().__init__()
+
+        self.debug = debug
+
+    def validate_config(self, config: dict) -> bool:
+        return True
+
+    def process(self, config: dict, images: list, outputs: dict) -> dict:
+        output = {}
+
+        blacklevel = None
+
+        for img in images:
+            if blacklevel is None:
+                if img.blacklevel_16 > 0:
+                    blacklevel = img.blacklevel_16
+            else:
+                if img.blacklevel_16 > 0 and img.blacklevel_16 != blacklevel:
+                    logger.warnung(f"Blacklevels differ {blacklevel} {img.blacklevel_16}")
+
+        if blacklevel:
+            output['R'] = blacklevel
+            output['Gr'] = blacklevel
+            output['Gb'] = blacklevel
+            output['B'] = blacklevel
+            output['referenceBitwidth'] = 16
+            return output
+
+        logger.warning("No valid blacklevel found. Skipping blc")
+        return None
diff --git a/utils/tuning/rkisp1.py b/utils/tuning/rkisp1.py
index c5036c65557b..7cf3f2f9fbf1 100755
--- a/utils/tuning/rkisp1.py
+++ b/utils/tuning/rkisp1.py
@@ -14,6 +14,7 @@  from libtuning.parsers import YamlParser
 from libtuning.generators import YamlOutput
 from libtuning.modules.lsc import LSCRkISP1
 from libtuning.modules.agc import AGCRkISP1
+from libtuning.modules.blc import BLC
 from libtuning.modules.ccm import CCMRkISP1
 from libtuning.modules.static import StaticModule
 
@@ -27,6 +28,7 @@  gamma_out = StaticModule('GammaOutCorrection', {'gamma': 2.2})
 tuner = lt.Tuner('RkISP1')
 tuner.add(AGCRkISP1(debug=[lt.Debug.Plot]))
 tuner.add(awb)
+tuner.add(BLC(debug=[lt.Debug.Plot]))
 tuner.add(CCMRkISP1(debug=[lt.Debug.Plot]))
 tuner.add(color_processing)
 tuner.add(filter)
@@ -53,7 +55,7 @@  tuner.add(LSCRkISP1(
 
 tuner.set_input_parser(YamlParser())
 tuner.set_output_formatter(YamlOutput())
-tuner.set_output_order([AGCRkISP1, awb, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1])
+tuner.set_output_order([AGCRkISP1, awb, BLC, CCMRkISP1, color_processing, filter, gamma_out, LSCRkISP1])
 
 if __name__ == '__main__':
     sys.exit(tuner.run(sys.argv))