summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-15 20:50:35 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-15 20:50:35 +0100
commit22aaf0c05ab2ab2b271ba46ee925cfcf49e62ae9 (patch)
treeed8e4dd6e94eb40beea2998b3d36f667f6f9fd90
parentxmonad example now disables when working in gimp or inkscape (diff)
downloadblueshift-22aaf0c05ab2ab2b271ba46ee925cfcf49e62ae9.tar.gz
blueshift-22aaf0c05ab2ab2b271ba46ee925cfcf49e62ae9.tar.bz2
blueshift-22aaf0c05ab2ab2b271ba46ee925cfcf49e62ae9.tar.xz
fix compose specs and implement it
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--examples/lisp-esque61
-rw-r--r--examples/lisp-esque.conf22
2 files changed, 60 insertions, 23 deletions
diff --git a/examples/lisp-esque b/examples/lisp-esque
index 079d018..9c093a5 100644
--- a/examples/lisp-esque
+++ b/examples/lisp-esque
@@ -138,6 +138,9 @@ if isinstance(conf[0], str) and not conf[0].startswith(':'):
# Available outputs
screens = list_screens('drm' if ttymode else 'randr')
+# Map of composed function
+composed = {}
+
## For the following functions, the type of args is the type of args
## after it has been evaluated, they may be functions inside that
@@ -385,6 +388,50 @@ def _transfrom(mods, args):
print('Selected transition from method: %s' % ', '.join(args))
+def _compose(mods, args):
+ '''
+ Compose a function
+
+ @param mods:[] Not used
+ @param args:list<str|list<str>> The name of the function follow by the wrapped function and
+ parameters wrappers: 'as-is' for identity, 'yes' for tautology,
+ 'no' for contradiction, and functions names for functions, or
+ a composition
+ '''
+ new_function = args[0]
+ old_function = composed[args[1]] if args[1] in composed else eval(args[1])
+ arguments = [[arg] if isinstance(arg, str) else arg for arg in args[2:]]
+
+ wrapping = []
+ for arg in arguments:
+ composite = lambda x : x()
+ for f_ in arg:
+ if f_ == 'as-is':
+ continue
+ elif f_ == 'yes':
+ composite = lambda x : True
+ elif f_ == 'no':
+ composite = lambda x : False
+ else:
+ composite_ = composite
+ f = composed[f_] if f_ in composed else eval(f_)
+ composite = lambda x : f(composite_(x))
+ wrapping.append(composite)
+
+ def F_new(*args):
+ arg_ptr = -1
+ def arg_itr():
+ nonlocal arg_ptr
+ arg_ptr += 1
+ return args[arg_ptr]
+ evaled = []
+ for wrap in wrapping:
+ evaled.append(wrap(arg_itr))
+ return old_function(*evaled)
+
+ composed[new_function] = F_new
+
+
def _negative(mods, args):
'''
Add negative image adjustment
@@ -396,7 +443,7 @@ def _negative(mods, args):
monitor (or all of them) on whether to apply negative image,
'yes' implied for all monitors if empty
'''
- pass
+ else
def _invert(mods, args):
@@ -424,18 +471,6 @@ def _temperature(mods, args):
pass
-def _compose(mods, args):
- '''
- Compose a function
-
- @param mods:[] Not used
- @param args:list<str|list<str>> The name of the function follow by parameters wrappers:
- 'as-is' for unmodified, 'yes' for tautology, 'no' for contradiction,
- and functions names for functions, or a composition
- '''
- pass
-
-
def _current(mods, args):
'''
Add adjustments applied when Blueshift starts
diff --git a/examples/lisp-esque.conf b/examples/lisp-esque.conf
index c9dad3c..a26f82c 100644
--- a/examples/lisp-esque.conf
+++ b/examples/lisp-esque.conf
@@ -141,17 +141,19 @@
; If you want a more advance calculation of the correlated colour
; temperature you can replace (temperature) in the step about with
; (temperature') and add the following *before* it:
- ; (compose temperature' as-is (divide_by_maximum cmf_10deg))
+ ; (compose temperature' temperature as-is (divide_by_maximum cmf_10deg))
; This is the default, but you can also use for example and of the following:
- ; (compose temperature' as-is (divide_by_maximum series_d))
- ; (compose temperature' as-is (clip_whitepoint simple_whitepoint))
- ; (compose temperature' as-is (divide_by_maximum cmf_2deg))
- ; (compose temperature' as-is redshift')
- ; Where Redshift' needs to be composed by temperature':
- ; (compose redshift' as-is yes) ; as in redshift<=1.8
- ; (compose redshift' as-is no) ; as in redshift>1.8
- ; (compose redshift' as-is yes yes) ; as in redshift<=1.8 but interpolating in linear RGB
- ; (compose redshift' as-is no yes) ; as in redshift>1.8 but interpolating in linear RGB
+ ; (compose temperature' temperature as-is (divide_by_maximum series_d))
+ ; (compose temperature' temperature as-is (clip_whitepoint simple_whitepoint))
+ ; (compose temperature' temperature as-is (divide_by_maximum cmf_2deg))
+ ; (compose temperature' temperature as-is redshift')
+ ; Where Redshift' needs to be composed before temperature':
+ ; (compose redshift' redshift as-is yes) ; as in redshift<=1.8
+ ; (compose redshift' redshift as-is no) ; as in redshift>1.8
+ ; (compose redshift' redshift as-is yes yes) ; as in redshift<=1.8
+ ; ; but interpolating in linear RGB
+ ; (compose redshift' redshift as-is no yes) ; as in redshift>1.8
+ ; ; but interpolating in linear RGB
; See `info blueshift 'configuration api' 'colour curve manipulators'`
; and look for ‘temperature’ for details.