diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-24 11:55:43 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-24 11:55:43 +0100 |
commit | 96ba06e375857ba39166760ec98911cdd2fa5395 (patch) | |
tree | b1e710c3e616fd708c6c99ba19bc1000e197f5b0 /src | |
parent | add specs for linear ramp interpolation (diff) | |
download | blueshift-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>
Diffstat (limited to 'src')
-rw-r--r-- | src/aux.py | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -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): |