Skip to content

Commit

Permalink
Allow setting the sensel noise threshold per channel
Browse files Browse the repository at this point in the history
Fixes photoshell#46

Change the name of the darkness option
Remove pre-commit hook that won't play nicely with namedtuples
  • Loading branch information
SamWhited committed Jul 5, 2015
1 parent 8fb1a95 commit 495b5d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
48 changes: 43 additions & 5 deletions rawkit/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Options(object):
'_auto_brightness',
'_auto_brightness_threshold',
'_chromatic_aberration',
'_darkness',
'_sensel_threshold',
'_half_size',
'_noise_threshold',
'_rgbg_interpolation',
Expand Down Expand Up @@ -429,18 +429,56 @@ def half_size(self):
"""
return False

@option(param='user_black', ctype=ctypes.c_int)
def darkness(self):
@option
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 on top 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 not length 4.
"""
return None

@sensel_threshold.param_writer
def sensel_threshold(self, params):
if self.sensel_threshold is None:
params.user_cblack = (-1, -1, -1, -1)
params.user_black = -1
else:
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):
"""
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ def test_calling_an_option_method_directly_should_error(opt_method):


def test_setting_a_value(options):
# TODO: It would probably be better for these to operate on a Mock and
# check if __set__ was called.

# Uses normal set
options.darkness = 1
assert options.darkness is 1
options.brightness = 1
assert options.brightness is 1

# Uses a special setter
options.bps = 16
Expand Down

0 comments on commit 495b5d0

Please sign in to comment.