summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-16 23:23:29 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-16 23:23:29 +0100
commit7695e738a943dd37f403b2327cd7b06c7202dea6 (patch)
tree4cccde223957d74fc88f727f84c442d4833521de /src
parentmake more parameters optional (diff)
downloadblueshift-7695e738a943dd37f403b2327cd7b06c7202dea6.tar.gz
blueshift-7695e738a943dd37f403b2327cd7b06c7202dea6.tar.bz2
blueshift-7695e738a943dd37f403b2327cd7b06c7202dea6.tar.xz
colour tempurature does not work correctly, otherwise all curves work
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__main__.py8
-rw-r--r--src/colour.py30
-rw-r--r--src/curve.py47
3 files changed, 48 insertions, 37 deletions
diff --git a/src/__main__.py b/src/__main__.py
index 8fd4235..083d0b0 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -42,10 +42,10 @@ def periodically(year, month, day, hour, minute, second, weekday, fade):
fadeout_steps = 100
if fade is None:
negative(False, False, False)
- temperature(6500, lambda T : divide_by_maximum(series_d(T)), True)
- temperature(6500, lambda T : clip_whitepoint(simple_whitepoint(T)), True)
- temperature(6500, cmf_2deg, True)
- temperature(6500, cmf_10deg, True)
+ temperature(6500, lambda T : divide_by_maximum(series_d(T)))
+ temperature(6500, lambda T : clip_whitepoint(simple_whitepoint(T)))
+ temperature(6500, cmf_2deg)
+ temperature(6500, cmf_10deg)
rgb_contrast(1.0, 1.0, 1.0)
cie_contrast(1.0)
rgb_brightness(1.0, 1.0, 1.0)
diff --git a/src/colour.py b/src/colour.py
index ee61c59..69d3064 100644
--- a/src/colour.py
+++ b/src/colour.py
@@ -45,7 +45,7 @@ def ciexyy_to_ciexyz(x, y, Y):
@param Y:float The Y parameter
@return :[float, float, float] The X, Y and Z parameters
'''
- return [Y * x / y, Y, Y * (1 - x - y) / y]
+ return [Y if y == 0 else Y * x / y, Y, Y if y == 0 else Y * (1 - x - y) / y]
def ciexyz_to_ciexyy(X, Y, Z):
@@ -57,10 +57,10 @@ def ciexyz_to_ciexyy(X, Y, Z):
@param Z:float The Z parameter
@return :[float, float, float] The x, y and Y parameters
'''
- p = -Y / X
- q = 1 + Y / X
- y = 1 / (p / 2 + (p ** 2 / 4 - q) ** 0.5)
- x = X * y / Y
+ if X + Y + Z == 0:
+ return [0, 0, 0]
+ y = Y / (X + Y + Z)
+ x = X / (X + Y + Z)
return [x, y, Y]
@@ -73,9 +73,9 @@ def ciexyz_to_linear(X, Y, Z):
@param Z:float The Z parameter
@return :[float, float, float] The red, green and blue components
'''
- r = 3.2406 * X - 1.5372 * Y - 0.4986 * Z
- g = -0.9689 * X + 1.8758 * Y + 0.0415 * Z
- b = 0.0557 * X - 0.2040 * Y + 1.0570 * Z
+ r = 3.24156 * X - 1.53767 * Y - 0.49870 * Z
+ g = -0.96920 * X + 1.87589 * Y + 0.04155 * Z
+ b = 0.05562 * X - 0.20396 * Y + 1.05686 * Z
return [r, g, b]
@@ -88,9 +88,9 @@ def linear_to_ciexyz(r, g, b):
@param b:float The blue component
@return :[float, float, float] The X, Y and Z parameters
'''
- X = 0.4124 * r + 0.3576 * g + 0.1805 * b
- Y = 0.2126 * r + 0.7152 * g + 0.0722 * b
- Z = 0.0193 * r + 0.1192 * g + 1.9502 * b
+ X = 0.4123160 * r + 0.3576020 * g + 0.1805010 * b
+ Y = 0.2126000 * r + 0.7151990 * g + 0.0722016 * b
+ Z = 0.0193297 * r + 0.1192040 * g + 0.9506340 * b
return [X, Y, Z]
@@ -103,9 +103,12 @@ def srgb_to_ciexyy(r, g, b):
@param b:float The blue component
@return :[float, float, float] The x, y and Y parameters
'''
+ if r == g == b == 0:
+ return (0.312857, 0.328993, 0)
(r, g, b) = standard_to_linear(r, g, b)
(X, Y, Z) = linear_to_ciexyz(r, g, b)
- return ciexyz_to_ciexyy(X, Y, Z)
+ (x, y, Y) = ciexyz_to_ciexyy(X, Y, Z)
+ return (x, y, Y)
def ciexyy_to_srgb(x, y, Y):
@@ -119,5 +122,6 @@ def ciexyy_to_srgb(x, y, Y):
'''
(X, Y, Z) = ciexyy_to_ciexyz(x, y, Y)
(r, g, b) = ciexyz_to_linear(X, Y, Z)
- return linear_to_standard(r, g, b)
+ (r, g, b) = linear_to_standard(r, g, b)
+ return (r, g, b)
diff --git a/src/curve.py b/src/curve.py
index 5c0486a..b87e90f 100644
--- a/src/curve.py
+++ b/src/curve.py
@@ -148,34 +148,21 @@ def cmf_10deg(temperature):
temp = (temp % 100) / 100
x = x1 * temp + x2 * (1 - temp)
y = y1 * temp + y2 * (1 - temp)
- return ciexyy_to_srgb(x, y, 1.0)
+ return ciexyy_to_srgb(x, y, 1)
-def temperature(temperature, algorithm, linear_rgb = True):
+def temperature(temperature, algorithm):
'''
Change colour temperature according to the CIE illuminant series D
@param temperature:float The blackbody temperature in kelvins
@param algorithm:(float)→(float, float, float) Algorithm for calculating a white point, for example `series_d` or `simple_whitepoint`
- @param linear_rgb:[bool] Whether to use linear RGB, otherwise sRG is used
'''
if temperature == 6500:
return
(r, g, b) = algorithm(temperature)
- if linear_rgb:
- for curve in (r_curve, g_curve, b_curve):
- 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
rgb_brightness(r, g, b)
- if linear_rgb:
- for curve in (r_curve, g_curve, b_curve):
- 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
def divide_by_maximum(rgb):
@@ -201,7 +188,7 @@ def clip_whitepoint(rgb):
return [min(max(0, x), 1) for x in rgb]
-def rgb_contrast(r, g, b):
+def rgb_contrast(r, g = None, b = None):
'''
Apply contrast correction on the colour curves using sRGB
@@ -219,14 +206,14 @@ def rgb_contrast(r, g, b):
def cie_contrast(level):
'''
- Apply contrast correction on the colour curves using CIE XYZ
+ Apply contrast correction on the colour curves using CIE xyY
@param level:float The brightness parameter
'''
if not level == 1.0:
for i in range(i_size):
(x, y, Y) = srgb_to_ciexyy(r_curve[i], g_curve[i], b_curve[i])
- (r_curve[i], g_curve[i], b_curve[i]) = to_rgb(x, y, (Y - 0.5) * level + 0.5)
+ (r_curve[i], g_curve[i], b_curve[i]) = ciexyy_to_srgb(x, y, (Y - 0.5) * level + 0.5)
def rgb_brightness(r, g = None, b = None):
@@ -247,14 +234,34 @@ def rgb_brightness(r, g = None, b = None):
def cie_brightness(level):
'''
- Apply brightness correction on the colour curves using CIE XYZ
+ Apply brightness correction on the colour curves using CIE xyY
@param level:float The brightness parameter
'''
if not level == 1.0:
for i in range(i_size):
(x, y, Y) = srgb_to_ciexyy(r_curve[i], g_curve[i], b_curve[i])
- (r_curve[i], g_curve[i], b_curve[i]) = to_rgb(x, y, Y * level)
+ (r_curve[i], g_curve[i], b_curve[i]) = ciexyy_to_srgb(x, y, Y * level)
+
+
+def linearise():
+ '''
+ Convert the curves from formatted in standard RGB to linear RGB
+ '''
+ 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
+
+
+def standardise():
+ '''
+ Convert the curves from formatted in linear RGB to standard RGB
+ '''
+ 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
def gamma(r, g = None, b = None):