summaryrefslogtreecommitdiff
path: root/utils/tuning/libtuning/utils.py
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-06-11 09:09:40 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2024-07-05 22:38:16 +0200
commit797f59850201fcc267814be5c70d4730c4a67702 (patch)
tree3df840e2ceb84ab1b79bf57e5d82e15ceaec005d /utils/tuning/libtuning/utils.py
parent22c7c1e560ded2f0bf882cc92283881bdeedc2cc (diff)
libtuning: Improve filename parsing
In the tuning datasets, the files had names like 'imx335_1600l_3000k_1.dng'. That failed on the old filename parsing function. As there is no need to dictate the order of the tags, split the big regex into chunks and parse them one by one. This also makes the code easier to digest. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'utils/tuning/libtuning/utils.py')
-rw-r--r--utils/tuning/libtuning/utils.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/utils/tuning/libtuning/utils.py b/utils/tuning/libtuning/utils.py
index 90fd7072..c70dfae0 100644
--- a/utils/tuning/libtuning/utils.py
+++ b/utils/tuning/libtuning/utils.py
@@ -43,16 +43,30 @@ def _list_image_files(directory):
def _parse_image_filename(fn: Path):
- result = re.search(r'^(alsc_)?(\d+)[kK]_(\d+)?[lLuU]?.\w{3,4}$', fn.name)
- if result is None:
- logger.error(f'The file name of {fn.name} is incorrectly formatted')
- return None, None, None
+ lsc_only = False
+ color_temperature = None
+ lux = None
+
+ parts = fn.stem.split('_')
+ for part in parts:
+ if part == 'alsc':
+ lsc_only = True
+ continue
+ r = re.match(r'(\d+)[kK]', part)
+ if r:
+ color_temperature = int(r.group(1))
+ continue
+ r = re.match(r'(\d+)[lLuU]', part)
+ if r:
+ lux = int(r.group(1))
+
+ if color_temperature is None:
+ logger.error(f'The file name of "{fn.name}" does not contain a color temperature')
- color = int(result.group(2))
- lsc_only = result.group(1) is not None
- lux = None if lsc_only else int(result.group(3))
+ if lux is None and lsc_only is False:
+ logger.error(f'The file name of "{fn.name}" must either contain alsc or a lux level')
- return color, lux, lsc_only
+ return color_temperature, lux, lsc_only
# \todo Implement this from check_imgs() in ctt.py