summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-24 11:55:43 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-24 11:55:43 +0100
commit96ba06e375857ba39166760ec98911cdd2fa5395 (patch)
treeb1e710c3e616fd708c6c99ba19bc1000e197f5b0
parentadd specs for linear ramp interpolation (diff)
downloadblueshift-96ba06e375857ba39166760ec98911cdd2fa5395.tar.gz
blueshift-96ba06e375857ba39166760ec98911cdd2fa5395.tar.bz2
blueshift-96ba06e375857ba39166760ec98911cdd2fa5395.tar.xz
implemention of linearly_interpolate_ramp
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/aux.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/aux.py b/src/aux.py
index 77f9f3d..b7a83f8 100644
--- a/src/aux.py
+++ b/src/aux.py
@@ -49,17 +49,32 @@ def ramps_to_function(r, g, b):
return functionise((r, g, b))
-def linearly_interpolate_ramp(r, g, b): # TODO demo and document this
+def linearly_interpolate_ramp(r, g, b): # TODO test, demo and document this
'''
Linearly interpolate ramps to the size of the output axes
- @param r:list<int> The red colour curves as [0, 65535] integers
- @param g:list<int> The green colour curves as [0, 65535] integers
- @param b:list<int> The blue colour curves as [0, 65535] integers
- @return :(r:list<int>, g:list<int>, b:list<int>) The input parameters extended to sizes of `o_size`,
- or their original size, whatever is larger.
+ @param r:list<float> The red colour curves
+ @param g:list<float> The green colour curves
+ @param b:list<float> The blue colour curves
+ @return :(r:list<float>, g:list<float>, b:list<float>) The input parameters extended to sizes of `o_size`,
+ or their original size, whatever is larger.
'''
- pass # TODO implement linearly_interpolate_ramp
+ R, G, B = None, None, None
+ R = r[:] if len(r) >= o_size else ([None] * o_size)
+ G = g[:] if len(g) >= o_size else ([None] * o_size)
+ B = b[:] if len(b) >= o_size else ([None] * o_size)
+ for small, large in curves(R, G, B):
+ if len(large) > len(small):
+ small_ = len(small) - 1
+ large_ = len(large) - 1
+ for i in range(len(large)):
+ j = i * small_ / large_
+ j, w = int(j), j % 1
+ k = j + 1
+ if k > small_:
+ k = small_
+ large[i] = small[j] * (w - 1) + small[k] * w
+ return (R, G, B)
def functionise(rgb):