From 23e447dcf758c80f7ff15dd325ee830271ea7f0c Mon Sep 17 00:00:00 2001 From: Sam Whited Date: Sat, 13 Jun 2015 01:13:01 -0500 Subject: [PATCH] Allow setting the sensel noise threshold per channel Fixes #46 Change the name of the darkness option Remove pre-commit hook that won't play nicely with namedtuples --- .pre-commit-config.yaml | 1 - rawkit/options.py | 44 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e63cf06..51570fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,4 +12,3 @@ - id: trailing-whitespace - id: check-case-conflict - id: check-merge-conflict - - id: check-docstring-first diff --git a/rawkit/options.py b/rawkit/options.py index bb97745..6bcd50a 100644 --- a/rawkit/options.py +++ b/rawkit/options.py @@ -207,8 +207,8 @@ class Options(object): '_bps', '_brightness', '_chromatic_aberration', - '_darkness', '_lightness', + '_sensel_threshold', '_half_size', '_noise_threshold', '_rgbg_interpolation', @@ -420,17 +420,53 @@ def half_size(self): return False @option(param='user_black', ctype=ctypes.c_int) - def darkness(self): + def sensel_threshold(self): """ - Raise the black level of a photo. + The sensel value below which we consider data to be sensor noise. If + your shadows are foggy, you may need to raise this. - :type: :class:`int` + If this option is set to a tuple of length 4, the level is set per + channel in RGBG order. Unlike + :class:`libraw.structs.libraw_output_params_t.user_cblack`, this option + is always absolute (the per-channel values are overall values, not + corrections ontop of the overall value). + + To use the default value, set the threshold (overall or per-channel) to + `None`. + + :type: :class:`int` or `4 int tuple` :default: None :dcraw: ``-k`` :libraw: :class:`libraw.structs.libraw_output_params_t.user_black` + :class:`libraw.structs.libraw_output_params_t.user_cblack` + :raises: :exc:`ValueError` when the value is a tuple but is not of + length 4. """ return None + @sensel_threshold.param_writer + def sensel_threshold(self, params): + if self.sensel_threshold is not None: + try: + if len(self.sensel_threshold) == 4: + first_black = None + for i in range(0, 4): + if self.sensel_threshold[i] is None: + params.user_cblack[i] = -1 + else: + if first_black is None: + first_black = self.sensel_threshold[i] + params.user_cblack[i] = 0 + else: + params.user_cblack[i] = self.sensel_threshold[ + i] - first_black + params.user_black = first_black + else: + raise ValueError("Sensel threshold must be of length 4") + except TypeError: + params.user_cblack = (-1, -1, -1, -1) + params.user_black = ctypes.c_int(self.sensel_threshold) + @option def chromatic_aberration(self): """