summaryrefslogtreecommitdiffstats
path: root/src/aux.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/aux.py')
-rw-r--r--src/aux.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/aux.py b/src/aux.py
index a21ab5d..ff852ba 100644
--- a/src/aux.py
+++ b/src/aux.py
@@ -65,8 +65,11 @@ def linearly_interpolate_ramp(r, g, b): # TODO test, demo and document this
small_, large_ = len(small) - 1, len(large) - 1
if large_ > small_:
for i in range(len(large)):
+ # Scaling
j = i * small_ / large_
+ # Floor, weight, ceiling
j, w, k = int(j), j % 1, min(int(j) + 1, small_)
+ # Interpolation
large[i] = small[j] * (1 - w) + small[k] * w
return (R, G, B)
@@ -82,8 +85,11 @@ def functionise(rgb):
def fcurve(R_curve, G_curve, B_curve):
for curve, cur in curves(R_curve, G_curve, B_curve):
for i in range(i_size):
+ # Nearest neighbour
y = int(curve[i] * (len(cur) - 1) + 0.5)
+ # Truncation to actual neighbour
y = min(max(0, y), len(cur) - 1)
+ # Remapping
curve[i] = cur[y]
return lambda : fcurve(*rgb)