JuliaAttic / Color.jl

Basic color manipulation utilities.
Other
47 stars 21 forks source link

Speed up LMS<->XYZ conversions by a factor of 20 #48

Closed timholy closed 10 years ago

timholy commented 10 years ago

Also gives a 2x speed boost to RGB<->XYZ. The slow ^ operation in rgb_compand is the remaining bottleneck, but there's not an easy way around that.

Note: this may be problematic once multithreading lands (the globals tmp1, tmp2 are not thread-safe), so I'm going to not hit the merge button on this one without review. CC @StefanKarpinski.

dcjones commented 10 years ago

Awesome speedup! I have to admit though, I'm not crazy about the tmp globals. Could we replace this pattern

gemv3!(tmp2, M_RGB_XYZ, tmp1)
XYZ(tmp2[1], tmp2[2], tmp2[3])

with a macro to do in place, like

XYZ(M_RGB_XYZ[1] * c.r + M_RGB_XYZ[2] * c.g + M_RGB_XYZ[3] * c.b,
    M_RGB_XYZ[4] * c.r + M_RGB_XYZ[5] * c.g + M_RGB_XYZ[6] * c.b,
    M_RGB_XYZ[7] * c.r + M_RGB_XYZ[8] * c.g + M_RGB_XYZ[9] * c.b)

I guess to do it in a generic way, well need to define getindex functions and index into the color like c[1] instead of c.r.

timholy commented 10 years ago

I belatedly had the very same thought. We can use getfield(c, 1) for indexing, if you don't want to define getindex. (Or would you rather have getindex anyway?)

I'll push a better version. In working on #42 I discovered that there are a whole bunch of other places this can be used (in conversions.jl).