summaryrefslogtreecommitdiffstats
path: root/src/curve.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/curve.py')
-rw-r--r--src/curve.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/curve.py b/src/curve.py
index 3435124..d3e2a2d 100644
--- a/src/curve.py
+++ b/src/curve.py
@@ -34,12 +34,14 @@ b_curve = [i / (i_size - 1) for i in range(i_size)]
+
clip_result = True
'''
Set to `False` if you want to allow value overflow rather than clipping,
doing so can create visual artifacts
'''
+
def curves(r, g, b):
'''
Generate a tuple of curve–parameter pairs
@@ -52,6 +54,7 @@ def curves(r, g, b):
return ((r_curve, r), (g_curve, g), (b_curve, b))
+
def series_d(temperature):
'''
Calculate the colour for a blackbody temperature
@@ -68,6 +71,7 @@ def series_d(temperature):
y = 2.870 * x - 3.000 * x ** 2 - 0.275
return ciexy_to_srgb(x, y, 1.0)
+
def simple_whitepoint(temperature):
'''
Calculate the colour for a blackbody temperature using a simple, but inaccurate, algorithm
@@ -89,6 +93,7 @@ def simple_whitepoint(temperature):
b = 0.543206789 * math.log(temp - 10) - 1.196254089
return (r, g, b)
+
cmf_2deg_cache = None
def cmf_2deg(temperature):
'''
@@ -115,6 +120,7 @@ def cmf_2deg(temperature):
y = y1 * temp + y2 * (1 - temp)
return ciexy_to_srgb(x, y, 1.0)
+
cmf_10deg_cache = None
def cmf_10deg(temperature):
'''
@@ -142,6 +148,7 @@ def cmf_10deg(temperature):
return ciexy_to_srgb(x, y, 1.0)
+
def temperature(temperature, algorithm, linear_rgb = True):
'''
Change colour temperature according to the CIE illuminant series D
@@ -167,6 +174,7 @@ def temperature(temperature, algorithm, linear_rgb = True):
(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():
'''
Divide all colour components by the value of the most prominent colour component for each colour
@@ -177,6 +185,7 @@ def divide_by_maximum():
for curve in (r_curve, g_curve, b_curve):
curve[i] /= m
+
def rgb_contrast(r, g, b):
'''
Apply contrast correction on the colour curves using sRGB
@@ -190,6 +199,7 @@ def rgb_contrast(r, g, b):
for i in range(i_size):
curve[i] = (curve[i] - 0.5) * level + 0.5
+
def cie_contrast(level):
'''
Apply contrast correction on the colour curves using CIE XYZ
@@ -201,6 +211,7 @@ def cie_contrast(level):
(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)
+
def rgb_brightness(r, g, b):
'''
Apply brightness correction on the colour curves using sRGB
@@ -214,6 +225,7 @@ def rgb_brightness(r, g, b):
for i in range(i_size):
curve[i] *= level
+
def cie_brightness(level):
'''
Apply brightness correction on the colour curves using CIE XYZ
@@ -225,6 +237,7 @@ def cie_brightness(level):
(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)
+
def gamma(r, g, b):
'''
Apply gamma correction on the colour curves
@@ -237,6 +250,7 @@ def gamma(r, g, b):
if not level == 1.0:
for i in range(i_size):
curve[i] **= level
+
def sigmoid(r, g, b):
'''
@@ -254,6 +268,7 @@ def sigmoid(r, g, b):
except:
curve[i] = 0;
+
def clip():
'''
Clip all values below the actual minimum and above actual maximums