This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
82 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
""":mod:`rawkit.options` --- Options for processing raw files | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
""" | ||
|
||
import ctypes | ||
|
||
|
||
class WhiteBalance(object): | ||
|
||
""" | ||
Represents the white balance of a photo. | ||
:param auto: determines if we should automatically set the WB | ||
:type auto: :class:`boolean` | ||
:param camera: causes us to use the camera defined WB if present | ||
:type camera: :class:`boolean` | ||
:param greybox: set the WB based on a neutral grey region of the image | ||
:type greybox: :class:`4 int tuple` | ||
:param rgbg: set the WB manually based on an RGBG channel multiplier | ||
:type rgbg: :class:`4 float tuple` | ||
:returns: A white blance object | ||
:rtype: :class:`WhiteBalance` | ||
""" | ||
|
||
def __init__(self, | ||
auto=False, | ||
camera=False, | ||
greybox=None, | ||
rgbg=None): | ||
"""Initialize a white balance object.""" | ||
self.auto = auto | ||
self.camera = camera | ||
self.greybox = greybox | ||
self.rgbg = rgbg | ||
|
||
|
||
class Options(object): | ||
|
||
""" | ||
Represents a set of options which can be used when processing raw data. | ||
""" | ||
|
||
__slots__ = [ | ||
'_bps', | ||
'brightness', | ||
'darkness', | ||
'half_size', | ||
'noise_threshold', | ||
'rgbg', | ||
'saturation', | ||
'shot', | ||
'use_camera_matrix', | ||
'white_balance', | ||
'greybox' | ||
] | ||
|
||
def __init__(self): | ||
for i in self.__slots__: | ||
setattr(self, i, None) | ||
self._bps = 8 | ||
self.white_balance = WhiteBalance(auto=True, camera=True) | ||
self.half_size = False | ||
|
||
@property | ||
def bps(self): | ||
return self._bps | ||
|
||
@bps.setter | ||
def bps(self, value): | ||
if value in (8, 16): | ||
self._bps = value | ||
else: | ||
raise ValueError("BPS must be 8 or 16") | ||
|
||
def map_to_libraw_params(self, params): | ||
""" | ||
Internal method that writes rawkit options into the libraw options | ||
struct with the proper C data types. | ||
""" | ||
params.output_bps = ctypes.c_int(self.bps) | ||
|
||
if self.brightness is not None: | ||
params.bright = ctypes.c_float(self.brightness) | ||
if self.darkness is not None: | ||
params.user_black = ctypes.c_int(self.darkness) | ||
|
||
params.half_size = ctypes.c_int(self.half_size) | ||
if self.noise_threshold is not None: | ||
params.threshold = ctypes.c_float(self.noise_threshold) | ||
if self.rgbg is not None: | ||
params.four_color_rgb = ctypes.c_int(self.rgbg) | ||
if self.saturation is not None: | ||
params.user_sat = ctypes.c_int(self.saturation) | ||
if self.shot is not None: | ||
params.shot_select = ctypes.c_uint(self.shot) | ||
if self.use_camera_matrix is not None: | ||
params.use_camera_matrix = ctypes.c_int(self.use_camera_matrix) | ||
|
||
if self.white_balance.greybox is not None: | ||
params.greybox = (ctypes.c_uint * 4)(*self.white_balance.greybox) | ||
if self.white_balance.rgbg is not None: | ||
params.user_mul = (ctypes.c_float * 4)(*self.white_balance.rgbg) | ||
params.use_camera_wb = ctypes.c_int(self.white_balance.camera) | ||
params.use_auto_wb = ctypes.c_int(self.white_balance.auto) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters