[PATCH v2 24/25] tuning: rkisp1: Add blc module

Stefan Klug stefan.klug at ideasonboard.com
Fri Jun 28 12:47:17 CEST 2024


This module simple copies the values from the tuning images into the
tuning file.

Signed-off-by: Stefan Klug <stefan.klug at 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))
-- 
2.43.0



More information about the libcamera-devel mailing list