[PATCH v2 23/25] libtuning: Make blacklevel optional

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


Not every sensor provides blacklevel information through the kernel
interface. We should therefore not require that information to be in the
raw images for the tuning process. It can be provided via the tuning config.

Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>
---
 utils/tuning/libtuning/image.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/utils/tuning/libtuning/image.py b/utils/tuning/libtuning/image.py
index c8911a0ff125..0b9c78fcd9c2 100644
--- a/utils/tuning/libtuning/image.py
+++ b/utils/tuning/libtuning/image.py
@@ -25,6 +25,8 @@ class Image:
         self.color = -1
         self.lux = -1
         self.macbeth = None
+        self.blacklevel = 0
+        self.blacklevel_16 = 0
 
         try:
             self._load_metadata_exif()
@@ -74,8 +76,12 @@ class Image:
         self.againQ8 = metadata[f'Exif.{photo}.ISOSpeedRatings'].value * 256 / 100
         self.againQ8_norm = self.againQ8 / 256
         self.camName = metadata['Exif.Image.Model'].value
-        self.blacklevel = int(metadata[f'Exif.{subimage}.BlackLevel'].value[0])
-        self.blacklevel_16 = self.blacklevel << (16 - self.sigbits)
+        if f'Exif.{subimage}.BlackLevel' in metadata:
+            self.blacklevel = int(metadata[f'Exif.{subimage}.BlackLevel'].value[0])
+            self.blacklevel_16 = self.blacklevel << (16 - self.sigbits)
+        else:
+            logger.warning("Image doesn't contain blacklevel info")
+
 
         # Channel order depending on bayer pattern
         # The key is the order given by exif, where 0 is R, 1 is G, and 2 is B
-- 
2.43.0



More information about the libcamera-devel mailing list