0
$\begingroup$
f1 = {Max[4 # - 1.5, -4 # + 4.5], Min[4 # - 0.5, -4 # + 3.5], 
 Min[4 # + 0.5, -4 # + 2.5]} &;

cf1 = Compile[{{z, _Real}}, {Max[4 z - 1.5, -4 z + 4.5], 
    Min[4 z - 0.5, -4 z + 3.5], Min[4 z + 0.5, -4 z + 2.5]}];

ArrayPlot[Table[x y, {x, -200, 200}, {y, -200, 200}], 
  ColorFunction -> (RGBColor@f1@# &)] // Timing

I know how to compile the ColorFunction f1, but I dont't know whether f2 can be compiled.

f2 = Blend[{{0, RGBColor[0, 0, 9/16]}, {1/9, Blue}, {23/63, Cyan},{13/21,Yellow}, 
{47/63, Orange}, {55/63, Red}, {1, RGBColor[1/2, 0, 0]}}, #] &;
$\endgroup$
3
  • 1
    $\begingroup$ See this list... Blend is not on that list, which means you can't compile it unless you re-implement Blend using functions on that list (which shouldn't be hard, since it's just linear interpolation). $\endgroup$
    – rm -rf
    Mar 12 '13 at 13:32
  • 2
    $\begingroup$ Why do you need to compile a ColorFunction it shouldn't be too slow... $\endgroup$
    – s0rce
    Mar 12 '13 at 18:20
  • $\begingroup$ As rm, notes, Blend[] internally performs linear interpolation over the RGB color space. See the linked question for compiled functions for linear interpolation. $\endgroup$
    – J. M.'s torpor
    Apr 27 '13 at 4:45

Browse other questions tagged or ask your own question.