summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-10 16:46:02 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-10 16:46:02 +0100
commitee1044c6836ceea91497f36c561b46cc827f229e (patch)
treed5b4338d7de51e0c2532d3f1d5904a6467e16aea
parentm doc (diff)
downloadblueshift-ee1044c6836ceea91497f36c561b46cc827f229e.tar.gz
blueshift-ee1044c6836ceea91497f36c561b46cc827f229e.tar.bz2
blueshift-ee1044c6836ceea91497f36c561b46cc827f229e.tar.xz
make clip, linearise and standardise more flexible by making it possible to restrict which colour curves to affect
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--examples/lisp-esque.conf3
-rw-r--r--info/blueshift.texinfo34
-rw-r--r--src/curve.py41
3 files changed, 64 insertions, 14 deletions
diff --git a/examples/lisp-esque.conf b/examples/lisp-esque.conf
index 9be3789..3490aee 100644
--- a/examples/lisp-esque.conf
+++ b/examples/lisp-esque.conf
@@ -241,6 +241,9 @@
; (clip)
; Or for the first but not second monitor:
; (clip yes no)
+ ; You can also clip individual colour curves:
+ ; (clip (yes, no, no) no)
+ ; Clips only the red curve on the primary monitor
; Clipping cannot time dependent.
diff --git a/info/blueshift.texinfo b/info/blueshift.texinfo
index 3730504..7b2c3fc 100644
--- a/info/blueshift.texinfo
+++ b/info/blueshift.texinfo
@@ -325,8 +325,13 @@ lists, where 0 is the darkest colour and 1
is the brightest colour. Values outside this
range are clipped unless @code{clip_result}
is set to @code{False}. By calling @code{clip}
-(has no parameters) this clipping is done
-independently of the value of @code{clip_result}.
+this clipping is done independently of the value
+of @code{clip_result}. @code{clip} optionally
+takes one or three arguments, if one, nothing
+will happen if it is @code{False}, if three,
+nothing will happen for the red, green and
+blue colour curves if the first, second and
+third arguments, respectively, is @code{False}.
When applied these values are automatically
translated to appropriate integer values:
[0, @code{o_size} - 1].
@@ -427,10 +432,35 @@ used to calibrate white point.
Converts the colour curves from sRGB to
linear RGB. sRGB is the default colour space.
+@item linearise(rgb)
+Converts the colour curves from sRGB to
+linear RGB if @code{rgb} is @code{True}.
+sRGB is the default colour space.
+
+@item linearise(r, g, b)
+Converts the colour curves from sRGB to
+linear RGB, but only for the red, green
+and blue colour curves if @code{red},
+@code{green}, @code{blue} is @code{True},
+respectively. sRGB is the default colour
+space.
+
@item standardise()
Converts the colour curves from linear RGB to
sRGB, the default colour space.
+@item standardise(rgb)
+Converts the colour curves from linear RGB to
+sRGB, the default colour space, if @code{rgb}
+is @code{True}.
+
+@item standardise(r, g, b)
+Converts the colour curves from linear RGB to
+sRGB, the default colour space, but only for
+the red, green and blue colour curves if
+@code{red}, @code{green}, @code{blue} is
+@code{True}, respectively.
+
@item gamma(rgb)
Adjusts the gamma to @code{rgb}.
diff --git a/src/curve.py b/src/curve.py
index c69bdce..4ef52a4 100644
--- a/src/curve.py
+++ b/src/curve.py
@@ -298,24 +298,36 @@ def cie_brightness(level):
(r_curve[i], g_curve[i], b_curve[i]) = ciexyy_to_srgb(x, y, Y * level)
-def linearise():
+def linearise(r = True, g = None, b = None):
'''
Convert the curves from formatted in standard RGB to linear RGB
+
+ @param r:bool Whether to convert the red colour curve
+ @param g:bool? Whether to convert the green colour curve, defaults to `r` if `None`
+ @param b:bool? Whether to convert the blue colour curve, defaults to `r` if `None`
'''
+ if g is None: g = r
+ if b is None: b = r
for i in range(i_size):
- r, g, b = r_curve[i], g_curve[i], b_curve[i]
- (r, g, b) = standard_to_linear(r, g, b)
- r_curve[i], g_curve[i], b_curve[i] = r, g, b
+ sr, sg, sb = r_curve[i], g_curve[i], b_curve[i]
+ (lr, lg, lb) = standard_to_linear(sr, sg, sb)
+ r_curve[i], g_curve[i], b_curve[i] = (lr if r else sr), (lg if g else sg), (lb if b else sb)
-def standardise():
+def standardise(r = True, g = None, b = None):
'''
Convert the curves from formatted in linear RGB to standard RGB
+
+ @param r:bool Whether to convert the red colour curve
+ @param g:bool? Whether to convert the green colour curve, defaults to `r` if `None`
+ @param b:bool? Whether to convert the blue colour curve, defaults to `r` if `None`
'''
+ if g is None: g = r
+ if b is None: b = r
for i in range(i_size):
- r, g, b = r_curve[i], g_curve[i], b_curve[i]
- (r, g, b) = linear_to_standard(r, g, b)
- r_curve[i], g_curve[i], b_curve[i] = r, g, b
+ lr, lg, lb = r_curve[i], g_curve[i], b_curve[i]
+ (sr, sg, sb) = linear_to_standard(lr, lg, lb)
+ r_curve[i], g_curve[i], b_curve[i] = (sr if r else lr), (sg if g else lg), (sb if b else lb)
def gamma(r, g = None, b = None):
@@ -509,11 +521,16 @@ def start_over():
b_curve[i] = v
-def clip():
+def clip(r = True, g = None, b = None):
'''
Clip all values below the actual minimum and above actual maximums
+
+ @param r:bool Whether to clip the red colour curve
+ @param g:bool? Whether to clip the green colour curve, defaults to `r` if `None`
+ @param b:bool? Whether to clip the blue colour curve, defaults to `r` if `None`
'''
- for curve in (r_curve, g_curve, b_curve):
- for i in range(i_size):
- curve[i] = min(max(0.0, curve[i]), 1.0)
+ for curve, action in curves(r, r if g is None else g, r if b is None else b):
+ if action:
+ for i in range(i_size):
+ curve[i] = min(max(0.0, curve[i]), 1.0)