Indeed.
You may, nevertheless, wish to fix the fact that when $v >= $vmax both the original and the updated code give (r= 0 g= 0 b= 0) cf the expected (r=255 g=255 b=255).
As to performance, I ran a little benchmark over 1,000,000 random values -200..+200:
s/iter colorRamp1785_u colorRamp1785_2 colorRamp1785_3
colorRamp1785_u 7.26 -- -19% -65%
colorRamp1785_2 5.85 24% -- -57%
colorRamp1785_3 2.54 186% 130% --
YMMV, of course. (colorRamp1785_3 is, of course, a direct look-up, after normalising $vmin..$vmax to 0..1785.)
[Colour reproduction and colour perception being what they are, I imagine there's a cunning way of mapping a linear scale to something which appears linear. I just wish I knew what that was :-(]
Update: FWIW the fastest I can make a direct look-up is the code below, which benchmarks:
s/iter colorRamp1785_u colorRamp1785_1 colorRamp1785_2 colorRamp1785_d
colorRamp1785_u 7.23 -- -8% -20% -67%
colorRamp1785_1 6.62 9% -- -13% -64%
colorRamp1785_2 5.79 25% 14% -- -59%
colorRamp1785_d 2.37 205% 179% 144% --
|