From 96ba06e375857ba39166760ec98911cdd2fa5395 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 24 Mar 2014 11:55:43 +0100 Subject: implemention of linearly_interpolate_ramp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/aux.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src') 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 The red colour curves as [0, 65535] integers - @param g:list The green colour curves as [0, 65535] integers - @param b:list The blue colour curves as [0, 65535] integers - @return :(r:list, g:list, b:list) The input parameters extended to sizes of `o_size`, - or their original size, whatever is larger. + @param r:list The red colour curves + @param g:list The green colour curves + @param b:list The blue colour curves + @return :(r:list, g:list, b:list) 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): -- cgit v1.2.3-70-g09d2